Skip to content

Commit

Permalink
* hash.c, marshal.c, object.c, variable.c: fix callback argument types
Browse files Browse the repository at this point in the history
  of iterators.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Mar 30, 2012
1 parent db5ede2 commit 4b3a1f7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Sat Mar 31 07:40:51 2012 Nobuyoshi Nakada <[email protected]>

* hash.c, marshal.c, object.c, variable.c: fix callback argument types
of iterators.

Thu Mar 29 23:50:15 2012 Nobuyoshi Nakada <[email protected]>

* st.c (st_update): pass pointer to key to the callback function.
Expand Down
5 changes: 3 additions & 2 deletions hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ hash_foreach_ensure(VALUE hash)
}

static VALUE
hash_foreach_call(struct hash_foreach_arg *arg)
hash_foreach_call(VALUE arg)
{
if (st_foreach_check(RHASH(arg->hash)->ntbl, hash_foreach_iter, (st_data_t)arg, Qundef)) {
VALUE hash = ((struct hash_foreach_arg *)arg)->hash;
if (st_foreach_check(RHASH(hash)->ntbl, hash_foreach_iter, (st_data_t)arg, (st_data_t)Qundef)) {
rb_raise(rb_eRuntimeError, "hash modified during iteration");
}
return Qnil;
Expand Down
6 changes: 5 additions & 1 deletion marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,12 @@ w_uclass(VALUE obj, VALUE super, struct dump_arg *arg)
}

static int
w_obj_each(ID id, VALUE value, struct dump_call_arg *arg)
w_obj_each(st_data_t key, st_data_t val, st_data_t a)
{
ID id = (ID)key;
VALUE value = (VALUE)val;
struct dump_call_arg *arg = (struct dump_call_arg *)a;

if (id == rb_id_encoding()) return ST_CONTINUE;
if (id == rb_intern("E")) return ST_CONTINUE;
w_symbol(id, arg->arg);
Expand Down
5 changes: 4 additions & 1 deletion object.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,11 @@ rb_inspect(VALUE obj)
}

static int
inspect_i(ID id, VALUE value, VALUE str)
inspect_i(st_data_t k, st_data_t v, st_data_t a)
{
ID id = (ID)k;
VALUE value = (VALUE)v;
VALUE str = (VALUE)a;
VALUE str2;
const char *ivname;

Expand Down
38 changes: 29 additions & 9 deletions variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ fc_path(struct fc_result *fc, ID name)
}

static int
fc_i(ID key, rb_const_entry_t *ce, struct fc_result *res)
fc_i(st_data_t k, st_data_t v, st_data_t a)
{
ID key = (ID)k;
rb_const_entry_t *ce = (rb_const_entry_t *)v;
struct fc_result *res = (struct fc_result *)a;
VALUE value = ce->value;
if (!rb_is_const_id(key)) return ST_CONTINUE;

Expand Down Expand Up @@ -455,8 +458,10 @@ readonly_setter(VALUE val, ID id, void *data, struct global_variable *gvar)
}

static int
mark_global_entry(ID key, struct global_entry *entry)
mark_global_entry(st_data_t k, st_data_t v, st_data_t a)
{
ID key = (ID)key;
struct global_entry *entry = (struct global_entry *)v;
struct trace_var *trace;
struct global_variable *var = entry->var;

Expand Down Expand Up @@ -746,8 +751,10 @@ rb_gvar_defined(struct global_entry *entry)
}

static int
gvar_i(ID key, struct global_entry *entry, VALUE ary)
gvar_i(st_data_t k, st_data_t v, st_data_t a)
{
ID key = (ID)k;
VALUE ary = (VALUE)a;
rb_ary_push(ary, ID2SYM(key));
return ST_CONTINUE;
}
Expand Down Expand Up @@ -916,15 +923,18 @@ rb_mark_generic_ivar(VALUE obj)
}

static int
givar_mark_i(ID key, VALUE value)
givar_mark_i(st_data_t k, st_data_t v, st_data_t a)
{
VALUE value = (VALUE)v;
rb_gc_mark(value);
return ST_CONTINUE;
}

static int
givar_i(VALUE obj, st_table *tbl)
givar_i(st_data_t k, st_data_t v, st_data_t a)
{
VALUE obj = (VALUE)k;
st_table *tbl = (st_table *)v;
if (rb_special_const_p(obj)) {
st_foreach_safe(tbl, givar_mark_i, 0);
}
Expand Down Expand Up @@ -1241,8 +1251,11 @@ rb_ivar_count(VALUE obj)
}

static int
ivar_i(ID key, VALUE val, VALUE ary)
ivar_i(st_data_t k, st_data_t v, st_data_t a)
{
ID key = (ID)k;
VALUE ary = (VALUE)a;

if (rb_is_instance_id(key)) {
rb_ary_push(ary, ID2SYM(key));
}
Expand Down Expand Up @@ -1855,8 +1868,12 @@ rb_const_remove(VALUE mod, ID id)
}

static int
sv_i(ID key, rb_const_entry_t *ce, st_table *tbl)
sv_i(st_data_t k, st_data_t v, st_data_t a)
{
ID key = (ID)k;
rb_const_entry_t *ce = (rb_const_entry_t *)v;
st_table *tbl = (st_table *)a;

if (rb_is_const_id(key)) {
if (!st_lookup(tbl, (st_data_t)key, 0)) {
st_insert(tbl, (st_data_t)key, (st_data_t)ce);
Expand Down Expand Up @@ -2301,8 +2318,11 @@ rb_define_class_variable(VALUE klass, const char *name, VALUE val)
}

static int
cv_i(ID key, VALUE value, VALUE ary)
cv_i(st_data_t k, st_data_t v, st_data_t a)
{
ID key = (ID)k;
VALUE ary = (VALUE)a;

if (rb_is_class_id(key)) {
VALUE kval = ID2SYM(key);
if (!rb_ary_includes(ary, kval)) {
Expand Down Expand Up @@ -2334,7 +2354,7 @@ rb_mod_class_variables(VALUE obj)
VALUE ary = rb_ary_new();

if (RCLASS_IV_TBL(obj)) {
st_foreach_safe(RCLASS_IV_TBL(obj), cv_i, ary);
st_foreach_safe(RCLASS_IV_TBL(obj), cv_i, (st_data_t)ary);
}
return ary;
}
Expand Down

0 comments on commit 4b3a1f7

Please sign in to comment.