compile time option to override C++'s new/delete to use guardedalloc, useful for...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 18 Aug 2009 15:20:29 +0000 (15:20 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 18 Aug 2009 15:20:29 +0000 (15:20 +0000)
CMakeLists.txt
blenderplayer/CMakeLists.txt
intern/guardedalloc/CMakeLists.txt
intern/guardedalloc/cpp/mallocn.cpp [new file with mode: 0644]
source/creator/CMakeLists.txt

index 16110e766079fb612f46a263618b509d62b6091e..2f12d34272671c87cc9008ec217bbc031a517c0c 100644 (file)
@@ -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 "")
index 4539701a3ae7ad14b1781d0162b97b27c073dfe4..77bc059a6a0b9f748f0fee6fbf89dce3905f8a97 100644 (file)
@@ -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})
index af64fb99d5849442baf28f15f9b7f5a060767871..b29837fac7d4d5e38fff4d0d4a6cd8af98415658 100644 (file)
@@ -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 (file)
index 0000000..bb2839c
--- /dev/null
@@ -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);
+}
index a0ebf627e2c958410ed21098a9383eddcf570b88..a9368e021cd11222e16736d268f2be0a129fcada 100644 (file)
@@ -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})