Revision: 28572
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28572
Author:   joeedh
Date:     2010-05-04 15:36:32 +0200 (Tue, 04 May 2010)

Log Message:
-----------
ghash debug mode, compile with GHASH_DEBUG_LEAKS defined and ghash will append 
the file/line BLI_ghash_new was called from to the tag str it passed to 
MEM_mallocN

Modified Paths:
--------------
    branches/render25/source/blender/blenlib/BLI_ghash.h
    branches/render25/source/blender/blenlib/intern/BLI_ghash.c

Modified: branches/render25/source/blender/blenlib/BLI_ghash.h
===================================================================
--- branches/render25/source/blender/blenlib/BLI_ghash.h        2010-05-04 
12:31:24 UTC (rev 28571)
+++ branches/render25/source/blender/blenlib/BLI_ghash.h        2010-05-04 
13:36:32 UTC (rev 28572)
@@ -63,6 +63,9 @@
        
        Entry **buckets;
        struct BLI_mempool *entrypool;
+#ifdef GHASH_DEBUG_LEAKS
+       const char *tag;
+#endif
        int nbuckets, nentries, cursize;
 } GHash;
 
@@ -72,7 +75,12 @@
        struct Entry *curEntry;
 } GHashIterator;
 
-GHash* BLI_ghash_new           (GHashHashFP hashfp, GHashCmpFP cmpfp);
+#ifndef GHASH_DEBUG_LEAKS
+       GHash*  BLI_ghash_new           (GHashHashFP hashfp, GHashCmpFP cmpfp);
+#else
+       GHash *_BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, char *file, 
int line);
+       #define BLI_ghash_new(hashfp, cmpfp) _BLI_ghash_new(hashfp, cmpfp, 
__FILE__, __LINE__)
+#endif
 void   BLI_ghash_free          (GHash *gh, GHashKeyFreeFP keyfreefp, 
GHashValFreeFP valfreefp);
 
 //BM_INLINE void       BLI_ghash_insert        (GHash *gh, void *key, void 
*val);

Modified: branches/render25/source/blender/blenlib/intern/BLI_ghash.c
===================================================================
--- branches/render25/source/blender/blenlib/intern/BLI_ghash.c 2010-05-04 
12:31:24 UTC (rev 28571)
+++ branches/render25/source/blender/blenlib/intern/BLI_ghash.c 2010-05-04 
13:36:32 UTC (rev 28572)
@@ -45,8 +45,20 @@
 
 /***/
 
+#ifdef GHASH_DEBUG_LEAKS
+GHash *_BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, char *file, int 
line) {
+       const char *str = calloc(1, strlen(file) + 32);
+       GHash *gh;
+
+       sprintf(str, "gh...@%s:%d", file, line);
+
+       gh = MEM_mallocN(sizeof(*gh), str);
+       gh->tag = str;
+
+#else
 GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp) {
        GHash *gh= MEM_mallocN(sizeof(*gh), "GHash");
+#endif
        gh->hashfp= hashfp;
        gh->cmpfp= cmpfp;
        gh->entrypool = BLI_mempool_create(sizeof(Entry), 64, 64, 0);
@@ -93,6 +105,10 @@
        gh->nentries = 0;
        gh->nbuckets = 0;
        MEM_freeN(gh);
+
+#ifdef GHASH_DEBUG_LEAKS
+       free(gh->tag);
+#endif
 }
 
 /***/


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to