1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2013-12-03 12:53:18 +00:00
parent 1083b375ec
commit c7159e81fc
3 changed files with 20 additions and 3 deletions

View file

@ -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

View file

@ -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);

View file

@ -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;
}