# HG changeset patch # User lost@l-w.ca # Date 1295746087 25200 # Node ID ac311e7ffed6bfb996133f1595916322652e0d51 # Parent f4df3bd4b85f0193824550fb44d0a19d37824075 Split lw_alloc.c for better linking diff -r f4df3bd4b85f -r ac311e7ffed6 lwlib/lw_alloc.c --- a/lwlib/lw_alloc.c Sat Jan 22 18:06:37 2011 -0700 +++ b/lwlib/lw_alloc.c Sat Jan 22 18:28:07 2011 -0700 @@ -24,12 +24,6 @@ #define ___lw_alloc_c_seen___ #include "lw_alloc.h" -void lw_free(void *P) -{ - if (P) - free(P); -} - void *lw_alloc(int size) { void *r; @@ -41,26 +35,3 @@ } return r; } - -void *lw_realloc(void *P, int S) -{ - void *r; - - if (!P) - { - return lw_alloc(S); - } - - if (!S) - { - lw_free(P); - return NULL; - } - - r = realloc(P, S); - if (!r) - { - abort(); - } - return r; -} diff -r f4df3bd4b85f -r ac311e7ffed6 lwlib/lw_alloc.h --- a/lwlib/lw_alloc.h Sat Jan 22 18:06:37 2011 -0700 +++ b/lwlib/lw_alloc.h Sat Jan 22 18:28:07 2011 -0700 @@ -25,12 +25,18 @@ #ifdef ___lw_alloc_c_seen___ +#define ___E + #else /* def ___lw_alloc_c_seen___ */ -extern void lw_free(void *P); -extern void *lw_alloc(int S); -extern void *lw_realloc(void *P, int S); +#define ___E extern #endif /* def ___lw_alloc_c_seen___ */ +___E void lw_free(void *P); +___E void *lw_alloc(int S); +___E void *lw_realloc(void *P, int S); + +#undef ___E + #endif /* ___lw_alloc_h_seen___ */ \ No newline at end of file diff -r f4df3bd4b85f -r ac311e7ffed6 lwlib/lw_free.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lwlib/lw_free.c Sat Jan 22 18:28:07 2011 -0700 @@ -0,0 +1,31 @@ +/* +lw_free.c + +Copyright © 2010 William Astle + +This file is part of LWTOOLS. + +LWTOOLS is free software: you can redistribute it and/or modify it under the +terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +*/ + +#include + +#define ___lw_alloc_c_seen___ +#include "lw_alloc.h" + +void lw_free(void *P) +{ + if (P) + free(P); +} diff -r f4df3bd4b85f -r ac311e7ffed6 lwlib/lw_realloc.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lwlib/lw_realloc.c Sat Jan 22 18:28:07 2011 -0700 @@ -0,0 +1,48 @@ +/* +lw_realloc.c + +Copyright © 2010 William Astle + +This file is part of LWTOOLS. + +LWTOOLS is free software: you can redistribute it and/or modify it under the +terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +*/ + +#include + +#define ___lw_alloc_c_seen___ +#include "lw_alloc.h" + +void *lw_realloc(void *P, int S) +{ + void *r; + + if (!P) + { + return lw_alloc(S); + } + + if (!S) + { + lw_free(P); + return NULL; + } + + r = realloc(P, S); + if (!r) + { + abort(); + } + return r; +} diff -r f4df3bd4b85f -r ac311e7ffed6 lwlib/rules.make --- a/lwlib/rules.make Sat Jan 22 18:06:37 2011 -0700 +++ b/lwlib/rules.make Sat Jan 22 18:28:07 2011 -0700 @@ -1,6 +1,6 @@ dirname := $(dir $(lastword $(MAKEFILE_LIST))) -lwlib_srcs_local := lw_alloc.c lw_error.c lw_expr.c lw_stack.c \ - lw_string.c lw_stringlist.c lw_cmdline.c +lwlib_srcs_local := lw_alloc.c lw_realloc.c lw_free.c lw_error.c lw_expr.c \ + lw_stack.c lw_string.c lw_stringlist.c lw_cmdline.c lwlib_srcs := $(lwlib_srcs) $(addprefix $(dirname),$(lwlib_srcs_local))