summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-07 05:29:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-07 05:29:20 +0000
commitad40f8a268634ff94f2dad1412233a4b1f3751c5 (patch)
treee426a2cfcb4292d70b12b62a2f175cfc5f7123e9 /st.c
parentbdb4fa708465479259cbe2f0215376f6252b7773 (diff)
* st.c (st_foreach): should not yield same pair when checking
after unpacking. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/st.c b/st.c
index ba21b31a5b..56ee31e281 100644
--- a/st.c
+++ b/st.c
@@ -745,7 +745,14 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
key = (st_data_t)table->bins[i*2];
val = (st_data_t)table->bins[i*2+1];
retval = (*func)(key, val, arg);
- if (!table->entries_packed) goto unpacked;
+ if (!table->entries_packed) {
+ FIND_ENTRY(table, ptr, key, i);
+ if (retval == ST_CHECK) {
+ if (!ptr) goto deleted;
+ goto unpacked_continue;
+ }
+ goto unpacked;
+ }
switch (retval) {
case ST_CHECK: /* check if hash is modified during iteration */
for (j = 0; j < table->num_entries; j++) {
@@ -753,9 +760,7 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
break;
}
if (j == table->num_entries) {
- /* call func with error notice */
- retval = (*func)(0, 0, arg, 1);
- return 1;
+ goto deleted;
}
/* fall through */
case ST_CONTINUE:
@@ -771,11 +776,6 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
}
}
return 0;
- unpacked:
- ptr = table->head;
- while (i-- > 0) {
- if (!(ptr = ptr->fore)) return 0;
- }
}
else {
ptr = table->head;
@@ -785,10 +785,12 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
do {
i = ptr->hash % table->num_bins;
retval = (*func)(ptr->key, ptr->record, arg);
+ unpacked:
switch (retval) {
case ST_CHECK: /* check if hash is modified during iteration */
for (tmp = table->bins[i]; tmp != ptr; tmp = tmp->next) {
if (!tmp) {
+ deleted:
/* call func with error notice */
retval = (*func)(0, 0, arg, 1);
return 1;
@@ -796,6 +798,7 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
}
/* fall through */
case ST_CONTINUE:
+ unpacked_continue:
ptr = ptr->fore;
break;
case ST_STOP: