compile time option to override C++'s new/delete to use guardedalloc, useful for debugging. shows memory leaks very quickly. currently cmake only - WITH_CXX_GUARDEDALLOC

This commit is contained in:
Campbell Barton 2009-08-18 15:20:29 +00:00
parent 3803a3c5a7
commit ede954b938
5 changed files with 61 additions and 1 deletions

@ -70,6 +70,7 @@ OPTION(WITH_OPENMP "Enable OpenMP (has to be supported by the compiler)"
OPTION(WITH_WEBPLUGIN "Enable Web Plugin (Unix only)" OFF)
OPTION(WITH_FFTW3 "Enable FFTW3 support" OFF)
OPTION(WITH_JACK "Enable Jack Support (http://www.jackaudio.org)" OFF)
OPTION(WITH_CXX_GUARDEDALLOC "" OFF)
OPTION(WITH_INSTALL "Install accompanying scripts and language files needed to run blender" ON)
IF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
@ -514,6 +515,11 @@ INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
# better not define flags here but this is a debugging option thats off by default.
IF(WITH_CXX_GUARDEDALLOC)
SET(CMAKE_CXX_FLAGS " -DWITH_CXX_GUARDEDALLOC -I${CMAKE_SOURCE_DIR}/intern/guardedalloc ${CMAKE_CXX_FLAGS}")
ENDIF(WITH_CXX_GUARDEDALLOC)
#-----------------------------------------------------------------------------
# Libraries
FILE(WRITE ${CMAKE_BINARY_DIR}/cmake_blender_libs.txt "")

@ -110,6 +110,10 @@ IF(UNIX)
extern_glew
)
IF(WITH_CXX_GUARDEDALLOC)
SET(BLENDER_SORTED_LIBS ${BLENDER_SORTED_LIBS} bf_guardedalloc_cpp)
ENDIF(WITH_CXX_GUARDEDALLOC)
FOREACH(SORTLIB ${BLENDER_SORTED_LIBS})
SET(REMLIB ${SORTLIB})
FOREACH(SEARCHLIB ${BLENDER_LINK_LIBS})

@ -29,4 +29,9 @@ SET(INC .)
FILE(GLOB SRC intern/*.c)
BLENDERLIB(bf_guardedalloc "${SRC}" "${INC}")
#, libtype=['intern', 'player'], priority = [10, 175] )
# Override C++ alloc optional
IF(WITH_CXX_GUARDEDALLOC)
FILE(GLOB SRC cpp/*.cpp)
BLENDERLIB(bf_guardedalloc_cpp "${SRC}" "${INC}")
ENDIF(WITH_CXX_GUARDEDALLOC)

@ -0,0 +1,41 @@
/**
* $Id: mallocn.c 21060 2009-06-21 16:37:13Z campbellbarton $
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <new>
#include "../MEM_guardedalloc.h"
void* operator new (size_t size)
{
return MEM_mallocN(size, "c++/anonymous");
}
/* not default but can be used when needing to set a string */
void* operator new (size_t size, const char *str)
{
return MEM_mallocN(size, str);
}
void operator delete (void *p)
{
MEM_freeN(p);
}

@ -348,6 +348,10 @@ IF(UNIX)
bf_audaspace
)
IF(WITH_CXX_GUARDEDALLOC)
SET(BLENDER_SORTED_LIBS ${BLENDER_SORTED_LIBS} bf_guardedalloc_cpp)
ENDIF(WITH_CXX_GUARDEDALLOC)
FOREACH(SORTLIB ${BLENDER_SORTED_LIBS})
SET(REMLIB ${SORTLIB})
FOREACH(SEARCHLIB ${BLENDER_LINK_LIBS})