diff --git a/CMakeLists.txt b/CMakeLists.txt index 16110e76607..2f12d342726 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 "") diff --git a/blenderplayer/CMakeLists.txt b/blenderplayer/CMakeLists.txt index 4539701a3ae..77bc059a6a0 100644 --- a/blenderplayer/CMakeLists.txt +++ b/blenderplayer/CMakeLists.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}) diff --git a/intern/guardedalloc/CMakeLists.txt b/intern/guardedalloc/CMakeLists.txt index af64fb99d58..b29837fac7d 100644 --- a/intern/guardedalloc/CMakeLists.txt +++ b/intern/guardedalloc/CMakeLists.txt @@ -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) diff --git a/intern/guardedalloc/cpp/mallocn.cpp b/intern/guardedalloc/cpp/mallocn.cpp new file mode 100644 index 00000000000..bb2839c7986 --- /dev/null +++ b/intern/guardedalloc/cpp/mallocn.cpp @@ -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 +#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); +} diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index a0ebf627e2c..a9368e021cd 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -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})