[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60527] trunk/blender: add cmake option WITH_MEM_VALGRIND, helps to track down errors with mempool use which sometimes only show up as bugs in very rare cases (because even though the element is freed, the chunk is still allocated).
Campbell Barton
ideasman42 at gmail.com
Thu Oct 3 14:22:45 CEST 2013
Revision: 60527
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60527
Author: campbellbarton
Date: 2013-10-03 12:22:44 +0000 (Thu, 03 Oct 2013)
Log Message:
-----------
add cmake option WITH_MEM_VALGRIND, helps to track down errors with mempool use which sometimes only show up as bugs in very rare cases (because even though the element is freed, the chunk is still allocated).
Modified Paths:
--------------
trunk/blender/CMakeLists.txt
trunk/blender/source/blender/blenlib/CMakeLists.txt
trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
Modified: trunk/blender/CMakeLists.txt
===================================================================
--- trunk/blender/CMakeLists.txt 2013-10-03 10:50:03 UTC (rev 60526)
+++ trunk/blender/CMakeLists.txt 2013-10-03 12:22:44 UTC (rev 60527)
@@ -278,6 +278,10 @@
option(WITH_MEM_JEMALLOC "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
mark_as_advanced(WITH_MEM_JEMALLOC)
+# currently only used for BLI_mempool
+option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
+mark_as_advanced(WITH_MEM_VALGRIND)
+
# Debug
option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
mark_as_advanced(WITH_CXX_GUARDEDALLOC)
Modified: trunk/blender/source/blender/blenlib/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/blenlib/CMakeLists.txt 2013-10-03 10:50:03 UTC (rev 60526)
+++ trunk/blender/source/blender/blenlib/CMakeLists.txt 2013-10-03 12:22:44 UTC (rev 60527)
@@ -178,6 +178,10 @@
add_definitions(-DWITH_BINRELOC)
endif()
+if(WITH_MEM_VALGRIND)
+ add_definitions(-DWITH_MEM_VALGRIND)
+endif()
+
if(WIN32)
list(APPEND INC
../../../intern/utfconv
Modified: trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_mempool.c 2013-10-03 10:50:03 UTC (rev 60526)
+++ trunk/blender/source/blender/blenlib/intern/BLI_mempool.c 2013-10-03 12:22:44 UTC (rev 60527)
@@ -45,6 +45,9 @@
#include "BLI_strict_flags.h" /* keep last */
+#ifdef WITH_MEM_VALGRIND
+# include "valgrind/memcheck.h"
+#endif
/* note: copied from BLO_blend_defs.h, don't use here because we're in BLI */
#ifdef __BIG_ENDIAN__
@@ -275,6 +278,10 @@
lasttail = mempool_chunk_add(pool, mpchunk, lasttail);
}
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_CREATE_MEMPOOL(pool, 0, false);
+#endif
+
return pool;
}
@@ -297,6 +304,11 @@
}
pool->free = pool->free->next;
+
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_MEMPOOL_ALLOC(pool, retval, pool->esize);
+#endif
+
return retval;
}
@@ -367,6 +379,10 @@
}
curnode->next = NULL; /* terminate the list */
}
+
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_MEMPOOL_FREE(pool, addr);
+#endif
}
int BLI_mempool_count(BLI_mempool *pool)
@@ -582,6 +598,10 @@
{
mempool_chunk_free_all(&pool->chunks, pool->flag);
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_DESTROY_MEMPOOL(pool);
+#endif
+
if (pool->flag & BLI_MEMPOOL_SYSMALLOC) {
free(pool);
}
More information about the Bf-blender-cvs
mailing list