diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-22 04:48:52 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-22 04:48:52 +0000 |
| commit | 7c36ce8ac3efdb899fe479011af3b3da18bae561 (patch) | |
| tree | 8006036c98680136b7470af4431d95663fcfffec /st.c | |
| parent | 22b217dc6fcdf142195ea29a28f5ace02b9a624b (diff) | |
| download | ruby-7c36ce8ac3efdb899fe479011af3b3da18bae561.tar.gz ruby-7c36ce8ac3efdb899fe479011af3b3da18bae561.tar.xz ruby-7c36ce8ac3efdb899fe479011af3b3da18bae561.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@6950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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; |
