summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-22 04:48:52 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-22 04:48:52 +0000
commit0c97c8e33584e6203bb09c08f92b63bd2cca8ae7 (patch)
tree8006036c98680136b7470af4431d95663fcfffec /st.c
parent56173249ef486db321c8aa01a680966f921f5201 (diff)
* hash.c (rb_hash_rehash): add iteration check. [ruby-dev:24301]
* st.c (st_foreach): add deep check. * hash.c (rb_hash_fetch): returns KeyError instead of IndexError. * hash.c (env_fetch): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/st.c b/st.c
index 753dce9..12ed401 100644
--- a/st.c
+++ b/st.c
@@ -3,6 +3,7 @@
/* static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */
#include "config.h"
+#include "defines.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -492,8 +493,21 @@ st_foreach(table, func, arg)
for(i = 0; i < table->num_bins; i++) {
last = 0;
for(ptr = table->bins[i]; ptr != 0;) {
- retval = (*func)(ptr->key, ptr->record, arg);
+ retval = (*func)(ptr->key, ptr->record, arg, 0);
switch (retval) {
+ case ST_CHECK: /* check if hash is modified during iteration */
+ tmp = 0;
+ if (i < table->num_bins) {
+ for (tmp = table->bins[i]; tmp; tmp=tmp->next) {
+ if (tmp == ptr) break;
+ }
+ }
+ if (!tmp) {
+ /* call func with error notice */
+ retval = (*func)(0, 0, arg, 1);
+ return;
+ }
+ /* fall through */
case ST_CONTINUE:
last = ptr;
ptr = ptr->next;