annotate lwlib/lw_alloc.c @ 390:027d7fbcdcfc

Basic symbol table output; needs work for non-constant symbols
author lost@l-w.ca
date Wed, 14 Jul 2010 22:46:56 -0600
parents be63116281b0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
324
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
1 /*
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
2 lw_alloc.c
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
3
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
4 Copyright © 2010 William Astle
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
5
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
6 This file is part of LWTOOLS.
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
7
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
11 version.
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
12
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
16 more details.
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
17
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
20 */
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
21
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
22 #include <config.h>
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
23
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
24 #include <stdlib.h>
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
25
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
26 #define ___lw_alloc_c_seen___
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
27 #include "lw_alloc.h"
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
28
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
29 void lw_free(void *P)
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
30 {
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
31 if (P)
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
32 free(P);
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
33 }
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
34
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
35 void *lw_alloc(int size)
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
36 {
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
37 void *r;
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
38
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
39 r = malloc(size);
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
40 if (!r)
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
41 {
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
42 abort();
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
43 }
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
44 return r;
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
45 }
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
46
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
47 void *lw_realloc(void *P, int S)
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
48 {
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
49 void *r;
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
50
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
51 if (!P)
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
52 {
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
53 return lw_alloc(S);
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
54 }
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
55
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
56 if (!S)
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
57 {
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
58 lw_free(P);
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
59 return NULL;
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
60 }
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
61
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
62 r = realloc(P, S);
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
63 if (!r)
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
64 {
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
65 abort();
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
66 }
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
67 return r;
be63116281b0 Created lwlib folder and added first bits to it
lost
parents:
diff changeset
68 }