mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
st_foreach now free from ANYARGS
After5e86b005c0
, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from st_foreach. I strongly believe that this commit should have had come withb0af0592fd
, which added extra parameter to st_foreach callbacks.
This commit is contained in:
parent
e3fc30564e
commit
6dd60cf114
8 changed files with 34 additions and 20 deletions
|
@ -106,7 +106,7 @@ unp_fec(VALUE self, VALUE test)
|
|||
}
|
||||
|
||||
static int
|
||||
unp_fe_i(st_data_t key, st_data_t val, st_data_t args, int error)
|
||||
unp_fe_i(st_data_t key, st_data_t val, st_data_t args)
|
||||
{
|
||||
struct checker *c = (struct checker *)args;
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ numhash_aset(VALUE self, VALUE key, VALUE data)
|
|||
}
|
||||
|
||||
static int
|
||||
numhash_i(st_data_t key, st_data_t value, st_data_t arg)
|
||||
numhash_i(st_data_t key, st_data_t value, st_data_t arg, int _)
|
||||
{
|
||||
VALUE ret;
|
||||
ret = rb_yield_values(3, (VALUE)key, (VALUE)value, (VALUE)arg);
|
||||
|
@ -135,4 +135,3 @@ Init_numhash(void)
|
|||
rb_define_method(st, "size", numhash_size, 0);
|
||||
rb_define_method(st, "delete_safe", numhash_delete_safe, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -138,14 +138,14 @@ freeobj_i(VALUE tpval, void *data)
|
|||
}
|
||||
|
||||
static int
|
||||
free_keys_i(st_data_t key, st_data_t value, void *data)
|
||||
free_keys_i(st_data_t key, st_data_t value, st_data_t data)
|
||||
{
|
||||
ruby_xfree((void *)key);
|
||||
return ST_CONTINUE;
|
||||
}
|
||||
|
||||
static int
|
||||
free_values_i(st_data_t key, st_data_t value, void *data)
|
||||
free_values_i(st_data_t key, st_data_t value, st_data_t data)
|
||||
{
|
||||
ruby_xfree((void *)value);
|
||||
return ST_CONTINUE;
|
||||
|
|
2
gc.c
2
gc.c
|
@ -5620,7 +5620,7 @@ gc_check_after_marks_i(st_data_t k, st_data_t v, void *ptr)
|
|||
}
|
||||
|
||||
static void
|
||||
gc_marks_check(rb_objspace_t *objspace, int (*checker_func)(ANYARGS), const char *checker_name)
|
||||
gc_marks_check(rb_objspace_t *objspace, st_foreach_callback_func *checker_func, const char *checker_name)
|
||||
{
|
||||
size_t saved_malloc_increase = objspace->malloc_params.increase;
|
||||
#if RGENGC_ESTIMATE_OLDMALLOC
|
||||
|
|
|
@ -118,9 +118,11 @@ typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t
|
|||
* results of hash() are same and compare() returns 0, otherwise the
|
||||
* behavior is undefined */
|
||||
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg);
|
||||
int st_foreach_with_replace(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, 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);
|
||||
typedef int st_foreach_callback_func(st_data_t, st_data_t, st_data_t);
|
||||
typedef int st_foreach_check_callback_func(st_data_t, st_data_t, st_data_t, int);
|
||||
int st_foreach_with_replace(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg);
|
||||
int st_foreach(st_table *, st_foreach_callback_func *, st_data_t);
|
||||
int st_foreach_check(st_table *, st_foreach_check_callback_func *, st_data_t, st_data_t);
|
||||
st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size);
|
||||
st_index_t st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never);
|
||||
st_index_t st_values(st_table *table, st_data_t *values, st_index_t size);
|
||||
|
|
|
@ -112,7 +112,7 @@ static VALUE rb_marshal_dump_limited(VALUE obj, VALUE port, int limit);
|
|||
static VALUE rb_marshal_load_with_proc(VALUE port, VALUE proc);
|
||||
|
||||
static int
|
||||
mark_marshal_compat_i(st_data_t key, st_data_t value)
|
||||
mark_marshal_compat_i(st_data_t key, st_data_t value, st_data_t _)
|
||||
{
|
||||
marshal_compat_t *p = (marshal_compat_t *)value;
|
||||
rb_gc_mark(p->newclass);
|
||||
|
|
|
@ -493,7 +493,7 @@ onig_print_names(FILE* fp, regex_t* reg)
|
|||
|
||||
if (IS_NOT_NULL(t)) {
|
||||
fprintf(fp, "name table\n");
|
||||
onig_st_foreach(t, i_print_name_entry, (HashDataType )fp);
|
||||
onig_st_foreach(t, (st_foreach_callback_func *)i_print_name_entry, (HashDataType )fp);
|
||||
fputs("\n", fp);
|
||||
}
|
||||
return 0;
|
||||
|
@ -516,7 +516,7 @@ names_clear(regex_t* reg)
|
|||
NameTable* t = (NameTable* )reg->name_table;
|
||||
|
||||
if (IS_NOT_NULL(t)) {
|
||||
onig_st_foreach(t, i_free_name_entry, 0);
|
||||
onig_st_foreach(t, (st_foreach_callback_func *)i_free_name_entry, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -585,7 +585,7 @@ onig_foreach_name(regex_t* reg,
|
|||
narg.reg = reg;
|
||||
narg.arg = arg;
|
||||
narg.enc = reg->enc; /* should be pattern encoding. */
|
||||
onig_st_foreach(t, i_names, (HashDataType )&narg);
|
||||
onig_st_foreach(t, (st_foreach_callback_func *)i_names, (HashDataType )&narg);
|
||||
}
|
||||
return narg.ret;
|
||||
}
|
||||
|
@ -613,7 +613,7 @@ onig_renumber_name_table(regex_t* reg, GroupNumRemap* map)
|
|||
NameTable* t = (NameTable* )reg->name_table;
|
||||
|
||||
if (IS_NOT_NULL(t)) {
|
||||
onig_st_foreach(t, i_renumber_name, (HashDataType )map);
|
||||
onig_st_foreach(t, (st_foreach_callback_func *)i_renumber_name, (HashDataType )map);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
25
st.c
25
st.c
|
@ -1548,7 +1548,7 @@ st_update(st_table *tab, st_data_t key,
|
|||
different for ST_CHECK and when the current element is removed
|
||||
during traversing. */
|
||||
static inline int
|
||||
st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg,
|
||||
st_general_foreach(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg,
|
||||
int check_p)
|
||||
{
|
||||
st_index_t bin;
|
||||
|
@ -1659,20 +1659,33 @@ st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_update_callback_func
|
|||
}
|
||||
|
||||
int
|
||||
st_foreach_with_replace(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg)
|
||||
st_foreach_with_replace(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg)
|
||||
{
|
||||
return st_general_foreach(tab, func, replace, arg, TRUE);
|
||||
}
|
||||
|
||||
int
|
||||
st_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg)
|
||||
struct functor {
|
||||
st_foreach_callback_func *func;
|
||||
st_data_t arg;
|
||||
};
|
||||
|
||||
static int
|
||||
apply_functor(st_data_t k, st_data_t v, st_data_t d, int _)
|
||||
{
|
||||
return st_general_foreach(tab, func, NULL, arg, FALSE);
|
||||
const struct functor *f = (void *)d;
|
||||
return f->func(k, v, f->arg);
|
||||
}
|
||||
|
||||
int
|
||||
st_foreach(st_table *tab, st_foreach_callback_func *func, st_data_t arg)
|
||||
{
|
||||
const struct functor f = { func, arg };
|
||||
return st_general_foreach(tab, apply_functor, NULL, (st_data_t)&f, FALSE);
|
||||
}
|
||||
|
||||
/* See comments for function st_delete_safe. */
|
||||
int
|
||||
st_foreach_check(st_table *tab, int (*func)(ANYARGS), st_data_t arg,
|
||||
st_foreach_check(st_table *tab, st_foreach_check_callback_func *func, st_data_t arg,
|
||||
st_data_t never ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return st_general_foreach(tab, func, NULL, arg, TRUE);
|
||||
|
|
Loading…
Add table
Reference in a new issue