ruby-changes:31900
From: nobu <ko1@a...>
Date: Tue, 3 Dec 2013 21:53:25 +0900 (JST)
Subject: [ruby-changes:31900] nobu:r43979 (trunk): vm_eval.c: rb_catch_protect
nobu 2013-12-03 21:53:18 +0900 (Tue, 03 Dec 2013) New Revision: 43979 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43979 Log: 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. Modified files: trunk/ChangeLog trunk/internal.h trunk/vm_eval.c Index: ChangeLog =================================================================== --- ChangeLog (revision 43978) +++ ChangeLog (revision 43979) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Dec 3 21:53:15 2013 Nobuyoshi Nakada <nobu@r...> + + * 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@g...> * object.c (rb_obj_clone): Protect FL_PROMOTED and FL_WB_PROTECTED Index: vm_eval.c =================================================================== --- vm_eval.c (revision 43978) +++ vm_eval.c (revision 43979) @@ -1834,6 +1834,16 @@ VALUE https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1834 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)(), V https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1855 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)(), V https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1864 state = 0; } TH_POP_TAG(); - if (state) - JUMP_TAG(state); + if (stateptr) + *stateptr = state; return val; } Index: internal.h =================================================================== --- internal.h (revision 43978) +++ internal.h (revision 43979) @@ -771,6 +771,7 @@ VALUE rb_check_block_call(VALUE, ID, int https://github.com/ruby/ruby/blob/trunk/internal.h#L771 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/