[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59222] trunk/blender/source/blender: add assert for hashes if an existing element is ever inserted into a ghash /edgehash.
Campbell Barton
ideasman42 at gmail.com
Sun Aug 18 02:36:05 CEST 2013
Revision: 59222
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59222
Author: campbellbarton
Date: 2013-08-18 00:36:04 +0000 (Sun, 18 Aug 2013)
Log Message:
-----------
add assert for hashes if an existing element is ever inserted into a ghash/edgehash.
the outliner does this intentionally, so add a flag to allow this situation optionally.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_edgehash.h
trunk/blender/source/blender/blenlib/BLI_ghash.h
trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
trunk/blender/source/blender/blenlib/intern/edgehash.c
trunk/blender/source/blender/editors/space_outliner/outliner_tree.c
trunk/blender/source/blender/makesdna/DNA_space_types.h
Modified: trunk/blender/source/blender/blenlib/BLI_edgehash.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_edgehash.h 2013-08-18 00:13:51 UTC (rev 59221)
+++ trunk/blender/source/blender/blenlib/BLI_edgehash.h 2013-08-18 00:36:04 UTC (rev 59222)
@@ -36,6 +36,10 @@
typedef void (*EdgeHashFreeFP)(void *key);
+enum {
+ EDGEHASH_FLAG_ALLOW_DUPES = (1 << 0), /* only checked for in debug mode */
+};
+
EdgeHash *BLI_edgehash_new(void);
void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP valfreefp);
@@ -65,6 +69,9 @@
/* Remove all edges from hash. */
void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP valfreefp);
+void BLI_edgehash_flag_set(EdgeHash *eh, unsigned short flag);
+void BLI_edgehash_flag_clear(EdgeHash *eh, unsigned short flag);
+
/***/
/**
Modified: trunk/blender/source/blender/blenlib/BLI_ghash.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_ghash.h 2013-08-18 00:13:51 UTC (rev 59221)
+++ trunk/blender/source/blender/blenlib/BLI_ghash.h 2013-08-18 00:36:04 UTC (rev 59222)
@@ -42,28 +42,18 @@
typedef void (*GHashKeyFreeFP) (void *key);
typedef void (*GHashValFreeFP) (void *val);
-typedef struct Entry {
- struct Entry *next;
+typedef struct GHash GHash;
- void *key, *val;
-} Entry;
-
-typedef struct GHash {
- GHashHashFP hashfp;
- GHashCmpFP cmpfp;
-
- Entry **buckets;
- struct BLI_mempool *entrypool;
- unsigned int nbuckets;
- unsigned int nentries, cursize;
-} GHash;
-
typedef struct GHashIterator {
GHash *gh;
unsigned int curBucket;
struct Entry *curEntry;
} GHashIterator;
+enum {
+ GHASH_FLAG_ALLOW_DUPES = (1 << 0), /* only checked for in debug mode */
+};
+
/* *** */
GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info);
@@ -75,6 +65,8 @@
void *BLI_ghash_pop(GHash *gh, void *key, GHashKeyFreeFP keyfreefp);
bool BLI_ghash_haskey(GHash *gh, const void *key);
int BLI_ghash_size(GHash *gh);
+void BLI_ghash_flag_set(GHash *gh, unsigned short flag);
+void BLI_ghash_flag_clear(GHash *gh, unsigned short flag);
/* *** */
Modified: trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_ghash.c 2013-08-18 00:13:51 UTC (rev 59221)
+++ trunk/blender/source/blender/blenlib/intern/BLI_ghash.c 2013-08-18 00:36:04 UTC (rev 59222)
@@ -62,6 +62,27 @@
/***/
+typedef struct Entry {
+ struct Entry *next;
+
+ void *key, *val;
+} Entry;
+
+typedef struct GHash {
+ GHashHashFP hashfp;
+ GHashCmpFP cmpfp;
+
+ Entry **buckets;
+ struct BLI_mempool *entrypool;
+ unsigned int nbuckets;
+ unsigned int nentries;
+ unsigned short cursize, flag;
+} GHash;
+
+
+/* -------------------------------------------------------------------- */
+/* GHash API */
+
GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info)
{
GHash *gh = MEM_mallocN(sizeof(*gh), info);
@@ -88,6 +109,8 @@
unsigned int hash = gh->hashfp(key) % gh->nbuckets;
Entry *e = (Entry *)BLI_mempool_alloc(gh->entrypool);
+ BLI_assert((gh->flag & GHASH_FLAG_ALLOW_DUPES) || (BLI_ghash_haskey(gh, key) == 0));
+
e->next = gh->buckets[hash];
e->key = key;
e->val = val;
@@ -252,8 +275,20 @@
MEM_freeN(gh);
}
-/***/
+void BLI_ghash_flag_set(GHash *gh, unsigned short flag)
+{
+ gh->flag |= flag;
+}
+void BLI_ghash_flag_clear(GHash *gh, unsigned short flag)
+{
+ gh->flag &= (unsigned short)~flag;
+}
+
+
+/* -------------------------------------------------------------------- */
+/* GHash Iterator API */
+
GHashIterator *BLI_ghashIterator_new(GHash *gh)
{
GHashIterator *ghi = MEM_mallocN(sizeof(*ghi), "ghash iterator");
Modified: trunk/blender/source/blender/blenlib/intern/edgehash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/edgehash.c 2013-08-18 00:13:51 UTC (rev 59221)
+++ trunk/blender/source/blender/blenlib/intern/edgehash.c 2013-08-18 00:36:04 UTC (rev 59222)
@@ -76,7 +76,8 @@
struct EdgeHash {
EdgeEntry **buckets;
BLI_mempool *epool;
- unsigned int nbuckets, nentries, cursize;
+ unsigned int nbuckets, nentries;
+ unsigned short cursize, flag;
};
/***/
@@ -100,6 +101,8 @@
unsigned int hash;
EdgeEntry *e = BLI_mempool_alloc(eh->epool);
+ BLI_assert((eh->flag & EDGEHASH_FLAG_ALLOW_DUPES) || (BLI_edgehash_haskey(eh, v0, v1) == 0));
+
/* this helps to track down errors with bad edge data */
BLI_assert(v0 != v1);
@@ -199,6 +202,16 @@
}
+void BLI_edgehash_flag_set(EdgeHash *eh, unsigned short flag)
+{
+ eh->flag |= flag;
+}
+
+void BLI_edgehash_flag_clear(EdgeHash *eh, unsigned short flag)
+{
+ eh->flag &= (unsigned short)~flag;
+}
+
/***/
struct EdgeHashIterator {
Modified: trunk/blender/source/blender/editors/space_outliner/outliner_tree.c
===================================================================
--- trunk/blender/source/blender/editors/space_outliner/outliner_tree.c 2013-08-18 00:13:51 UTC (rev 59221)
+++ trunk/blender/source/blender/editors/space_outliner/outliner_tree.c 2013-08-18 00:36:04 UTC (rev 59222)
@@ -194,6 +194,7 @@
}
if (soops->treehash == NULL) {
soops->treehash = BLI_ghash_new(tse_hash, tse_cmp, "treehash");
+ BLI_ghash_flag_set(soops->treehash, GHASH_FLAG_ALLOW_DUPES);
}
if (restore_treehash) {
Modified: trunk/blender/source/blender/makesdna/DNA_space_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_space_types.h 2013-08-18 00:13:51 UTC (rev 59221)
+++ trunk/blender/source/blender/makesdna/DNA_space_types.h 2013-08-18 00:36:04 UTC (rev 59222)
@@ -253,7 +253,7 @@
struct TreeStoreElem search_tse;
short flag, outlinevis, storeflag, search_flags;
- struct GHash *treehash;
+ struct GHash *treehash; /* note, allows duplicates */
} SpaceOops;
More information about the Bf-blender-cvs
mailing list