From d74535f87febd6d930edc0377400cb7f8bf3c6f6 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Fri, 24 Dec 2004 18:31:38 +0000 Subject: [PATCH] - Tried to make it possible to have debug versions of the memory management code in the default link library along with the normal versions. Let's see how well this works out in the GCC version. SAS/C does not seem to like it... git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14785 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/GNUmakefile.68k | 64 +++++++++++++++++++-- library/GNUmakefile.os4 | 86 +++++++++++++++++++++++----- library/changes | 5 ++ library/signal_headers.h | 8 +-- library/smakefile | 42 +++++++++++++- library/stdio_vasprintf.c | 22 +++++-- library/stdio_vasprintf_hook_entry.c | 6 +- library/stdlib_alloca.c | 12 +++- library/stdlib_calloc.c | 12 +++- library/stdlib_free.c | 13 ++++- library/stdlib_headers.h | 43 +++++++++++++- library/stdlib_malloc.c | 14 ++++- library/stdlib_protos.h | 8 +-- library/stdlib_realloc.c | 12 +++- library/string_strdup.c | 16 +++++- library/unistd_getcwd.c | 16 +++++- 16 files changed, 322 insertions(+), 57 deletions(-) diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index ec6a635..99b8807 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.68k,v 1.17 2004-11-18 09:40:37 obarthel Exp $ +# $Id: GNUmakefile.68k,v 1.18 2004-12-24 18:31:37 obarthel Exp $ # # :ts=8 # @@ -103,10 +103,10 @@ WARNINGS = \ -Wundef -Wbad-function-cast -Wmissing-declarations -Wconversion INCLUDES = -Iinclude -I. -Inetinclude - OPTIONS = -DNDEBUG -fno-builtin -DNO_INLINE_STDARG + OPTIONS = -DNDEBUG -fno-builtin #OPTIONS = -D__MEM_DEBUG -fno-builtin #OPTIONS = -DDEBUG -D__MEM_DEBUG -DNO_INLINE_STDARG -fno-builtin - OPTIMIZE = -O -fomit-frame-pointer -fstrength-reduce -finline-functions +#OPTIMIZE = -O -fomit-frame-pointer -fstrength-reduce -finline-functions #OPTIMIZE = -O2 -fomit-frame-pointer #DEBUG = -g2 @@ -237,7 +237,9 @@ C_LIB = \ stdio_translateioerror.o \ stdio_ungetc.o \ stdio_vasprintf.o \ + stdio_vasprintf_debug.o \ stdio_vasprintf_hook_entry.o \ + stdio_vasprintf_hook_entry_debug.o \ stdio_vfprintf.o \ stdio_vfscanf.o \ stdio_vprintf.o \ @@ -248,12 +250,14 @@ C_LIB = \ stdlib_abort.o \ stdlib_abs.o \ stdlib_alloca.o \ + stdlib_alloca_debug.o \ stdlib_assertion_failure.o \ stdlib_atexit.o \ stdlib_atoi.o \ stdlib_atol.o \ stdlib_bsearch.o \ stdlib_calloc.o \ + stdlib_calloc_debug.o \ stdlib_checkdetach.o \ stdlib_constructor.o \ stdlib_constructor_begin.o \ @@ -270,6 +274,7 @@ C_LIB = \ stdlib_dosbase.o \ stdlib_exit.o \ stdlib_free.o \ + stdlib_free_debug.o \ stdlib_getdefstacksize.o \ stdlib_getenv.o \ stdlib_getsp.o \ @@ -279,6 +284,7 @@ C_LIB = \ stdlib_ldiv.o \ stdlib_machine_test.o \ stdlib_malloc.o \ + stdlib_malloc_debug.o \ stdlib_math.o \ stdlib_mkdtemp.o \ stdlib_mkstemp.o \ @@ -342,6 +348,7 @@ C_LIB = \ string_strcpy.o \ string_strcspn.o \ string_strdup.o \ + string_strdup_debug.o \ string_strerror.o \ string_strlcat.o \ string_strlcpy.o \ @@ -384,6 +391,7 @@ C_LIB = \ unistd_fileno.o \ unistd_ftruncate.o \ unistd_getcwd.o \ + unistd_getcwd_debug.o \ unistd_getopt.o \ unistd_getpid.o \ unistd_init_exit.o \ @@ -423,7 +431,6 @@ UNIX_LIB = \ stdio_fdhookentry.o \ stdio_fflush.o \ stdio_fopen.o \ - stdio_fopen.o \ stdio_init_exit.o \ stdio_locksemaphorename.o \ stdio_openiob.o \ @@ -432,7 +439,6 @@ UNIX_LIB = \ stdio_rename.o \ stdlib_mkdtemp.o \ stdlib_mkstemp.o \ - stdlib_mkstemp.o \ stdlib_mktemp.o \ stdlib_system.o \ unistd_access.o \ @@ -440,6 +446,7 @@ UNIX_LIB = \ unistd_chdir_exit.o \ unistd_chown.o \ unistd_getcwd.o \ + unistd_getcwd_debug.o \ unistd_lchown.o \ unistd_link.o \ unistd_readlink.o \ @@ -497,6 +504,7 @@ MATH_LIB = \ stdio_sprintf.o \ stdio_sscanf.o \ stdio_vasprintf.o \ + stdio_vasprintf_debug.o \ stdio_vfprintf.o \ stdio_vfscanf.o \ stdio_vprintf.o \ @@ -895,6 +903,52 @@ $(LIBC_OBJS)/stdlib_red_black.o : stdlib_red_black.c stdlib_mem_debug.h ############################################################################## +$(LIBC_OBJS)/stdlib_alloca_debug.o : stdlib_alloca.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdlib_alloca_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdlib_alloca.c + +$(LIBC_OBJS)/stdlib_calloc_debug.o : stdlib_calloc.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdlib_calloc_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdlib_calloc.c + +$(LIBC_OBJS)/stdlib_free_debug.o : stdlib_free.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdlib_free_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdlib_free.c + +$(LIBC_OBJS)/stdlib_malloc_debug.o : stdlib_malloc.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdlib_malloc_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdlib_malloc.c + +$(LIBC_OBJS)/stdlib_realloc_debug.o : stdlib_realloc.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdlib_realloc_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdlib_realloc.c + +$(LIBC_OBJS)/stdio_vasprintf_hook_entry_debug.o : stdio_vasprintf_hook_entry.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdio_vasprintf_hook_entry_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdio_vasprintf_hook_entry.c + +$(LIBC_OBJS)/stdio_vasprintf_debug.o : stdio_vasprintf.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdio_vasprintf_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdio_vasprintf.c + +$(LIBM_OBJS)/stdio_vasprintf_debug.o : stdio_vasprintf.c + @echo "Compiling $< [$(TYPE):m debug]" + @$(CC) -o $(LIBM_OBJS)/stdio_vasprintf_debug.o -c $(CFLAGS) -DIEEE_FLOATING_POINT_SUPPORT -D__USE_MEM_TREES -D__MEM_DEBUG stdio_vasprintf.c + +$(LIBC_OBJS)/string_strdup_debug.o : string_strdup.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/string_strdup_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG string_strdup.c + +$(LIBC_OBJS)/unistd_getcwd_debug.o : unistd_getcwd.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/unistd_getcwd_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG unistd_getcwd.c + +$(LIBUNIX_OBJS)/unistd_getcwd_debug.o : unistd_getcwd.c + @echo "Compiling $< [$(TYPE):unix debug]" + @$(CC) -o $(LIBUNIX_OBJS)/unistd_getcwd_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG -DUNIX_PATH_SEMANTICS unistd_getcwd.c + +############################################################################## + $(LIBC_OBJS) : $(MAKEDIR) $@ diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index d510180..568a78f 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.os4,v 1.17 2004-12-13 11:11:57 obarthel Exp $ +# $Id: GNUmakefile.os4,v 1.18 2004-12-24 18:31:37 obarthel Exp $ # # :ts=8 # @@ -32,19 +32,19 @@ MAKE = make -f GNUmakefile.os4 ############################################################################## ifeq (,$(TYPE)) -LIBC_OBJS = libc_objs -LIBUNIX_OBJS = libunix_objs -LIBM_OBJS = libm_objs -LIBNET_OBJS = libnet_objs -LIBDEBUG_OBJS = libdebug_objs -LIBAMIGA_OBJS = libamiga_objs +LIBC_OBJS = libc_objs +LIBUNIX_OBJS = libunix_objs +LIBM_OBJS = libm_objs +LIBNET_OBJS = libnet_objs +LIBDEBUG_OBJS = libdebug_objs +LIBAMIGA_OBJS = libamiga_objs else -LIBC_OBJS = $(TYPE)/libc_objs -LIBUNIX_OBJS = $(TYPE)/libunix_objs -LIBM_OBJS = $(TYPE)/libm_objs -LIBNET_OBJS = $(TYPE)/libnet_objs -LIBDEBUG_OBJS = $(TYPE)/libdebug_objs -LIBAMIGA_OBJS = $(TYPE)/libamiga_objs +LIBC_OBJS = $(TYPE)/libc_objs +LIBUNIX_OBJS = $(TYPE)/libunix_objs +LIBM_OBJS = $(TYPE)/libm_objs +LIBNET_OBJS = $(TYPE)/libnet_objs +LIBDEBUG_OBJS = $(TYPE)/libdebug_objs +LIBAMIGA_OBJS = $(TYPE)/libamiga_objs endif ############################################################################## @@ -241,7 +241,9 @@ C_LIB = \ stdio_translateioerror.o \ stdio_ungetc.o \ stdio_vasprintf.o \ + stdio_vasprintf_debug.o \ stdio_vasprintf_hook_entry.o \ + stdio_vasprintf_hook_entry_debug.o \ stdio_vfprintf.o \ stdio_vfscanf.o \ stdio_vprintf.o \ @@ -252,12 +254,14 @@ C_LIB = \ stdlib_abort.o \ stdlib_abs.o \ stdlib_alloca.o \ + stdlib_alloca_debug.o \ stdlib_assertion_failure.o \ stdlib_atexit.o \ stdlib_atoi.o \ stdlib_atol.o \ stdlib_bsearch.o \ stdlib_calloc.o \ + stdlib_calloc_debug.o \ stdlib_checkdetach.o \ stdlib_constructor.o \ stdlib_constructor_begin.o \ @@ -274,6 +278,7 @@ C_LIB = \ stdlib_dosbase.o \ stdlib_exit.o \ stdlib_free.o \ + stdlib_free_debug.o \ stdlib_getdefstacksize.o \ stdlib_getenv.o \ stdlib_getsp.o \ @@ -283,6 +288,7 @@ C_LIB = \ stdlib_ldiv.o \ stdlib_machine_test.o \ stdlib_malloc.o \ + stdlib_malloc_debug.o \ stdlib_math.o \ stdlib_mkdtemp.o \ stdlib_mkstemp.o \ @@ -346,6 +352,7 @@ C_LIB = \ string_strcpy.o \ string_strcspn.o \ string_strdup.o \ + string_strdup_debug.o \ string_strerror.o \ string_strlcat.o \ string_strlcpy.o \ @@ -388,6 +395,7 @@ C_LIB = \ unistd_fileno.o \ unistd_ftruncate.o \ unistd_getcwd.o \ + unistd_getcwd_debug.o \ unistd_getopt.o \ unistd_getpid.o \ unistd_init_exit.o \ @@ -428,7 +436,6 @@ UNIX_LIB = \ stdio_fdhookentry.o \ stdio_fflush.o \ stdio_fopen.o \ - stdio_fopen.o \ stdio_init_exit.o \ stdio_locksemaphorename.o \ stdio_openiob.o \ @@ -437,7 +444,6 @@ UNIX_LIB = \ stdio_rename.o \ stdlib_mkdtemp.o \ stdlib_mkstemp.o \ - stdlib_mkstemp.o \ stdlib_mktemp.o \ stdlib_system.o \ unistd_access.o \ @@ -445,6 +451,7 @@ UNIX_LIB = \ unistd_chdir_exit.o \ unistd_chown.o \ unistd_getcwd.o \ + unistd_getcwd_debug.o \ unistd_lchown.o \ unistd_link.o \ unistd_readlink.o \ @@ -509,6 +516,7 @@ MATH_LIB = \ stdio_sprintf.o \ stdio_sscanf.o \ stdio_vasprintf.o \ + stdio_vasprintf_debug.o \ stdio_vfprintf.o \ stdio_vfscanf.o \ stdio_vprintf.o \ @@ -907,6 +915,54 @@ $(LIBC_OBJS)/stdlib_red_black.o : stdlib_red_black.c stdlib_mem_debug.h ############################################################################## +# Peculiar build rules for the debug versions of memory allocation functions, +# or at least those which use memory allocation functionality. +$(LIBC_OBJS)/stdlib_alloca_debug.o : stdlib_alloca.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdlib_alloca_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdlib_alloca.c + +$(LIBC_OBJS)/stdlib_calloc_debug.o : stdlib_calloc.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdlib_calloc_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdlib_calloc.c + +$(LIBC_OBJS)/stdlib_free_debug.o : stdlib_free.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdlib_free_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdlib_free.c + +$(LIBC_OBJS)/stdlib_malloc_debug.o : stdlib_malloc.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdlib_malloc_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdlib_malloc.c + +$(LIBC_OBJS)/stdlib_realloc_debug.o : stdlib_realloc.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdlib_realloc_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdlib_realloc.c + +$(LIBC_OBJS)/stdio_vasprintf_hook_entry_debug.o : stdio_vasprintf_hook_entry.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdio_vasprintf_hook_entry_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdio_vasprintf_hook_entry.c + +$(LIBC_OBJS)/stdio_vasprintf_debug.o : stdio_vasprintf.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/stdio_vasprintf_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG stdio_vasprintf.c + +$(LIBM_OBJS)/stdio_vasprintf_debug.o : stdio_vasprintf.c + @echo "Compiling $< [$(TYPE):m debug]" + @$(CC) -o $(LIBM_OBJS)/stdio_vasprintf_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG $(FLOAT_TYPE) stdio_vasprintf.c + +$(LIBC_OBJS)/string_strdup_debug.o : string_strdup.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/string_strdup_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG string_strdup.c + +$(LIBC_OBJS)/unistd_getcwd_debug.o : unistd_getcwd.c + @echo "Compiling $< [$(TYPE):c debug]" + @$(CC) -o $(LIBC_OBJS)/unistd_getcwd_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG unistd_getcwd.c + +$(LIBUNIX_OBJS)/unistd_getcwd_debug.o : unistd_getcwd.c + @echo "Compiling $< [$(TYPE):unix debug]" + @$(CC) -o $(LIBUNIX_OBJS)/unistd_getcwd_debug.o -c $(CFLAGS) -D__USE_MEM_TREES -D__MEM_DEBUG -DUNIX_PATH_SEMANTICS unistd_getcwd.c + +############################################################################## + # Individual build rules for libc.a $(LIBC_OBJS) : $(MAKEDIR) $@ diff --git a/library/changes b/library/changes index a6b5acd..c8d285b 100644 --- a/library/changes +++ b/library/changes @@ -11,6 +11,11 @@ - Finally optimized the alloca() memory cleanup code. +- Tried to make it possible to have debug versions of the memory + management code in the default link library along with the + normal versions. Let's see how well this works out in the GCC + version. SAS/C does not seem to like it... + c.lib 1.184 (28.11.2004) diff --git a/library/signal_headers.h b/library/signal_headers.h index 8563764..81db57f 100644 --- a/library/signal_headers.h +++ b/library/signal_headers.h @@ -1,5 +1,5 @@ /* - * $Id: signal_headers.h,v 1.2 2004-11-14 11:06:27 obarthel Exp $ + * $Id: signal_headers.h,v 1.3 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -85,9 +85,9 @@ extern const char NOCOMMON __abnormal_program_termination[]; /****************************************************************************/ -#ifndef _STDLIB_PROTOS_H -#include "stdlib_protos.h" -#endif /* _STDLIB_PROTOS_H */ +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ /****************************************************************************/ diff --git a/library/smakefile b/library/smakefile index 00b874c..fe1b599 100644 --- a/library/smakefile +++ b/library/smakefile @@ -1,5 +1,5 @@ # -# $Id: smakefile,v 1.13 2004-12-24 11:46:12 obarthel Exp $ +# $Id: smakefile,v 1.14 2004-12-24 18:31:38 obarthel Exp $ # # :ts=8 # @@ -345,7 +345,9 @@ STDIO_OBJ = \ stdio_translateioerror.o \ stdio_ungetc.o \ stdio_vasprintf.o \ + stdio_vasprintf_debug.o \ stdio_vasprintf_hook_entry.o \ + stdio_vasprintf_hook_debug.o \ stdio_vfprintf.o \ stdio_vfscanf.o \ stdio_vprintf.o \ @@ -358,6 +360,10 @@ STDLIB_OBJ = \ stdlib_abort.o \ stdlib_abs.o \ stdlib_alloca.o \ + stdlib_alloca_debug.o \ + stdlib_calloc_debug.o \ + stdlib_free_debug.o \ + stdlib_malloc_debug.o \ stdlib_assertion_failure.o \ stdlib_atexit.o \ stdlib_atof.o \ @@ -446,6 +452,7 @@ STRING_OBJ = \ string_strcpy.o \ string_strcspn.o \ string_strdup.o \ + string_strdup_debug.o \ string_strerror.o \ string_strlcat.o \ string_strlcpy.o \ @@ -497,6 +504,7 @@ UNISTD_OBJ = \ unistd_fileno.o \ unistd_ftruncate.o \ unistd_getcwd.o \ + unistd_getcwd_debug.o \ unistd_getopt.o \ unistd_getpid.o \ unistd_init_exit.o \ @@ -677,6 +685,38 @@ sas_profile.o : sas_profile.c @echo "Compiling $<" @sc $(CFLAGS) noprofile sas_profile.c +stdio_vasprintf_hook_debug.o : stdio_vasprintf_hook_entry.c + @echo "Compiling $<" + @sc $(CFLAGS) define=__USE_MEM_TREES define=__MEM_DEBUG objname=stdio_vasprintf_hook_debug.o stdio_vasprintf_hook_entry.c + +stdio_vasprintf_debug.o : stdio_vasprintf.c + @echo "Compiling $<" + @sc $(CFLAGS) define=__USE_MEM_TREES define=__MEM_DEBUG objname=stdio_vasprintf_debug.o stdio_vasprintf.c + +stdlib_alloca_debug.o : stdlib_alloca.c + @echo "Compiling $<" + @sc $(CFLAGS) define=__USE_MEM_TREES define=__MEM_DEBUG objname=stdlib_alloca_debug.o stdlib_alloca.c + +stdlib_calloc_debug.o : stdlib_calloc.c + @echo "Compiling $<" + @sc $(CFLAGS) define=__USE_MEM_TREES define=__MEM_DEBUG objname=stdlib_calloc_debug.o stdlib_calloc.c + +stdlib_free_debug.o : stdlib_free.c + @echo "Compiling $<" + @sc $(CFLAGS) define=__USE_MEM_TREES define=__MEM_DEBUG objname=stdlib_free_debug.o stdlib_free.c + +stdlib_malloc_debug.o : stdlib_malloc.c + @echo "Compiling $<" + @sc $(CFLAGS) define=__USE_MEM_TREES define=__MEM_DEBUG objname=stdlib_malloc_debug.o stdlib_malloc.c + +string_strdup_debug.o : string_strdup.c + @echo "Compiling $<" + @sc $(CFLAGS) define=__USE_MEM_TREES define=__MEM_DEBUG objname=string_strdup_debug.o string_strdup.c + +unistd_getcwd_debug.o : unistd_getcwd.c + @echo "Compiling $<" + @sc $(CFLAGS) define=__USE_MEM_TREES define=__MEM_DEBUG objname=unistd_getcwd_debug.o unistd_getcwd.c + ############################################################################## ctype.lib : $(CTYPE_OBJ) diff --git a/library/stdio_vasprintf.c b/library/stdio_vasprintf.c index f5a143c..335ecdc 100644 --- a/library/stdio_vasprintf.c +++ b/library/stdio_vasprintf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_vasprintf.c,v 1.2 2004-08-07 09:15:32 obarthel Exp $ + * $Id: stdio_vasprintf.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -37,13 +37,15 @@ /****************************************************************************/ -#ifndef _STDIO_HEADERS_H -#include "stdio_headers.h" -#endif /* _STDIO_HEADERS_H */ +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ /****************************************************************************/ -#include "stdlib_protos.h" +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ /****************************************************************************/ @@ -55,7 +57,7 @@ /****************************************************************************/ -int +__static int __vasprintf(const char *file,int line,char **ret,const char *format,va_list arg) { struct iob string_iob; @@ -121,6 +123,10 @@ __vasprintf(const char *file,int line,char **ret,const char *format,va_list arg) /****************************************************************************/ +#if NOT defined(__MEM_DEBUG) + +/****************************************************************************/ + int vasprintf(char **ret,const char *format,va_list arg) { @@ -130,3 +136,7 @@ vasprintf(char **ret,const char *format,va_list arg) return(result); } + +/****************************************************************************/ + +#endif /* __MEM_DEBUG */ diff --git a/library/stdio_vasprintf_hook_entry.c b/library/stdio_vasprintf_hook_entry.c index 0172527..647a2c6 100644 --- a/library/stdio_vasprintf_hook_entry.c +++ b/library/stdio_vasprintf_hook_entry.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_vasprintf_hook_entry.c,v 1.1.1.1 2004-07-26 16:31:43 obarthel Exp $ + * $Id: stdio_vasprintf_hook_entry.c,v 1.2 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -43,7 +43,9 @@ /****************************************************************************/ -#include "stdlib_protos.h" +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ /****************************************************************************/ diff --git a/library/stdlib_alloca.c b/library/stdlib_alloca.c index fa04997..336a350 100644 --- a/library/stdlib_alloca.c +++ b/library/stdlib_alloca.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_alloca.c,v 1.2 2004-12-24 11:46:12 obarthel Exp $ + * $Id: stdlib_alloca.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -111,7 +111,7 @@ __alloca_cleanup(const char * file,int line) /****************************************************************************/ -void * +__static void * __alloca(size_t size,const char * file,int line) { void * stack_pointer = __get_sp(); @@ -170,6 +170,10 @@ __alloca(size_t size,const char * file,int line) /****************************************************************************/ +#if NOT defined(__MEM_DEBUG) + +/****************************************************************************/ + void * alloca(size_t size) { @@ -179,3 +183,7 @@ alloca(size_t size) return(result); } + +/****************************************************************************/ + +#endif /* __MEM_DEBUG */ diff --git a/library/stdlib_calloc.c b/library/stdlib_calloc.c index ab9542d..53d71d9 100644 --- a/library/stdlib_calloc.c +++ b/library/stdlib_calloc.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_calloc.c,v 1.1.1.1 2004-07-26 16:31:52 obarthel Exp $ + * $Id: stdlib_calloc.c,v 1.2 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -47,7 +47,7 @@ /****************************************************************************/ -void * +__static void * __calloc(size_t num_elements,size_t element_size,const char * file,int line) { void * result = NULL; @@ -82,6 +82,10 @@ __calloc(size_t num_elements,size_t element_size,const char * file,int line) /****************************************************************************/ +#if NOT defined(__MEM_DEBUG) + +/****************************************************************************/ + void * calloc(size_t num_elements,size_t element_size) { @@ -91,3 +95,7 @@ calloc(size_t num_elements,size_t element_size) return(result); } + +/****************************************************************************/ + +#endif /* __MEM_DEBUG */ diff --git a/library/stdlib_free.c b/library/stdlib_free.c index ce12ffd..682b1fe 100644 --- a/library/stdlib_free.c +++ b/library/stdlib_free.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_free.c,v 1.2 2004-12-24 11:46:12 obarthel Exp $ + * $Id: stdlib_free.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -44,6 +44,7 @@ /****************************************************************************/ #undef free +#undef __free /****************************************************************************/ @@ -495,7 +496,7 @@ __force_free(void * ptr,const char * file,int line) /****************************************************************************/ -void +__static void __free(void * ptr,const char * file,int line) { if(ptr != NULL) @@ -504,6 +505,10 @@ __free(void * ptr,const char * file,int line) /****************************************************************************/ +#if NOT defined(__MEM_DEBUG) + +/****************************************************************************/ + void free(void * ptr) { @@ -512,6 +517,10 @@ free(void * ptr) /****************************************************************************/ +#endif /* __MEM_DEBUG */ + +/****************************************************************************/ + void __memory_exit(void) { diff --git a/library/stdlib_headers.h b/library/stdlib_headers.h index 49cb0e3..3fd4208 100644 --- a/library/stdlib_headers.h +++ b/library/stdlib_headers.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib_headers.h,v 1.4 2004-12-24 11:46:12 obarthel Exp $ + * $Id: stdlib_headers.h,v 1.5 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -103,6 +103,47 @@ /****************************************************************************/ +/* We shuffle things around a bit for the debug code. This works by joining + related code which shares the same name. The debug code symbols also have + to be completely separate from the "regular" code. */ +#if defined(__MEM_DEBUG) + +#define __static + +#define __alloca_cleanup __alloca_cleanup_debug +#define __alloca_exit __alloca_exit_debug + +#define __find_memory_node __find_memory_node_debug +#define __free_memory_node __free_memory_node_debug +#define __force_free __force_free_debug + +#define __get_allocation_size __get_allocation_size_debug +#define __allocate_memory __allocate_memory_debug + +#define __memory_pool __memory_pool_debug +#define __memory_list __memory_list_debug + +#define __vasprintf_hook_entry __vasprintf_hook_entry_debug + +extern void * __alloca(size_t size,const char * file,int line); +extern void * __calloc(size_t num_elements,size_t element_size,const char * file,int line); +extern void __free(void * ptr,const char * file,int line); +extern void * __malloc(size_t size,const char * file,int line); +extern void * __realloc(void *ptr,size_t size,const char * file,int line); +extern char * __strdup(const char *s,const char * file,int line); +extern char * __getcwd(char * buffer,size_t buffer_size,const char *file,int line); + +#else + +#define __static static + +#define __free(mem,file,line) free(mem) +#define __malloc(size,file,line) malloc(size) + +#endif /* __MEM_DEBUG */ + +/****************************************************************************/ + struct MemoryNode { struct MinNode mn_MinNode; diff --git a/library/stdlib_malloc.c b/library/stdlib_malloc.c index 954fb2b..a822b74 100644 --- a/library/stdlib_malloc.c +++ b/library/stdlib_malloc.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_malloc.c,v 1.2 2004-12-24 11:46:12 obarthel Exp $ + * $Id: stdlib_malloc.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -44,6 +44,7 @@ /****************************************************************************/ #undef malloc +#undef __malloc /****************************************************************************/ @@ -206,7 +207,7 @@ __allocate_memory(size_t size,BOOL never_free,const char * UNUSED file,int UNUSE /****************************************************************************/ -void * +__static void * __malloc(size_t size,const char * file,int line) { void * result = NULL; @@ -249,6 +250,10 @@ __malloc(size_t size,const char * file,int line) /****************************************************************************/ +#if NOT defined(__MEM_DEBUG) + +/****************************************************************************/ + void * malloc(size_t size) { @@ -259,6 +264,11 @@ malloc(size_t size) return(result); } + +/****************************************************************************/ + +#endif /* __MEM_DEBUG */ + /****************************************************************************/ void diff --git a/library/stdlib_protos.h b/library/stdlib_protos.h index f68a482..f517539 100644 --- a/library/stdlib_protos.h +++ b/library/stdlib_protos.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib_protos.h,v 1.3 2004-12-24 11:46:12 obarthel Exp $ + * $Id: stdlib_protos.h,v 1.4 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -141,7 +141,6 @@ extern int __startup_init(void); extern void __memory_init(void); extern size_t __get_allocation_size(size_t size); extern void * __allocate_memory(size_t size,BOOL never_free,const char * file,int line); -extern void * __malloc(size_t size,const char * file,int line); /* stdlib_free.c */ extern void __memory_exit(void); @@ -149,14 +148,9 @@ extern struct MemoryNode * __find_memory_node(void * address); extern void __force_free(void * ptr,const char * file,int line); extern void __check_memory_allocations(const char * file,int line); extern void __free_memory_node(struct MemoryNode * mn,const char * file,int line); -extern void __free(void * ptr,const char * file,int line); /* stdlib_alloca.c */ extern void __alloca_cleanup(const char * file,int line); -extern void * __alloca(size_t size,const char * file,int line); - -/* stdlib_realloc.c */ -extern void * __realloc(void *ptr,size_t size,const char * file,int line); /****************************************************************************/ diff --git a/library/stdlib_realloc.c b/library/stdlib_realloc.c index da77610..5919357 100644 --- a/library/stdlib_realloc.c +++ b/library/stdlib_realloc.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_realloc.c,v 1.1.1.1 2004-07-26 16:32:03 obarthel Exp $ + * $Id: stdlib_realloc.c,v 1.2 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -47,7 +47,7 @@ /****************************************************************************/ -void * +__static void * __realloc(void *ptr,size_t size,const char * file,int line) { void * result = NULL; @@ -199,6 +199,10 @@ __realloc(void *ptr,size_t size,const char * file,int line) /****************************************************************************/ +#if NOT defined(__MEM_DEBUG) + +/****************************************************************************/ + void * realloc(void *ptr,size_t size) { @@ -208,3 +212,7 @@ realloc(void *ptr,size_t size) return(result); } + +/****************************************************************************/ + +#endif /* __MEM_DEBUG */ diff --git a/library/string_strdup.c b/library/string_strdup.c index 47c4d90..712edab 100644 --- a/library/string_strdup.c +++ b/library/string_strdup.c @@ -1,5 +1,5 @@ /* - * $Id: string_strdup.c,v 1.2 2004-08-07 09:15:32 obarthel Exp $ + * $Id: string_strdup.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -43,7 +43,9 @@ /****************************************************************************/ -#include "stdlib_protos.h" +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ /****************************************************************************/ @@ -55,7 +57,7 @@ /****************************************************************************/ -char * +__static char * __strdup(const char *s,const char * file,int line) { char * result = NULL; @@ -88,6 +90,10 @@ __strdup(const char *s,const char * file,int line) /****************************************************************************/ +#if NOT defined(__MEM_DEBUG) + +/****************************************************************************/ + char * strdup(const char *s) { @@ -97,3 +103,7 @@ strdup(const char *s) return(result); } + +/****************************************************************************/ + +#endif /* __MEM_DEBUG */ diff --git a/library/unistd_getcwd.c b/library/unistd_getcwd.c index 80cf31b..aecc8ff 100644 --- a/library/unistd_getcwd.c +++ b/library/unistd_getcwd.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_getcwd.c,v 1.2 2004-08-07 09:15:32 obarthel Exp $ + * $Id: unistd_getcwd.c,v 1.3 2004-12-24 18:31:38 obarthel Exp $ * * :ts=4 * @@ -49,7 +49,9 @@ /****************************************************************************/ -#include "stdlib_protos.h" +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ /****************************************************************************/ @@ -61,7 +63,7 @@ /****************************************************************************/ -char * +__static char * __getcwd(char * buffer,size_t buffer_size,const char *file,int line) { #if defined(UNIX_PATH_SEMANTICS) @@ -213,6 +215,10 @@ __getcwd(char * buffer,size_t buffer_size,const char *file,int line) /****************************************************************************/ +#if NOT defined(__MEM_DEBUG) + +/****************************************************************************/ + char * getcwd(char * buffer, size_t buffer_size) { @@ -222,3 +228,7 @@ getcwd(char * buffer, size_t buffer_size) return(result); } + +/****************************************************************************/ + +#endif /* __MEM_DEBUG */