From c7159e81fc0d70b67358deaa39d21babbc3d89e7 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 3 Dec 2013 12:53:18 +0000 Subject: [PATCH] vm_eval.c: rb_catch_protect * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ internal.h | 1 + vm_eval.c | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ed558b7be..cc01861a29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Dec 3 21:53:15 2013 Nobuyoshi Nakada + + * 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 * 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); diff --git a/vm_eval.c b/vm_eval.c index e6122606ae..41a05634e4 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1832,6 +1832,16 @@ rb_catch(const char *tag, VALUE (*func)(), VALUE data) 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 */ @@ -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; }