diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-29 14:50:20 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-29 14:50:20 +0000 |
commit | 28cc4f75437eec9e76f52723f042445332fd86f5 (patch) | |
tree | 2eb33997a9469dcf62a1ccd03f16777f8f22660e | |
parent | 6da92c3e89697e1263248ab56e2ad33381429d6c (diff) |
* st.c (st_update): pass pointer to key to the callback function.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | ext/-test-/st/numhash/numhash.c | 4 | ||||
-rw-r--r-- | ext/-test-/st/update/update.c | 4 | ||||
-rw-r--r-- | gc.c | 5 | ||||
-rw-r--r-- | include/ruby/st.h | 2 | ||||
-rw-r--r-- | load.c | 4 | ||||
-rw-r--r-- | st.c | 4 |
7 files changed, 16 insertions, 11 deletions
@@ -1,3 +1,7 @@ +Thu Mar 29 23:50:15 2012 Nobuyoshi Nakada <[email protected]> + + * st.c (st_update): pass pointer to key to the callback function. + Thu Mar 29 16:36:10 2012 Nobuyoshi Nakada <[email protected]> * st.c (st_update): add existing parameter to the callback function. diff --git a/ext/-test-/st/numhash/numhash.c b/ext/-test-/st/numhash/numhash.c index 599678dde1..c746ac5495 100644 --- a/ext/-test-/st/numhash/numhash.c +++ b/ext/-test-/st/numhash/numhash.c @@ -60,9 +60,9 @@ numhash_each(VALUE self) } static int -update_func(st_data_t key, st_data_t *value, st_data_t arg) +update_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing) { - VALUE ret = rb_yield_values(2, (VALUE)key, (VALUE)*value); + VALUE ret = rb_yield_values(existing ? 2 : 1, (VALUE)*key, (VALUE)*value); switch (ret) { case Qfalse: return ST_STOP; diff --git a/ext/-test-/st/update/update.c b/ext/-test-/st/update/update.c index 0c82a7a091..979ad3e334 100644 --- a/ext/-test-/st/update/update.c +++ b/ext/-test-/st/update/update.c @@ -2,9 +2,9 @@ #include <ruby/st.h> static int -update_func(st_data_t key, st_data_t *value, st_data_t arg, int existing) +update_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing) { - VALUE ret = rb_yield_values(existing ? 2 : 1, (VALUE)key, (VALUE)*value); + VALUE ret = rb_yield_values(existing ? 2 : 1, (VALUE)*key, (VALUE)*value); switch (ret) { case Qfalse: return ST_STOP; @@ -3672,10 +3672,11 @@ wmap_allocate(VALUE klass) } static int -wmap_final_func(st_data_t key, st_data_t *value, st_data_t arg, int existing) +wmap_final_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing) { - VALUE obj = (VALUE)key, ary = (VALUE)*value; + VALUE obj, ary; if (!existing) return ST_STOP; + obj = (VALUE)*key, ary = (VALUE)*value; rb_ary_delete(ary, obj); if (!RARRAY_LEN(ary)) return ST_DELETE; return ST_CONTINUE; diff --git a/include/ruby/st.h b/include/ruby/st.h index c461de968c..c2294a92c1 100644 --- a/include/ruby/st.h +++ b/include/ruby/st.h @@ -121,7 +121,7 @@ int st_insert(st_table *, st_data_t, st_data_t); int st_insert2(st_table *, st_data_t, st_data_t, st_data_t (*)(st_data_t)); int st_lookup(st_table *, st_data_t, st_data_t *); int st_get_key(st_table *, st_data_t, st_data_t *); -typedef int st_update_callback_func(st_data_t key, st_data_t *value, st_data_t arg, int existing); +typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing); int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg); int st_foreach(st_table *, int (*)(ANYARGS), st_data_t); int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t); @@ -417,7 +417,7 @@ load_lock(const char *ftptr) } static int -release_barrier(st_data_t key, st_data_t *value, st_data_t done, int existing) +release_barrier(st_data_t *key, st_data_t *value, st_data_t done, int existing) { VALUE barrier = (VALUE)*value; if (!existing) return ST_STOP; @@ -425,7 +425,7 @@ release_barrier(st_data_t key, st_data_t *value, st_data_t done, int existing) /* still in-use */ return ST_CONTINUE; } - xfree((char *)key); + xfree((char *)*key); return ST_DELETE; } @@ -841,7 +841,7 @@ st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data existing = 1; } { - retval = (*func)(key, &value, arg, existing); + retval = (*func)(&key, &value, arg, existing); if (!table->entries_packed) { FIND_ENTRY(table, ptr, hash_val, bin_pos); goto unpacked; @@ -869,7 +869,7 @@ st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data existing = 1; } { - retval = (*func)(ptr->key, &value, arg, existing); + retval = (*func)(&key, &value, arg, existing); unpacked: switch (retval) { case ST_CONTINUE: |