Permalink
Browse files

st: more usage for st_foreach_nocheck

Use it in more places. Add checking for ST_STOP.

Conflicts:

	st.c
  • Loading branch information...
1 parent e08b702 commit 95d6ddcb2b91461646188cc90a43138d2a0ddabf @funny-falcon committed Feb 9, 2012
Showing with 38 additions and 35 deletions.
  1. +9 −9 class.c
  2. +1 −1 compile.c
  3. +3 −3 dln.c
  4. +1 −1 ext/syck/emitter.c
  5. +2 −2 ext/syck/rubyext.c
  6. +2 −2 ext/syck/syck.c
  7. +1 −1 load.c
  8. +1 −1 marshal.c
  9. +1 −1 parse.y
  10. +1 −1 process.c
  11. +5 −2 st.c
  12. +5 −5 thread.c
  13. +1 −1 transcode.c
  14. +5 −5 variable.c
View
@@ -184,14 +184,14 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
rb_free_const_table(RCLASS_CONST_TBL(clone));
}
RCLASS_CONST_TBL(clone) = st_init_numtable();
- st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)RCLASS_CONST_TBL(clone));
+ st_foreach_nocheck(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)RCLASS_CONST_TBL(clone));
}
if (RCLASS_M_TBL(orig)) {
if (RCLASS_M_TBL(clone)) {
rb_free_m_table(RCLASS_M_TBL(clone));
}
RCLASS_M_TBL(clone) = st_init_numtable();
- st_foreach(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)clone);
+ st_foreach_nocheck(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)clone);
}
return clone;
@@ -237,10 +237,10 @@ rb_singleton_class_clone(VALUE obj)
}
if (RCLASS_CONST_TBL(klass)) {
RCLASS_CONST_TBL(clone) = st_init_numtable();
- st_foreach(RCLASS_CONST_TBL(klass), clone_const_i, (st_data_t)RCLASS_CONST_TBL(clone));
+ st_foreach_nocheck(RCLASS_CONST_TBL(klass), clone_const_i, (st_data_t)RCLASS_CONST_TBL(clone));
}
RCLASS_M_TBL(clone) = st_init_numtable();
- st_foreach(RCLASS_M_TBL(klass), clone_method_i, (st_data_t)clone);
+ st_foreach_nocheck(RCLASS_M_TBL(klass), clone_method_i, (st_data_t)clone);
rb_singleton_class_attached(RBASIC(clone)->klass, clone);
FL_SET(clone, FL_SINGLETON);
return clone;
@@ -1011,13 +1011,13 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func
list = st_init_numtable();
for (; mod; mod = RCLASS_SUPER(mod)) {
- st_foreach(RCLASS_M_TBL(mod), method_entry_i, (st_data_t)list);
+ st_foreach_nocheck(RCLASS_M_TBL(mod), method_entry_i, (st_data_t)list);
if (BUILTIN_TYPE(mod) == T_ICLASS) continue;
if (obj && FL_TEST(mod, FL_SINGLETON)) continue;
if (!recur) break;
}
ary = rb_ary_new();
- st_foreach(list, func, ary);
+ st_foreach_nocheck(list, func, ary);
st_free_table(list);
return ary;
@@ -1242,17 +1242,17 @@ rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
klass = CLASS_OF(obj);
list = st_init_numtable();
if (klass && FL_TEST(klass, FL_SINGLETON)) {
- st_foreach(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
+ st_foreach_nocheck(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
klass = RCLASS_SUPER(klass);
}
if (RTEST(recur)) {
while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
- st_foreach(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
+ st_foreach_nocheck(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
klass = RCLASS_SUPER(klass);
}
}
ary = rb_ary_new();
- st_foreach(list, ins_methods_i, ary);
+ st_foreach_nocheck(list, ins_methods_i, ary);
st_free_table(list);
return ary;
View
@@ -435,7 +435,7 @@ validate_label(st_data_t name, st_data_t label, st_data_t arg)
static void
validate_labels(rb_iseq_t *iseq, st_table *labels_table)
{
- st_foreach(labels_table, validate_label, (st_data_t)iseq);
+ st_foreach_nocheck(labels_table, validate_label, (st_data_t)iseq);
if (!NIL_P(iseq->compile_data->err_info)) {
rb_exc_raise(iseq->compile_data->err_info);
}
View
@@ -466,7 +466,7 @@ static void
dln_print_undef(void)
{
fprintf(stderr, " Undefined symbols:\n");
- st_foreach(undef_tbl, undef_print, NULL);
+ st_foreach_nocheck(undef_tbl, undef_print, NULL);
}
static void
@@ -660,7 +660,7 @@ load_1(int fd, long disp, const char *need_init)
data.name0 = sym->n_un.n_name;
data.name1 = sym[1].n_un.n_name;
- st_foreach(reloc_tbl, reloc_repl, &data);
+ st_foreach_nocheck(reloc_tbl, reloc_repl, &data);
st_insert(undef_tbl, strdup(sym[1].n_un.n_name), NULL);
if (st_delete(undef_tbl, (st_data_t*)&key, NULL)) {
@@ -982,7 +982,7 @@ load_lib(const char *lib)
}
for (;;) {
target_offset = -1;
- st_foreach(undef_tbl, search_undef, lib_tbl);
+ st_foreach_nocheck(undef_tbl, search_undef, lib_tbl);
if (target_offset == -1) break;
if (load_1(fd, target_offset, 0) == -1) {
st_free_table(lib_tbl);
View
@@ -152,7 +152,7 @@ syck_emitter_st_free( SyckEmitter *e )
*/
if ( e->anchors != NULL )
{
- st_foreach( e->anchors, syck_st_free_anchors, 0 );
+ st_foreach_nocheck( e->anchors, syck_st_free_anchors, 0 );
st_free_table( e->anchors );
e->anchors = NULL;
}
View
@@ -754,11 +754,11 @@ syck_mark_parser(SyckParser *parser)
if ( parser->anchors != NULL )
{
- st_foreach( parser->anchors, syck_st_mark_nodes, 0 );
+ st_foreach_nocheck( parser->anchors, syck_st_mark_nodes, 0 );
}
if ( parser->bad_anchors != NULL )
{
- st_foreach( parser->bad_anchors, syck_st_mark_nodes, 0 );
+ st_foreach_nocheck( parser->bad_anchors, syck_st_mark_nodes, 0 );
}
}
View
@@ -223,7 +223,7 @@ syck_st_free( SyckParser *p )
if ( p->bad_anchors != NULL )
{
- st_foreach( p->bad_anchors, syck_st_free_nodes, 0 );
+ st_foreach_nocheck( p->bad_anchors, syck_st_free_nodes, 0 );
st_free_table( p->bad_anchors );
p->bad_anchors = NULL;
}
@@ -253,7 +253,7 @@ syck_free_parser( SyckParser *p )
*/
if ( p->syms != NULL )
{
- st_foreach( p->syms, syck_st_free_syms, 0 );
+ st_foreach_nocheck( p->syms, syck_st_free_syms, 0 );
st_free_table( p->syms );
p->syms = NULL;
}
View
@@ -185,7 +185,7 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c
fs.type = type;
fs.load_path = load_path ? load_path : rb_get_expanded_load_path();
fs.result = 0;
- st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
+ st_foreach_nocheck(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
if ((f = fs.result) != 0) {
if (fn) *fn = f;
goto loading;
View
@@ -106,7 +106,7 @@ static void
mark_marshal_compat_t(void *tbl)
{
if (!tbl) return;
- st_foreach(tbl, mark_marshal_compat_i, 0);
+ st_foreach_nocheck(tbl, mark_marshal_compat_i, 0);
}
void
View
@@ -10674,7 +10674,7 @@ rb_sym_all_symbols(void)
{
VALUE ary = rb_ary_new2(global_symbols.sym_id->num_entries);
- st_foreach(global_symbols.sym_id, symbols_i, ary);
+ st_foreach_nocheck(global_symbols.sym_id, symbols_i, ary);
return ary;
}
View
@@ -666,7 +666,7 @@ rb_waitpid(rb_pid_t pid, int *st, int flags)
struct wait_data data;
data.pid = (rb_pid_t)-1;
data.status = -1;
- st_foreach(pid_tbl, wait_each, (st_data_t)&data);
+ st_foreach_nocheck(pid_tbl, wait_each, (st_data_t)&data);
if (data.status != -1) {
rb_last_status_set(data.status, data.pid);
return data.pid;
View
@@ -995,20 +995,23 @@ st_update(st_table *table, st_data_t key, int (*func)(st_data_t key, st_data_t *
int
st_foreach_nocheck(st_table *table, int (*func)(ANYARGS), st_data_t arg)
{
+ enum st_retval retval;
if (table->num_entries == 0) return 0;
if (ULTRA_PACKED(table)) {
(*func)(UPKEY(table), UPVAL(table), arg);
}
else if (table->entries_packed) {
register st_index_t i;
for(i = 0; i < table->num_entries; i++) {
- (*func)(PKEY(table, i), PVAL(table, i), arg);
+ retval = (*func)(PKEY(table, i), PVAL(table, i), arg);
+ if (retval == ST_STOP) break;
}
}
else {
st_table_entry *ptr;
for(ptr = table->head; ptr; ptr = ptr->fore) {
- (*func)(ptr->key, ptr->record, arg);
+ retval = (*func)(ptr->key, ptr->record, arg);
+ if (retval == ST_STOP) break;
}
}
return 0;
View
@@ -2197,7 +2197,7 @@ rb_thread_keys(VALUE self)
GetThreadPtr(self, th);
if (th->local_storage) {
- st_foreach(th->local_storage, thread_keys_i, ary);
+ st_foreach_nocheck(th->local_storage, thread_keys_i, ary);
}
return ary;
}
@@ -2990,7 +2990,7 @@ clear_coverage(void)
{
VALUE coverages = rb_get_coverages();
if (RTEST(coverages)) {
- st_foreach(RHASH_TBL(coverages), clear_coverage_i, 0);
+ st_foreach_nocheck(RHASH_TBL(coverages), clear_coverage_i, 0);
}
}
@@ -3135,7 +3135,7 @@ thgroup_list(VALUE group)
param.ary = ary;
param.group = group;
- st_foreach(GET_THREAD()->vm->living_threads, thgroup_list_i, (st_data_t) & param);
+ st_foreach_nocheck(GET_THREAD()->vm->living_threads, thgroup_list_i, (st_data_t) & param);
return ary;
}
@@ -4064,7 +4064,7 @@ set_threads_event_flags_i(st_data_t key, st_data_t val, st_data_t flag)
static void
set_threads_event_flags(int flag)
{
- st_foreach(GET_VM()->living_threads, set_threads_event_flags_i, (st_data_t) flag);
+ st_foreach_nocheck(GET_VM()->living_threads, set_threads_event_flags_i, (st_data_t) flag);
}
static inline int
@@ -4244,7 +4244,7 @@ static rb_thread_t *
vm_event_hooks_running_thread(rb_vm_t *vm)
{
rb_thread_t *found = NULL;
- st_foreach(vm->living_threads, running_vm_event_hooks, (st_data_t)&found);
+ st_foreach_nocheck(vm->living_threads, running_vm_event_hooks, (st_data_t)&found);
return found;
}
View
@@ -317,7 +317,7 @@ transcode_search_path(const char *sname, const char *dname,
}
bfs.base_enc = q->enc;
- st_foreach(table2, transcode_search_path_i, (st_data_t)&bfs);
+ st_foreach_nocheck(table2, transcode_search_path_i, (st_data_t)&bfs);
bfs.base_enc = NULL;
xfree(q);
View
@@ -98,7 +98,7 @@ fc_i(ID key, rb_const_entry_t *ce, struct fc_result *res)
arg.klass = res->klass;
arg.track = value;
arg.prev = res;
- st_foreach(RCLASS_CONST_TBL(value), fc_i, (st_data_t)&arg);
+ st_foreach_nocheck(RCLASS_CONST_TBL(value), fc_i, (st_data_t)&arg);
if (arg.path) {
res->path = arg.path;
return ST_STOP;
@@ -123,10 +123,10 @@ find_class_path(VALUE klass)
arg.track = rb_cObject;
arg.prev = 0;
if (RCLASS_CONST_TBL(rb_cObject)) {
- st_foreach_safe(RCLASS_CONST_TBL(rb_cObject), fc_i, (st_data_t)&arg);
+ st_foreach_nocheck(RCLASS_CONST_TBL(rb_cObject), fc_i, (st_data_t)&arg);
}
if (arg.path == 0) {
- st_foreach_safe(rb_class_tbl, fc_i, (st_data_t)&arg);
+ st_foreach_nocheck(rb_class_tbl, fc_i, (st_data_t)&arg);
}
if (arg.path) {
st_data_t tmp = tmp_classpath;
@@ -1871,7 +1871,7 @@ rb_mod_const_at(VALUE mod, void *data)
tbl = st_init_numtable();
}
if (RCLASS_CONST_TBL(mod)) {
- st_foreach_safe(RCLASS_CONST_TBL(mod), sv_i, (st_data_t)tbl);
+ st_foreach_nocheck(RCLASS_CONST_TBL(mod), sv_i, (st_data_t)tbl);
}
return tbl;
}
@@ -1906,7 +1906,7 @@ rb_const_list(void *data)
if (!tbl) return rb_ary_new2(0);
ary = rb_ary_new2(tbl->num_entries);
- st_foreach_safe(tbl, list_i, ary);
+ st_foreach_nocheck(tbl, list_i, ary);
st_free_table(tbl);
return ary;

0 comments on commit 95d6ddc

Please sign in to comment.