1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2012-03-29 14:50:20 +00:00
parent 6da92c3e89
commit 28cc4f7543
7 changed files with 16 additions and 11 deletions

View file

@ -1,3 +1,7 @@
Thu Mar 29 23:50:15 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* st.c (st_update): pass pointer to key to the callback function.
Thu Mar 29 16:36:10 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* st.c (st_update): add existing parameter to the callback function.

View file

@ -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;

View file

@ -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;

5
gc.c
View file

@ -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;

View file

@ -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);

4
load.c
View file

@ -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;
}

4
st.c
View file

@ -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: