diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | vm_eval.c | 16 |
3 files changed, 20 insertions, 3 deletions
@@ -1,3 +1,9 @@ +Tue Dec 3 21:53:15 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * vm_eval.c (rb_catch_protect): new function similar to + rb_catch_obj(), but protect from all global jumps like as + rb_load_protect(), rb_protect(), etc. + Tue Dec 3 20:18:46 2013 Narihiro Nakamura <authornari@gmail.com> * object.c (rb_obj_clone): Protect FL_PROMOTED and FL_WB_PROTECTED diff --git a/internal.h b/internal.h index f1c9e94041..810159d313 100644 --- a/internal.h +++ b/internal.h @@ -771,6 +771,7 @@ VALUE rb_check_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, V typedef void rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE); VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv, rb_check_funcall_hook *hook, VALUE arg); +VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, int *stateptr); /* vm_insnhelper.c */ VALUE rb_equal_opt(VALUE obj1, VALUE obj2); @@ -1834,6 +1834,16 @@ VALUE rb_catch_obj(VALUE t, VALUE (*func)(), VALUE data) { int state; + VALUE val = rb_catch_protect(t, func, data, &state); + if (state) + JUMP_TAG(state); + return val; +} + +VALUE +rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, int *stateptr) +{ + int state; volatile VALUE val = Qnil; /* OK */ rb_thread_t *th = GET_THREAD(); rb_control_frame_t *saved_cfp = th->cfp; @@ -1845,7 +1855,7 @@ rb_catch_obj(VALUE t, VALUE (*func)(), VALUE data) if ((state = TH_EXEC_TAG()) == 0) { /* call with argc=1, argv = [tag], block = Qnil to insure compatibility */ - val = (*func)(tag, data, 1, &tag, Qnil); + val = (*func)(tag, data, 1, (const VALUE *)&tag, Qnil); } else if (state == TAG_THROW && RNODE(th->errinfo)->u1.value == tag) { th->cfp = saved_cfp; @@ -1854,8 +1864,8 @@ rb_catch_obj(VALUE t, VALUE (*func)(), VALUE data) state = 0; } TH_POP_TAG(); - if (state) - JUMP_TAG(state); + if (stateptr) + *stateptr = state; return val; } |