[asterisk-commits] murf: branch murf/datastructs r69624 - in /team/murf/datastructs: main/ utils/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Jun 16 23:25:00 CDT 2007
Author: murf
Date: Sat Jun 16 23:24:59 2007
New Revision: 69624
URL: http://svn.digium.com/view/asterisk?view=rev&rev=69624
Log:
Cleaned up some probs in hashtest, and found one small mistake in the lookup routine, where I accessed a hashbucket outside of a lock. Thanks to valgrind for that one...
Modified:
team/murf/datastructs/main/hashtab.c
team/murf/datastructs/utils/hashtest.c
Modified: team/murf/datastructs/main/hashtab.c
URL: http://svn.digium.com/view/asterisk/team/murf/datastructs/main/hashtab.c?view=diff&rev=69624&r1=69623&r2=69624
==============================================================================
--- team/murf/datastructs/main/hashtab.c (original)
+++ team/murf/datastructs/main/hashtab.c Sat Jun 16 23:24:59 2007
@@ -409,6 +409,7 @@
{
/* lookup this object in the hash table. return a ptr if found, or NULL if not */
int h;
+ const void *ret;
struct ast_hashtab_bucket *b;
if (!tab || !obj)
return 0;
@@ -418,9 +419,10 @@
h = (*tab->hash)(obj, tab->hash_tab_size);
for (b=tab->array[h]; b; b=b->next) {
if ((*tab->compare)(obj,b->object) == 0) {
+ ret = b->object;
if (tab->do_locking)
ast_rwlock_unlock(&tab->lock);
- return (void*)b->object; /* I can't touch obj in this func, but the outside world is welcome to */
+ return (void*)ret; /* I can't touch obj in this func, but the outside world is welcome to */
}
}
if (tab->do_locking)
@@ -570,10 +572,7 @@
static void *ast_hashtab_remove_object_internal(struct ast_hashtab *tab, struct ast_hashtab_bucket *b, int h)
{
const void *obj2;
-#ifdef FOR_DEBUG
- int c2;
-#endif
-
+
if (b->prev) {
b->prev->next = b->next;
} else {
@@ -590,28 +589,32 @@
b->object = b->next = (void*)2;
free(b); /* free up the hashbucket */
tab->hash_tab_elements--;
-#ifdef FOR_DEBUG
- /* do a little checking */
- for (c2 = 0, b2 = tab->tlist;b2;b2=b2->tnext) {
- c2++;
- }
- if (c2 != tab->hash_tab_elements) {
- printf("Hey! we didn't delete right! there are %d elements in the list, and we expected %d\n",
- c2, tab->hash_tab_elements);
- }
- for (c2 = 0, b2 = tab->tlist;b2;b2=b2->tnext) {
- unsigned int obj3 = (unsigned long)obj2;
- unsigned int b3 = (unsigned long)b;
- if (b2->object == obj2)
- printf("Hey-- you've still got a bucket pointing at ht_element %x\n", obj3);
- if (b2->next == b)
- printf("Hey-- you've still got a bucket with next ptr pointing to deleted bucket %x\n", b3);
- if (b2->prev == b)
- printf("Hey-- you've still got a bucket with prev ptr pointing to deleted bucket %x\n", b3);
- if (b2->tprev == b)
- printf("Hey-- you've still got a bucket with tprev ptr pointing to deleted bucket %x\n", b3);
- if (b2->tnext == b)
- printf("Hey-- you've still got a bucket with tnext ptr pointing to deleted bucket %x\n", b3);
+#ifdef DEBUG
+ {
+ int c2;
+ struct ast_hashtab_bucket *b2;
+ /* do a little checking */
+ for (c2 = 0, b2 = tab->tlist;b2;b2=b2->tnext) {
+ c2++;
+ }
+ if (c2 != tab->hash_tab_elements) {
+ printf("Hey! we didn't delete right! there are %d elements in the list, and we expected %d\n",
+ c2, tab->hash_tab_elements);
+ }
+ for (c2 = 0, b2 = tab->tlist;b2;b2=b2->tnext) {
+ unsigned int obj3 = (unsigned long)obj2;
+ unsigned int b3 = (unsigned long)b;
+ if (b2->object == obj2)
+ printf("Hey-- you've still got a bucket pointing at ht_element %x\n", obj3);
+ if (b2->next == b)
+ printf("Hey-- you've still got a bucket with next ptr pointing to deleted bucket %x\n", b3);
+ if (b2->prev == b)
+ printf("Hey-- you've still got a bucket with prev ptr pointing to deleted bucket %x\n", b3);
+ if (b2->tprev == b)
+ printf("Hey-- you've still got a bucket with tprev ptr pointing to deleted bucket %x\n", b3);
+ if (b2->tnext == b)
+ printf("Hey-- you've still got a bucket with tnext ptr pointing to deleted bucket %x\n", b3);
+ }
}
#endif
return (void*)obj2; /* inside this code, the obj's are untouchable, but outside, they aren't */
@@ -702,6 +705,7 @@
return (void*)obj2; /* inside this code, the obj's are untouchable, but outside, they aren't */
}
}
+
if (tab->do_locking)
ast_rwlock_unlock(&tab->lock);
return 0;
Modified: team/murf/datastructs/utils/hashtest.c
URL: http://svn.digium.com/view/asterisk/team/murf/datastructs/utils/hashtest.c?view=diff&rev=69624&r1=69623&r2=69624
==============================================================================
--- team/murf/datastructs/utils/hashtest.c (original)
+++ team/murf/datastructs/utils/hashtest.c Sat Jun 16 23:24:59 2007
@@ -125,18 +125,28 @@
/* pick a random element from 0 to highwater-1 */
x = my_rand(0,glob_highwater-1,seedp);
sprintf(keybuf, "key%08d", x);
-#ifdef DEBUG
- printf("Removing %s\n", keybuf);
+#if DEBUG
+ printf("Removing %s", keybuf);
#endif
lookup.key = keybuf;
- el = ast_hashtab_lookup(glob_hashtab, &lookup);
+ el = ast_hashtab_remove_object_via_lookup(glob_hashtab, &lookup);
+
if (el) {
- if (!ast_hashtab_remove_this_object(glob_hashtab, el)) {
- printf("Problem: key %s could not be removed from the hashtab\n", keybuf);
- }
- else
- els_removed++;
- }
+#if DEBUG
+ printf("...YES (el=%x)\n", (unsigned long)el);
+#endif
+ free(el->key);
+ free(el->val);
+ free(el);
+ els_removed++;
+ } else {
+#if DEBUG
+ printf("...NO.\n");
+#endif
+ return 0;
+ }
+
+
return el;
}
More information about the asterisk-commits
mailing list