[Bf-blender-cvs] [a359b4d] temp-ghash-experiments: Fix crashing GHashIterators.

Bastien Montagne noreply at git.blender.org
Sun Mar 1 21:28:17 CET 2015


Commit: a359b4d99b892c932b90a36391e278d9355f9dea
Author: Bastien Montagne
Date:   Sun Mar 1 18:43:57 2015 +0100
Branches: temp-ghash-experiments
https://developer.blender.org/rBa359b4d99b892c932b90a36391e278d9355f9dea

Fix crashing GHashIterators.

Inlined accessors are using a another struct than Entry itself,
those two must match perfectly!

Also fix a few other minor typo/mistakes, and come back to modulo
bucket-hashing for now.

===================================================================

M	source/blender/blenlib/BLI_ghash.h
M	source/blender/blenlib/intern/BLI_ghash.c

===================================================================

diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h
index 41fe923..e36ebd4 100644
--- a/source/blender/blenlib/BLI_ghash.h
+++ b/source/blender/blenlib/BLI_ghash.h
@@ -94,7 +94,7 @@ BLI_INLINE void  *BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSE
 BLI_INLINE void **BLI_ghashIterator_getValue_p(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT;
 BLI_INLINE bool   BLI_ghashIterator_done(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT;
 
-struct _gh_Entry { void *next, *key, *val; };
+struct _gh_Entry { void *next; unsigned int hash; void *key, *val; };
 BLI_INLINE void  *BLI_ghashIterator_getKey(GHashIterator *ghi)     { return  ((struct _gh_Entry *)ghi->curEntry)->key; }
 BLI_INLINE void  *BLI_ghashIterator_getValue(GHashIterator *ghi)   { return  ((struct _gh_Entry *)ghi->curEntry)->val; }
 BLI_INLINE void **BLI_ghashIterator_getValue_p(GHashIterator *ghi) { return &((struct _gh_Entry *)ghi->curEntry)->val; }
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index a1f673d..590fe74 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -47,7 +47,7 @@
 #include "BLI_ghash.h"
 #include "BLI_strict_flags.h"
 
-//#define GHASH_USE_MODULO_BUCKETS
+#define GHASH_USE_MODULO_BUCKETS
 
 /* Also used by smallhash! */
 const unsigned int hashsizes[] = {
@@ -79,6 +79,7 @@ const unsigned int hashsizes[] = {
 
 /***/
 
+/* WARNING! Keep in sync with ugly _gh_Entry in header!!! */
 typedef struct Entry {
 	struct Entry *next;
 
@@ -1196,12 +1197,12 @@ GSet *BLI_gset_pair_new(const char *info)
 int BLI_ghash_buckets_size(GHash *gh)
 {
 #ifdef GHASH_USE_MODULO_BUCKETS
-	return hashsizes[gh->cursize];
+	return (int)hashsizes[gh->cursize];
 #else
 	return 1 << gh->bucket_bit;
 #endif
 }
-int BLI_set_buckets_size(GSet *gs)
+int BLI_gset_buckets_size(GSet *gs)
 {
 	return BLI_ghash_buckets_size((GHash *)gs);
 }




More information about the Bf-blender-cvs mailing list