changeset 21:ac311e7ffed6

Split lw_alloc.c for better linking
author lost@l-w.ca
date Sat, 22 Jan 2011 18:28:07 -0700
parents f4df3bd4b85f
children 7c35fa8dbc91
files lwlib/lw_alloc.c lwlib/lw_alloc.h lwlib/lw_free.c lwlib/lw_realloc.c lwlib/rules.make
diffstat 5 files changed, 90 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- 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;
-}
--- 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
--- /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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdlib.h>
+
+#define ___lw_alloc_c_seen___
+#include "lw_alloc.h"
+
+void lw_free(void *P)
+{
+	if (P)
+		free(P);
+}
--- /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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdlib.h>
+
+#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;
+}
--- 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))