ruby-changes:22320
From: nobu <ko1@a...>
Date: Tue, 24 Jan 2012 14:21:45 +0900 (JST)
Subject: [ruby-changes:22320] nobu:r34369 (trunk): * vm.c (rb_iter_break_value): new function to break a block with
nobu 2012-01-24 14:20:48 +0900 (Tue, 24 Jan 2012) New Revision: 34369 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34369 Log: * vm.c (rb_iter_break_value): new function to break a block with the value. [ruby-dev:45132] [Feature #5895] Added directories: trunk/ext/-test-/iter/ trunk/test/-ext-/iter/ Added files: trunk/ext/-test-/iter/break.c trunk/ext/-test-/iter/extconf.rb trunk/test/-ext-/iter/test_iter_break.rb Modified files: trunk/ChangeLog trunk/include/ruby/ruby.h trunk/vm.c trunk/vm_eval.c Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 34368) +++ include/ruby/ruby.h (revision 34369) @@ -1185,6 +1185,7 @@ NORETURN(void rb_sys_fail(const char*)); NORETURN(void rb_mod_sys_fail(VALUE, const char*)); NORETURN(void rb_iter_break(void)); +NORETURN(void rb_iter_break_value(VALUE)); NORETURN(void rb_exit(int)); NORETURN(void rb_notimplement(void)); VALUE rb_syserr_new(int, const char *); Index: ChangeLog =================================================================== --- ChangeLog (revision 34368) +++ ChangeLog (revision 34369) @@ -1,3 +1,8 @@ +Tue Jan 24 14:20:42 2012 Nobuyoshi Nakada <nobu@r...> + + * vm.c (rb_iter_break_value): new function to break a block with + the value. [ruby-dev:45132] [Feature #5895] + Tue Jan 24 12:58:41 2012 Yukihiro Matsumoto <matz@r...> * object.c (rb_Hash): add Kernel#Hash conversion method like Index: vm_eval.c =================================================================== --- vm_eval.c (revision 34368) +++ vm_eval.c (revision 34369) @@ -906,6 +906,7 @@ state = 0; th->state = 0; th->errinfo = Qnil; + retval = GET_THROWOBJ_VAL(err); /* check skipped frame */ while (th->cfp != cfp) { Index: ext/-test-/iter/break.c =================================================================== --- ext/-test-/iter/break.c (revision 0) +++ ext/-test-/iter/break.c (revision 34369) @@ -0,0 +1,15 @@ +#include <ruby.h> + +static VALUE +iter_break_value(VALUE self, VALUE val) +{ + rb_iter_break_value(val); + return self; /* not reached */ +} + +void +Init_break(void) +{ + VALUE breakable = rb_define_module_under(rb_define_module("Bug"), "Breakable"); + rb_define_module_function(breakable, "iter_break", iter_break_value, 1); +} Property changes on: ext/-test-/iter/break.c ___________________________________________________________________ Added: svn:eol-style + LF Index: ext/-test-/iter/extconf.rb =================================================================== --- ext/-test-/iter/extconf.rb (revision 0) +++ ext/-test-/iter/extconf.rb (revision 34369) @@ -0,0 +1 @@ +create_makefile("-test-/iter/break") Property changes on: ext/-test-/iter/extconf.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: vm.c =================================================================== --- vm.c (revision 34368) +++ vm.c (revision 34369) @@ -987,25 +987,31 @@ JUMP_TAG(state); } -NORETURN(static void vm_iter_break(rb_thread_t *th)); +NORETURN(static void vm_iter_break(rb_thread_t *th, VALUE val)); static void -vm_iter_break(rb_thread_t *th) +vm_iter_break(rb_thread_t *th, VALUE val) { rb_control_frame_t *cfp = th->cfp; VALUE *dfp = GC_GUARDED_PTR_REF(*cfp->dfp); th->state = TAG_BREAK; - th->errinfo = (VALUE)NEW_THROW_OBJECT(Qnil, (VALUE)dfp, TAG_BREAK); + th->errinfo = (VALUE)NEW_THROW_OBJECT(val, (VALUE)dfp, TAG_BREAK); TH_JUMP_TAG(th, TAG_BREAK); } void rb_iter_break(void) { - vm_iter_break(GET_THREAD()); + vm_iter_break(GET_THREAD(), Qnil); } +void +rb_iter_break_value(VALUE val) +{ + vm_iter_break(GET_THREAD(), val); +} + /* optimization: redefine management */ static st_table *vm_opt_method_table = 0; @@ -1352,6 +1358,7 @@ #endif } th->errinfo = Qnil; + th->state = 0; goto vm_loop_start; } } Index: test/-ext-/iter/test_iter_break.rb =================================================================== --- test/-ext-/iter/test_iter_break.rb (revision 0) +++ test/-ext-/iter/test_iter_break.rb (revision 34369) @@ -0,0 +1,9 @@ +require 'test/unit' +require '-test-/iter/break' + +class TestIterBreak < Test::Unit::TestCase + def test_iter_break + feature5895 = '[ruby-dev:45132]' + assert_equal(42, 1.times{Bug::Breakable.iter_break(42)}, feature5895) + end +end Property changes on: test/-ext-/iter/test_iter_break.rb ___________________________________________________________________ Added: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/