ruby-changes:13186
From: marcandre <ko1@a...>
Date: Wed, 16 Sep 2009 06:18:25 +0900 (JST)
Subject: [ruby-changes:13186] Ruby:r24942 (trunk): * vm_eval.c (rb_catch_obj, rb_catch, rb_f_catch): No longer use the obsolete function rb_iterate.
marcandre 2009-09-16 06:18:04 +0900 (Wed, 16 Sep 2009) New Revision: 24942 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24942 Log: * vm_eval.c (rb_catch_obj, rb_catch, rb_f_catch): No longer use the obsolete function rb_iterate. Modified files: trunk/ChangeLog trunk/vm_eval.c Index: ChangeLog =================================================================== --- ChangeLog (revision 24941) +++ ChangeLog (revision 24942) @@ -1,3 +1,8 @@ +Wed Sep 16 06:17:33 2009 Marc-Andre Lafortune <ruby-core@m...> + + * vm_eval.c (rb_catch_obj, rb_catch, rb_f_catch): No longer use the + obsolete function rb_iterate. + Tue Sep 15 21:48:12 2009 Tanaka Akira <akr@f...> * configure.in (--enable-frame-address): removed. Index: vm_eval.c =================================================================== --- vm_eval.c (revision 24941) +++ vm_eval.c (revision 24942) @@ -1264,6 +1264,10 @@ rb_throw_obj(ID2SYM(rb_intern(tag)), val); } +static VALUE +catch_i(VALUE tag, VALUE data) { + return rb_yield_0(1, &tag); +} /* * call-seq: * catch([arg]) {|tag| block } => obj @@ -1305,10 +1309,6 @@ 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); @@ -1316,12 +1316,31 @@ else { rb_scan_args(argc, argv, "01", &tag); } + return rb_catch_obj(tag, catch_i, 0); +} + +VALUE +rb_catch(const char *tag, VALUE (*func)(), VALUE data) +{ + VALUE vtag = tag ? ID2SYM(rb_intern(tag)) : rb_obj_alloc(rb_cObject); + return rb_catch_obj(vtag, func, data); +} + +VALUE +rb_catch_obj(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 = rb_yield_0(1, &tag); + /* call with argc=1, argv = [tag], block = Qnil to insure compatibility */ + val = (*func)(tag, data, 1, &tag, Qnil); } else if (state == TAG_THROW && RNODE(th->errinfo)->u1.value == tag) { th->cfp = saved_cfp; @@ -1336,33 +1355,6 @@ return val; } -static VALUE -catch_null_i(VALUE dmy) -{ - return rb_funcall(Qnil, rb_intern("catch"), 0, 0); -} - -static VALUE -catch_i(VALUE tag) -{ - return rb_funcall(Qnil, rb_intern("catch"), 1, tag); -} - -VALUE -rb_catch(const char *tag, VALUE (*func)(), VALUE data) -{ - if (!tag) { - return rb_iterate(catch_null_i, 0, func, data); - } - return rb_iterate(catch_i, ID2SYM(rb_intern(tag)), func, data); -} - -VALUE -rb_catch_obj(VALUE tag, VALUE (*func)(), VALUE data) -{ - return rb_iterate((VALUE (*)_((VALUE)))catch_i, tag, func, data); -} - /* * call-seq: * caller(start=1) => array -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/