hash.c, st.c: fix for ST_CHECK
* hash.c (foreach_safe_i, hash_foreach_iter): deal with error detected by ST_CHECK. * st.c (st_foreach_check): call with non-error argument in normal case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
af5e21292c
commit
b0af0592fd
@ -1,3 +1,10 @@
|
|||||||
|
Thu Nov 14 11:33:47 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* hash.c (foreach_safe_i, hash_foreach_iter): deal with error detected
|
||||||
|
by ST_CHECK.
|
||||||
|
|
||||||
|
* st.c (st_foreach_check): call with non-error argument in normal case.
|
||||||
|
|
||||||
Thu Nov 14 02:37:14 2013 Zachary Scott <e@zzak.io>
|
Thu Nov 14 02:37:14 2013 Zachary Scott <e@zzak.io>
|
||||||
|
|
||||||
* ext/thread/thread.c: [DOC] This patch accomplishes the following:
|
* ext/thread/thread.c: [DOC] This patch accomplishes the following:
|
||||||
|
7
hash.c
7
hash.c
@ -141,10 +141,12 @@ struct foreach_safe_arg {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
foreach_safe_i(st_data_t key, st_data_t value, struct foreach_safe_arg *arg)
|
foreach_safe_i(st_data_t key, st_data_t value, st_data_t args, int error)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
struct foreach_safe_arg *arg = (void *)args;
|
||||||
|
|
||||||
|
if (error) return ST_STOP;
|
||||||
status = (*arg->func)(key, value, arg->arg);
|
status = (*arg->func)(key, value, arg->arg);
|
||||||
if (status == ST_CONTINUE) {
|
if (status == ST_CONTINUE) {
|
||||||
return ST_CHECK;
|
return ST_CHECK;
|
||||||
@ -174,12 +176,13 @@ struct hash_foreach_arg {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
hash_foreach_iter(st_data_t key, st_data_t value, st_data_t argp)
|
hash_foreach_iter(st_data_t key, st_data_t value, st_data_t argp, int error)
|
||||||
{
|
{
|
||||||
struct hash_foreach_arg *arg = (struct hash_foreach_arg *)argp;
|
struct hash_foreach_arg *arg = (struct hash_foreach_arg *)argp;
|
||||||
int status;
|
int status;
|
||||||
st_table *tbl;
|
st_table *tbl;
|
||||||
|
|
||||||
|
if (error) return ST_STOP;
|
||||||
tbl = RHASH(arg->hash)->ntbl;
|
tbl = RHASH(arg->hash)->ntbl;
|
||||||
status = (*arg->func)((VALUE)key, (VALUE)value, arg->arg);
|
status = (*arg->func)((VALUE)key, (VALUE)value, arg->arg);
|
||||||
if (RHASH(arg->hash)->ntbl != tbl) {
|
if (RHASH(arg->hash)->ntbl != tbl) {
|
||||||
|
10
st.c
10
st.c
@ -948,7 +948,7 @@ st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t
|
|||||||
val = PVAL(table, i);
|
val = PVAL(table, i);
|
||||||
hash = PHASH(table, i);
|
hash = PHASH(table, i);
|
||||||
if (key == never) continue;
|
if (key == never) continue;
|
||||||
retval = (*func)(key, val, arg);
|
retval = (*func)(key, val, arg, 0);
|
||||||
if (!table->entries_packed) {
|
if (!table->entries_packed) {
|
||||||
FIND_ENTRY(table, ptr, hash, i);
|
FIND_ENTRY(table, ptr, hash, i);
|
||||||
if (retval == ST_CHECK) {
|
if (retval == ST_CHECK) {
|
||||||
@ -987,7 +987,7 @@ st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t
|
|||||||
if (ptr->key == never)
|
if (ptr->key == never)
|
||||||
goto unpacked_continue;
|
goto unpacked_continue;
|
||||||
i = ptr->hash % table->num_bins;
|
i = ptr->hash % table->num_bins;
|
||||||
retval = (*func)(ptr->key, ptr->record, arg);
|
retval = (*func)(ptr->key, ptr->record, arg, 0);
|
||||||
unpacked:
|
unpacked:
|
||||||
switch (retval) {
|
switch (retval) {
|
||||||
case ST_CHECK: /* check if hash is modified during iteration */
|
case ST_CHECK: /* check if hash is modified during iteration */
|
||||||
@ -1037,7 +1037,7 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
|
|||||||
key = PKEY(table, i);
|
key = PKEY(table, i);
|
||||||
val = PVAL(table, i);
|
val = PVAL(table, i);
|
||||||
hash = PHASH(table, i);
|
hash = PHASH(table, i);
|
||||||
retval = (*func)(key, val, arg);
|
retval = (*func)(key, val, arg, 0);
|
||||||
if (!table->entries_packed) {
|
if (!table->entries_packed) {
|
||||||
FIND_ENTRY(table, ptr, hash, i);
|
FIND_ENTRY(table, ptr, hash, i);
|
||||||
if (!ptr) return 0;
|
if (!ptr) return 0;
|
||||||
@ -1064,7 +1064,7 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
|
|||||||
if (ptr != 0) {
|
if (ptr != 0) {
|
||||||
do {
|
do {
|
||||||
i = ptr->hash % table->num_bins;
|
i = ptr->hash % table->num_bins;
|
||||||
retval = (*func)(ptr->key, ptr->record, arg);
|
retval = (*func)(ptr->key, ptr->record, arg, 0);
|
||||||
unpacked:
|
unpacked:
|
||||||
switch (retval) {
|
switch (retval) {
|
||||||
case ST_CONTINUE:
|
case ST_CONTINUE:
|
||||||
@ -1105,7 +1105,7 @@ st_reverse_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
|
|||||||
st_data_t key, val;
|
st_data_t key, val;
|
||||||
key = PKEY(table, i);
|
key = PKEY(table, i);
|
||||||
val = PVAL(table, i);
|
val = PVAL(table, i);
|
||||||
retval = (*func)(key, val, arg);
|
retval = (*func)(key, val, arg, 0);
|
||||||
switch (retval) {
|
switch (retval) {
|
||||||
case ST_CHECK: /* check if hash is modified during iteration */
|
case ST_CHECK: /* check if hash is modified during iteration */
|
||||||
for (j = 0; j < table->num_entries; j++) {
|
for (j = 0; j < table->num_entries; j++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user