From 264880cc7b0cd81a025e2f4536b066c1ed61c886 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 May 2005 10:07:06 +0000 Subject: [PATCH] making dmalloc work again --- src/Jamrules | 6 ++++++ src/common/kernel/battle.c | 5 ----- src/common/util/lists.c | 2 -- src/common/util/message.c | 6 +++--- src/config.h | 31 ++++++++----------------------- src/eressea/main.c | 11 +++++++---- src/eressea/server.cpp | 22 ++++++++++++++++------ 7 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/Jamrules b/src/Jamrules index e93530904..05ea25c35 100644 --- a/src/Jamrules +++ b/src/Jamrules @@ -21,6 +21,12 @@ if ! $(CCACHE_DIR) { Echo Compiling with ccache ; } +if $(DMALLOC) { + Echo Compiling with dmalloc ; + CCFLAGS += -DUSE_DMALLOC ; + LINKFLAGS += -ldmalloc ; +} + if $(PROFILE) = 1 { Echo Compiling with profiler ; CCFLAGS += -pg -g ; diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index cb201a280..a3d6e9308 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -3911,11 +3911,6 @@ do_battle(void) /* Auswirkungen berechnen: */ aftermath(b); - /* - #ifdef MALLOCDBG - assert(_CrtCheckMemory()); - #endif - */ /* Hier ist das Gefecht beendet, und wir können die * Hilfsstrukturen * wieder löschen: */ diff --git a/src/common/util/lists.c b/src/common/util/lists.c index 800dfcc76..dc0140382 100644 --- a/src/common/util/lists.c +++ b/src/common/util/lists.c @@ -97,7 +97,6 @@ promotelist(void *l, void *p) insertlist((void_list **)l, (void_list *)p); } -#ifndef MALLOCDBG void removelist(void *l, void *p) { @@ -124,7 +123,6 @@ freelist(void *p1) p = p2; } } -#endif void invert_list(void * heap) diff --git a/src/common/util/message.c b/src/common/util/message.c index e45a9c31e..9ce6cf5be 100644 --- a/src/common/util/message.c +++ b/src/common/util/message.c @@ -89,7 +89,7 @@ mt_new_va(const char * name, ...) typedef struct arg_type { struct arg_type * next; const char * name; - void (*free)(void*); + void (*release)(void*); void* (*copy)(void*); } arg_type; @@ -101,7 +101,7 @@ register_argtype(const char * name, void(*free_arg)(void*), void*(*copy_arg)(voi arg_type * atype = (arg_type *)malloc(sizeof(arg_type)); atype->name = name; atype->next = argtypes; - atype->free = free_arg; + atype->release = free_arg; atype->copy = copy_arg; argtypes = atype; } @@ -130,7 +130,7 @@ static void free_arg(const char * type, void * data) { arg_type * atype = find_argtype(type); - if (atype && atype->free) atype->free(data); + if (atype && atype->release) atype->release(data); } message * diff --git a/src/config.h b/src/config.h index 9824dd4f3..2635f8779 100644 --- a/src/config.h +++ b/src/config.h @@ -34,37 +34,22 @@ extern "C" { /**** **** ** Debugging Libraries ** **** ****/ -/* - * MALLOCDBG is an integer >= 0 that specifies the level of - * debugging. 0 = no debugging, >= 1 increasing levels of - * debugging strength. - */ -#ifdef MPATROL -# ifndef MALLOCDBG -# define MALLOCDBG 1 -# endif -# include -#endif - #if defined __GNUC__ # define HAVE_INLINE # define INLINE_FUNCTION __inline #endif - -#ifdef DMALLOC -# ifndef MALLOCDBG -# define MALLOCDBG 1 -# endif + +/* define USE_DMALLOC to enable use of the dmalloc library */ +#ifdef USE_DMALLOC # include +# include # include #endif -#if defined(_DEBUG) && defined(_MSC_VER) -/* define MALLOCDBG in project settings, not here! */ -# ifdef MALLOCDBG -# include -# define _CRTDBG_MAP_ALLOC -# endif +/* define CRTDBG to enable MSVC CRT Debug library functions */ +#if defined(_DEBUG) && defined(_MSC_VER) && defined(CRTDBG) +# include +# define _CRTDBG_MAP_ALLOC #endif /**** **** diff --git a/src/eressea/main.c b/src/eressea/main.c index e1861a4be..13482e69f 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -410,9 +410,9 @@ game_done(void) #include "magic.h" -#ifdef MALLOCDBG +#ifdef CRTDBG void -init_malloc_debug(void) +init_crtdbg(void) { #if (defined(_MSC_VER)) # if MALLOCDBG == 2 @@ -621,8 +621,11 @@ main(int argc, char *argv[]) return -1; } #endif -#ifdef MALLOCDBG - init_malloc_debug(); +#ifdef CRTDBG + init_crtdbg(); +#endif +#ifdef DMALLOC + init_dmalloc(); #endif if ((i=read_args(argc, argv))!=0) return i; diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index d8288490b..aa89a061c 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -466,9 +466,9 @@ report_cleanup(); #include "magic.h" -#ifdef MALLOCDBG +#ifdef CRTDBG void -init_malloc_debug(void) +init_crtdbg(void) { #if (defined(_MSC_VER)) # if MALLOCDBG == 2 @@ -678,6 +678,8 @@ int main(int argc, char *argv[]) { int i; + char * lc_ctype; + char * lc_numeric; char zText[MAX_PATH]; setup_signal_handler(); @@ -689,16 +691,18 @@ main(int argc, char *argv[]) "Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version()); - setlocale(LC_ALL, ""); - setlocale(LC_NUMERIC, "C"); + lc_ctype = setlocale(LC_CTYPE, ""); + lc_numeric = setlocale(LC_NUMERIC, "C"); + if (lc_ctype) lc_ctype = strdup(lc_ctype); + if (lc_numeric) lc_numeric = strdup(lc_numeric); #ifdef LOCALE_CHECK if (!locale_check()) { log_error(("The current locale is not suitable for international Eressea.\n")); return -1; } #endif -#ifdef MALLOCDBG - init_malloc_debug(); +#ifdef CRTDBG + init_crtdbg(); #endif lua_State * luaState = lua_init(); @@ -739,5 +743,11 @@ main(int argc, char *argv[]) kernel_done(); lua_done(luaState); log_close(); + + setlocale(LC_CTYPE, lc_ctype); + setlocale(LC_NUMERIC, lc_numeric); + free(lc_ctype); + free(lc_numeric); + return 0; }