Bug #1852 » hash_additional.diff
| include/ruby/ruby.h | ||
|---|---|---|
|
VALUE rb_ensure(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
|
||
|
VALUE rb_catch(const char*,VALUE(*)(ANYARGS),VALUE);
|
||
|
VALUE rb_catch_obj(VALUE,VALUE(*)(ANYARGS),VALUE);
|
||
|
VALUE rb_catch_func(VALUE,VALUE(*)(ANYARGS),VALUE);
|
||
|
NORETURN(void rb_throw(const char*,VALUE));
|
||
|
NORETURN(void rb_throw_obj(VALUE,VALUE));
|
||
| thread.c | ||
|---|---|---|
|
rb_hash_delete(list, obj);
|
||
|
}
|
||
|
struct exec_recursive_params {
|
||
|
VALUE (*func) (VALUE, VALUE, int);
|
||
|
VALUE list;
|
||
|
VALUE obj;
|
||
|
VALUE objid;
|
||
|
VALUE pairid;
|
||
|
VALUE arg;
|
||
|
};
|
||
|
static VALUE
|
||
|
exec_recursive_i(VALUE tag, struct exec_recursive_params *p)
|
||
|
{
|
||
|
VALUE result = Qundef;
|
||
|
int state;
|
||
|
recursive_push(p->list, p->objid, p->pairid);
|
||
|
PUSH_TAG();
|
||
|
if ((state = EXEC_TAG()) == 0) {
|
||
|
result = (*p->func) (p->obj, p->arg, Qfalse);
|
||
|
}
|
||
|
POP_TAG();
|
||
|
recursive_pop(p->list, p->objid, p->pairid);
|
||
|
if (state)
|
||
|
JUMP_TAG(state);
|
||
|
return result;
|
||
|
}
|
||
|
/*
|
||
|
* Calls func(obj, arg, recursive), where recursive is non-zero if the
|
||
|
* current method is called recursively on obj, or on the pair <obj, pairid>
|
||
| ... | ... | |
|
static VALUE
|
||
|
exec_recursive(VALUE (*func) (VALUE, VALUE, int), VALUE obj, VALUE pairid, VALUE arg, int outer)
|
||
|
{
|
||
|
VALUE list = recursive_list_access();
|
||
|
VALUE objid = rb_obj_id(obj);
|
||
|
int outermost = outer && !recursive_check(list, ID2SYM(recursive_key), 0);
|
||
|
struct exec_recursive_params p;
|
||
|
p.list = recursive_list_access();
|
||
|
p.objid = rb_obj_id(obj);
|
||
|
int outermost = outer && !recursive_check(p.list, ID2SYM(recursive_key), 0);
|
||
|
if (recursive_check(list, objid, pairid)) {
|
||
|
if (recursive_check(p.list, p.objid, pairid)) {
|
||
|
if (outer && !outermost) {
|
||
|
rb_throw_obj(list, 0);
|
||
|
rb_throw_obj(p.list, p.list);
|
||
|
}
|
||
|
return (*func) (obj, arg, Qtrue);
|
||
|
}
|
||
|
else {
|
||
|
VALUE result = Qundef;
|
||
|
int state;
|
||
|
rb_thread_t *th;
|
||
|
rb_control_frame_t *saved_cfp;
|
||
|
p.func = func;
|
||
|
p.obj = obj;
|
||
|
p.pairid = pairid;
|
||
|
p.arg = arg;
|
||
|
recursive_push(list, objid, pairid);
|
||
|
PUSH_TAG();
|
||
|
if (outermost) {
|
||
|
th = GET_THREAD();
|
||
|
saved_cfp = th->cfp;
|
||
|
th->tag->tag = list;
|
||
|
recursive_push(list, ID2SYM(recursive_key), 0);
|
||
|
}
|
||
|
if ((state = EXEC_TAG()) == 0) {
|
||
|
result = (*func) (obj, arg, Qfalse);
|
||
|
}
|
||
|
if (outermost) {
|
||
|
recursive_pop(list, ID2SYM(recursive_key), 0);
|
||
|
recursive_push(p.list, ID2SYM(recursive_key), 0);
|
||
|
result = rb_catch_func(p.list, exec_recursive_i, (VALUE)&p);
|
||
|
recursive_pop(p.list, ID2SYM(recursive_key), 0);
|
||
|
if (result == p.list) {
|
||
|
result = (*func) (obj, arg, Qtrue);
|
||
|
}
|
||
|
}
|
||
|
POP_TAG();
|
||
|
recursive_pop(list, objid, pairid);
|
||
|
if (state == TAG_THROW && outermost && RNODE(th->errinfo)->u1.value == list) {
|
||
|
th->cfp = saved_cfp;
|
||
|
th->errinfo = Qnil;
|
||
|
return (*func) (obj, arg, Qtrue);
|
||
|
else {
|
||
|
result = exec_recursive_i(0, &p);
|
||
|
}
|
||
|
if (state)
|
||
|
JUMP_TAG(state);
|
||
|
return result;
|
||
|
}
|
||
|
}
|
||
| vm_eval.c | ||
|---|---|---|
|
rb_throw_obj(ID2SYM(rb_intern(tag)), val);
|
||
|
}
|
||
|
VALUE
|
||
|
rb_catch_func(VALUE tag, VALUE (*func)(), VALUE data)
|
||
|
{
|
||
|
int state;
|
||
|
volatile VALUE val = Qnil; /* OK */
|
||
|
rb_thread_t *th = GET_THREAD();
|
||
|
rb_control_frame_t *saved_cfp = th->cfp;
|
||
|
PUSH_TAG();
|
||
|
th->tag->tag = tag;
|
||
|
if ((state = EXEC_TAG()) == 0) {
|
||
|
val = (*func)(tag, data);
|
||
|
}
|
||
|
else if (state == TAG_THROW && RNODE(th->errinfo)->u1.value == tag) {
|
||
|
th->cfp = saved_cfp;
|
||
|
val = th->tag->retval;
|
||
|
th->errinfo = Qnil;
|
||
|
state = 0;
|
||
|
}
|
||
|
POP_TAG();
|
||
|
if (state)
|
||
|
JUMP_TAG(state);
|
||
|
return val;
|
||
|
}
|
||
|
static VALUE
|
||
|
f_catch_i(VALUE tag, VALUE data) {
|
||
|
return rb_yield_0(1, &tag);
|
||
|
}
|
||
|
/*
|
||
|
* call-seq:
|
||
|
* catch([arg]) {|tag| block } => obj
|
||
| ... | ... | |
|
rb_f_catch(int argc, VALUE *argv)
|
||
|
{
|
||
|
VALUE tag;
|
||
|
int state;
|
||
|
volatile VALUE val = Qnil; /* OK */
|
||
|
rb_thread_t *th = GET_THREAD();
|
||
|
rb_control_frame_t *saved_cfp = th->cfp;
|
||
|
if (argc == 0) {
|
||
|
tag = rb_obj_alloc(rb_cObject);
|
||
| ... | ... | |
|
else {
|
||
|
rb_scan_args(argc, argv, "01", &tag);
|
||
|
}
|
||
|
PUSH_TAG();
|
||
|
th->tag->tag = tag;
|
||
|
if ((state = EXEC_TAG()) == 0) {
|
||
|
val = rb_yield_0(1, &tag);
|
||
|
}
|
||
|
else if (state == TAG_THROW && RNODE(th->errinfo)->u1.value == tag) {
|
||
|
th->cfp = saved_cfp;
|
||
|
val = th->tag->retval;
|
||
|
th->errinfo = Qnil;
|
||
|
state = 0;
|
||
|
}
|
||
|
POP_TAG();
|
||
|
if (state)
|
||
|
JUMP_TAG(state);
|
||
|
return val;
|
||
|
return rb_catch_func(tag, f_catch_i, 0);
|
||
|
}
|
||
|
static VALUE
|
||