making dmalloc work again

This commit is contained in:
Enno Rehling 2005-05-07 10:07:06 +00:00
parent ced0d324e6
commit 264880cc7b
7 changed files with 40 additions and 43 deletions

View File

@ -21,6 +21,12 @@ if ! $(CCACHE_DIR) {
Echo Compiling with ccache ; Echo Compiling with ccache ;
} }
if $(DMALLOC) {
Echo Compiling with dmalloc ;
CCFLAGS += -DUSE_DMALLOC ;
LINKFLAGS += -ldmalloc ;
}
if $(PROFILE) = 1 { if $(PROFILE) = 1 {
Echo Compiling with profiler ; Echo Compiling with profiler ;
CCFLAGS += -pg -g ; CCFLAGS += -pg -g ;

View File

@ -3911,11 +3911,6 @@ do_battle(void)
/* Auswirkungen berechnen: */ /* Auswirkungen berechnen: */
aftermath(b); aftermath(b);
/*
#ifdef MALLOCDBG
assert(_CrtCheckMemory());
#endif
*/
/* Hier ist das Gefecht beendet, und wir können die /* Hier ist das Gefecht beendet, und wir können die
* Hilfsstrukturen * wieder löschen: */ * Hilfsstrukturen * wieder löschen: */

View File

@ -97,7 +97,6 @@ promotelist(void *l, void *p)
insertlist((void_list **)l, (void_list *)p); insertlist((void_list **)l, (void_list *)p);
} }
#ifndef MALLOCDBG
void void
removelist(void *l, void *p) removelist(void *l, void *p)
{ {
@ -124,7 +123,6 @@ freelist(void *p1)
p = p2; p = p2;
} }
} }
#endif
void void
invert_list(void * heap) invert_list(void * heap)

View File

@ -89,7 +89,7 @@ mt_new_va(const char * name, ...)
typedef struct arg_type { typedef struct arg_type {
struct arg_type * next; struct arg_type * next;
const char * name; const char * name;
void (*free)(void*); void (*release)(void*);
void* (*copy)(void*); void* (*copy)(void*);
} arg_type; } 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)); arg_type * atype = (arg_type *)malloc(sizeof(arg_type));
atype->name = name; atype->name = name;
atype->next = argtypes; atype->next = argtypes;
atype->free = free_arg; atype->release = free_arg;
atype->copy = copy_arg; atype->copy = copy_arg;
argtypes = atype; argtypes = atype;
} }
@ -130,7 +130,7 @@ static void
free_arg(const char * type, void * data) free_arg(const char * type, void * data)
{ {
arg_type * atype = find_argtype(type); arg_type * atype = find_argtype(type);
if (atype && atype->free) atype->free(data); if (atype && atype->release) atype->release(data);
} }
message * message *

View File

@ -34,37 +34,22 @@ extern "C" {
/**** **** /**** ****
** Debugging Libraries ** ** 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 <mpatrol.h>
#endif
#if defined __GNUC__ #if defined __GNUC__
# define HAVE_INLINE # define HAVE_INLINE
# define INLINE_FUNCTION __inline # define INLINE_FUNCTION __inline
#endif #endif
#ifdef DMALLOC /* define USE_DMALLOC to enable use of the dmalloc library */
# ifndef MALLOCDBG #ifdef USE_DMALLOC
# define MALLOCDBG 1
# endif
# include <stdlib.h> # include <stdlib.h>
# include <string.h>
# include <dmalloc.h> # include <dmalloc.h>
#endif #endif
#if defined(_DEBUG) && defined(_MSC_VER) /* define CRTDBG to enable MSVC CRT Debug library functions */
/* define MALLOCDBG in project settings, not here! */ #if defined(_DEBUG) && defined(_MSC_VER) && defined(CRTDBG)
# ifdef MALLOCDBG
# include <crtdbg.h> # include <crtdbg.h>
# define _CRTDBG_MAP_ALLOC # define _CRTDBG_MAP_ALLOC
# endif
#endif #endif
/**** **** /**** ****

View File

@ -410,9 +410,9 @@ game_done(void)
#include "magic.h" #include "magic.h"
#ifdef MALLOCDBG #ifdef CRTDBG
void void
init_malloc_debug(void) init_crtdbg(void)
{ {
#if (defined(_MSC_VER)) #if (defined(_MSC_VER))
# if MALLOCDBG == 2 # if MALLOCDBG == 2
@ -621,8 +621,11 @@ main(int argc, char *argv[])
return -1; return -1;
} }
#endif #endif
#ifdef MALLOCDBG #ifdef CRTDBG
init_malloc_debug(); init_crtdbg();
#endif
#ifdef DMALLOC
init_dmalloc();
#endif #endif
if ((i=read_args(argc, argv))!=0) return i; if ((i=read_args(argc, argv))!=0) return i;

View File

@ -466,9 +466,9 @@ report_cleanup();
#include "magic.h" #include "magic.h"
#ifdef MALLOCDBG #ifdef CRTDBG
void void
init_malloc_debug(void) init_crtdbg(void)
{ {
#if (defined(_MSC_VER)) #if (defined(_MSC_VER))
# if MALLOCDBG == 2 # if MALLOCDBG == 2
@ -678,6 +678,8 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int i; int i;
char * lc_ctype;
char * lc_numeric;
char zText[MAX_PATH]; char zText[MAX_PATH];
setup_signal_handler(); 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" "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()); "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version());
setlocale(LC_ALL, ""); lc_ctype = setlocale(LC_CTYPE, "");
setlocale(LC_NUMERIC, "C"); 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 #ifdef LOCALE_CHECK
if (!locale_check()) { if (!locale_check()) {
log_error(("The current locale is not suitable for international Eressea.\n")); log_error(("The current locale is not suitable for international Eressea.\n"));
return -1; return -1;
} }
#endif #endif
#ifdef MALLOCDBG #ifdef CRTDBG
init_malloc_debug(); init_crtdbg();
#endif #endif
lua_State * luaState = lua_init(); lua_State * luaState = lua_init();
@ -739,5 +743,11 @@ main(int argc, char *argv[])
kernel_done(); kernel_done();
lua_done(luaState); lua_done(luaState);
log_close(); log_close();
setlocale(LC_CTYPE, lc_ctype);
setlocale(LC_NUMERIC, lc_numeric);
free(lc_ctype);
free(lc_numeric);
return 0; return 0;
} }