Add ENABLE_MEMLEAK parameter to CMakeLists.txt (fix jmem.cpp so it can be compiled when MEMLEAK is defined).

This commit is contained in:
David Capello 2010-10-10 16:47:01 -03:00
parent f85070c1c6
commit f86c306bab
3 changed files with 16 additions and 11 deletions

View File

@ -16,6 +16,7 @@ option(USE_STATIC_ALLEGRO "Use static version of Allegro library" off)
option(USE_SHARED_JPEGLIB "Use your installed copy of jpeglib" off) option(USE_SHARED_JPEGLIB "Use your installed copy of jpeglib" off)
option(USE_SHARED_ZLIB "Use your installed copy of zlib" off) option(USE_SHARED_ZLIB "Use your installed copy of zlib" off)
option(USE_SHARED_LIBPNG "Use your installed copy of libpng" off) option(USE_SHARED_LIBPNG "Use your installed copy of libpng" off)
option(ENABLE_MEMLEAK "Enable memory-leaks detector (only for developers)" off)
###################################################################### ######################################################################
# Directories of third-party libraries # Directories of third-party libraries
@ -49,6 +50,10 @@ if(USE_STATIC_ALLEGRO)
add_definitions(-DALLEGRO_STATICLINK) add_definitions(-DALLEGRO_STATICLINK)
endif() endif()
if(ENABLE_MEMLEAK)
add_definitions(-DMEMLEAK)
endif()
###################################################################### ######################################################################
# Main ASE targets # Main ASE targets

View File

@ -10,10 +10,14 @@ if(WIN32)
User32 Shell32 ComCtl32 ComDlg32 Gdi32 Msimg32 User32 Shell32 ComCtl32 ComDlg32 Gdi32 Msimg32
WinMM AdvAPI32 Ole32 ShLwApi Vfw32 WinInet PsApi WinMM AdvAPI32 Ole32 ShLwApi Vfw32 WinInet PsApi
DDraw DxGuid DSound DInput8) DDraw DxGuid DSound DInput8)
if(MSVC AND ENABLE_MEMLEAK)
set(sys_libs ${sys_libs} dbghelp)
endif()
else() else()
# Pthreads # Pthreads
set(sys_libs ${sys_libs} set(sys_libs ${sys_libs} pthread)
pthread)
# Allegro library on Unix like systems # Allegro library on Unix like systems
find_program(allegro_config "allegro-config") find_program(allegro_config "allegro-config")

View File

@ -55,13 +55,9 @@ char *jstrdup(const char *string)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// With leak detection // With leak detection
#if defined(__GNUC__) #define BACKTRACE_LEVELS 16
#define BACKTRACE_LEVELS 4
#else
#define BACKTRACE_LEVELS 16
#endif
#if defined _MSC_VER #ifdef _MSC_VER
#include <windows.h> #include <windows.h>
#include <dbghelp.h> #include <dbghelp.h>
@ -109,7 +105,7 @@ typedef struct slot_t
static bool memleak_status = false; static bool memleak_status = false;
static slot_t* headslot; static slot_t* headslot;
static Mutex mutex; static Mutex* mutex = NULL;
void _jmemleak_init() void _jmemleak_init()
{ {
@ -210,7 +206,7 @@ static void addslot(void *ptr, unsigned long size)
p->size = size; p->size = size;
p->next = headslot; p->next = headslot;
ScopedLock lock(mutex); ScopedLock lock(*mutex);
headslot = p; headslot = p;
} }
@ -223,7 +219,7 @@ static void delslot(void *ptr)
ASSERT(ptr != NULL); ASSERT(ptr != NULL);
ScopedLock lock(mutex); ScopedLock lock(*mutex);
for (it=headslot; it!=NULL; prev=it, it=it->next) { for (it=headslot; it!=NULL; prev=it, it=it->next) {
if (it->ptr == ptr) { if (it->ptr == ptr) {