[srvx-commits] commit: Add built-in debug malloc wrapper.
Brought to you by:
entrope
From: Michael P. <md...@tr...> - 2005-01-20 23:41:42
|
Revision: srvx--devo--1.3--patch-4 Archive: sr...@sr...--2005-srvx Creator: Michael Poole <md...@tr...> Date: Thu Jan 20 18:41:17 EST 2005 Standard-date: 2005-01-20 23:41:17 GMT New-files: src/.arch-ids/alloc-srvx.c.id src/alloc-srvx.c Modified-files: ChangeLog TODO configure.in src/Makefile.am src/common.h src/dict-splay.c New-patches: sr...@sr...--2005-srvx/srvx--devo--1.3--patch-4 Summary: Add built-in debug malloc wrapper. Keywords: TODO: Remove the completed TODO item. configure.in: Add --with-malloc=srvx support. src/Makefile.am: Add alloc-srvx.c to extra sources. src/common.h: Reindent debug malloc directives; add directives for WITH_MALLOC_SRVX. src/dict-splay.c: Kludge around free() as macro vs function. * added files src/.arch-ids/alloc-srvx.c.id src/alloc-srvx.c {arch}/srvx/srvx--devo/srvx--devo--1.3/sr...@sr...--2005-srvx/patch-log/patch-4 * modified files --- orig/ChangeLog +++ mod/ChangeLog @@ -2,6 +2,32 @@ # arch-tag: aut...@sr...--2005-srvx/srvx--devo--1.3 # +2005-01-20 23:41:17 GMT Michael Poole <md...@tr...> patch-4 + + Summary: + Add built-in debug malloc wrapper. + Revision: + srvx--devo--1.3--patch-4 + + TODO: Remove the completed TODO item. + + configure.in: Add --with-malloc=srvx support. + + src/Makefile.am: Add alloc-srvx.c to extra sources. + + src/common.h: Reindent debug malloc directives; add directives for + WITH_MALLOC_SRVX. + + src/dict-splay.c: Kludge around free() as macro vs function. + + new files: + src/.arch-ids/alloc-srvx.c.id src/alloc-srvx.c + + modified files: + ChangeLog TODO configure.in src/Makefile.am src/common.h + src/dict-splay.c + + 2005-01-20 22:51:54 GMT Michael Poole <md...@tr...> patch-3 Summary: --- orig/TODO +++ mod/TODO @@ -18,6 +18,3 @@ [FEATREQ] Suspension durations and/or comments when suspending user access to a channel [FEATREQ] support "unregistered": ?ctrace print mode +s unregistered - -- rewrite memory allocation calls to use wrapper macros, and add - optional debugging for the stubs to tag size and/or type. --- orig/configure.in +++ mod/configure.in @@ -152,7 +152,7 @@ AC_MSG_CHECKING(which malloc to use) AC_ARG_WITH(malloc, [ --with-malloc=type Enables use of a special malloc library; one of: - system (the default), boehm-gc, dmalloc, mpatrol], + system (the default), boehm-gc, dmalloc, mpatrol, srvx], [], [withval="system"]) if test "x$withval" = "xsystem" ; then @@ -176,6 +176,10 @@ AC_CHECK_LIB(dl, dlopen, , AC_MSG_ERROR([libdl library is missing. boehm-gc build will fail.])) AC_CHECK_LIB(gc, GC_gcollect, , AC_MSG_ERROR([Boehm GC library is missing. boehm-gc build will fail.])) AC_DEFINE(WITH_MALLOC_BOEHM_GC, 1, [Define if using the Boehm GC to garbage collect and check memory leaks]) +elif test "x$withval" = "xsrvx" ; then + AC_MSG_RESULT(srvx) + AC_DEFINE(WITH_MALLOC_SRVX, 1, [Define if using the srvx internal debug allocator]) + MODULE_OBJS="$MODULE_OBJS alloc-srvx.\$(OBJEXT)" else AC_MSG_ERROR([Unknown malloc type $withval]) fi --- orig/src/Makefile.am +++ mod/src/Makefile.am @@ -22,7 +22,7 @@ mv $$TMPFILE arch-version.h ; \ fi -EXTRA_srvx_SOURCES = proto-bahamut.c proto-common.c proto-p10.c mod-snoop.c mod-memoserv.c mod-helpserv.c mod-sockcheck.c +EXTRA_srvx_SOURCES = alloc-srvx.c proto-bahamut.c proto-common.c proto-p10.c mod-snoop.c mod-memoserv.c mod-helpserv.c mod-sockcheck.c srvx_LDADD = @MODULE_OBJS@ srvx_DEPENDENCIES = @MODULE_OBJS@ srvx_SOURCES = \ --- orig/src/common.h +++ mod/src/common.h @@ -64,25 +64,40 @@ #endif #if defined(WITH_MALLOC_DMALLOC) -#define DMALLOC_FUNC_CHECK 1 -#include <string.h> -#include <dmalloc.h> +# define DMALLOC_FUNC_CHECK 1 +# include <string.h> +# include <dmalloc.h> #elif defined(WITH_MALLOC_MPATROL) -#include <string.h> -#include <mpatrol.h> +# include <string.h> +# include <mpatrol.h> #elif defined(WITH_MALLOC_BOEHM_GC) -#if !defined(NDEBUG) -#define GC_DEBUG 1 -#endif -#include <stdlib.h> -#include <string.h> -#include <gc/gc.h> -#define malloc(n) GC_MALLOC(n) -#define calloc(m,n) GC_MALLOC((m)*(n)) -#define realloc(p,n) GC_REALLOC((p),(n)) -#define free(p) GC_FREE(p) -#undef HAVE_STRDUP -#undef strdup +# if !defined(NDEBUG) +# define GC_DEBUG 1 +# endif +# include <stdlib.h> +# include <string.h> +# include <gc/gc.h> +# define malloc(n) GC_MALLOC(n) +# define calloc(m,n) GC_MALLOC((m)*(n)) +# define realloc(p,n) GC_REALLOC((p),(n)) +# define free(p) GC_FREE(p) +# undef HAVE_STRDUP +# undef strdup +#elif defined(WITH_MALLOC_SRVX) +# undef malloc +# define malloc(n) srvx_malloc(__FILE__, __LINE__, (n)) +# undef calloc +# define calloc(m,n) srvx_malloc(__FILE__, __LINE__, (m)*(n)) +# undef realloc +# define realloc(p,n) srvx_realloc(__FILE__, __LINE__, (p), (n)) +# undef free +# define free(p) srvx_free(__FILE__, __LINE__, (p)) +# undef strdup +# define strdup(s) srvx_strdup(__FILE__, __LINE__, (s)) +extern void *srvx_malloc(const char *, unsigned int, size_t); +extern void *srvx_realloc(const char *, unsigned int, void *, size_t); +extern char *srvx_strdup(const char *, unsigned int, const char *); +extern void srvx_free(const char *, unsigned int, void *); #endif extern time_t now; --- orig/src/dict-splay.c +++ mod/src/dict-splay.c @@ -123,10 +123,18 @@ static void dict_dispose_node(struct dict_node *node, free_f free_keys, free_f free_data) { - if (free_keys && node->key) - free_keys((void*)node->key); - if (free_data && node->data) - free_data(node->data); + if (free_keys && node->key) { + if (free_keys == free) + free((void*)node->key); + else + free_keys((void*)node->key); + } + if (free_data && node->data) { + if (free_data == free) + free(node->data); + else + free_data(node->data); + } free(node); } |