Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commit c29ca8ea702eab870c29438e64e9594146924e2f
- Author: Akinori MUSHA <knu@idaemons.org>
- Date: Tue Sep 1 14:48:33 2015 +0900
- * vm_eval.c (rb_f_loop): Kernel#loop returns the "result" value
- when StopIteration is raised.
- diff --git a/ChangeLog b/ChangeLog
- index 77779a5..8017d09 100644
- --- a/ChangeLog
- +++ b/ChangeLog
- @@ -1,3 +1,8 @@
- +Tue Sep 1 14:49:27 2015 Akinori MUSHA <knu@iDaemons.org>
- +
- + * vm_eval.c (rb_f_loop): Kernel#loop returns the "result" value
- + when StopIteration is raised.
- +
- Mon Aug 31 17:04:45 2015 Koichi Sasada <ko1@atdot.net>
- * class.c (move_refined_method): should insert a write barrier
- diff --git a/NEWS b/NEWS
- index 1803ed9..4ce0d65 100644
- --- a/NEWS
- +++ b/NEWS
- @@ -44,6 +44,10 @@ with all sufficient information, see the ChangeLog file.
- this parameter is bitwise-ORed to oflags generated by normal mode argument.
- [Feature #11253]
- +* Kernel
- +
- + * Kernel#loop returns the "result" value when StopIteration is raised.
- +
- * Module
- * Module#deprecate_constant [Feature #11398]
- diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
- index b5ced3b..85e8c48 100644
- --- a/test/ruby/test_enumerator.rb
- +++ b/test/ruby/test_enumerator.rb
- @@ -46,6 +46,14 @@ class TestEnumerator < Test::Unit::TestCase
- }
- end
- + def test_loop_return_value
- + assert_equal nil, loop { break }
- + assert_equal 42, loop { break 42 }
- +
- + e = Enumerator.new { |y| y << 1; y << 2; :stopped }
- + assert_equal :stopped, loop { e.next while true }
- + end
- +
- def test_nested_iteration
- def (o = Object.new).each
- yield :ok1
- diff --git a/vm_eval.c b/vm_eval.c
- index 00b47e5..a08e211 100644
- --- a/vm_eval.c
- +++ b/vm_eval.c
- @@ -24,7 +24,7 @@ static void vm_set_eval_stack(rb_thread_t * th, const rb_iseq_t *iseq, const rb_
- static int vm_collect_local_variables_in_heap(rb_thread_t *th, const VALUE *dfp, const struct local_var_list *vars);
- static VALUE rb_eUncaughtThrow;
- -static ID id_tag, id_value;
- +static ID id_result, id_tag, id_value;
- #define id_mesg idMesg
- /* vm_backtrace.c */
- @@ -1067,6 +1067,12 @@ loop_i(void)
- }
- static VALUE
- +loop_stop(VALUE dummy, VALUE exc)
- +{
- + return rb_attr_get(exc, id_result);
- +}
- +
- +static VALUE
- rb_f_loop_size(VALUE self, VALUE args, VALUE eobj)
- {
- return DBL2NUM(INFINITY);
- @@ -1095,8 +1101,7 @@ static VALUE
- rb_f_loop(VALUE self)
- {
- RETURN_SIZED_ENUMERATOR(self, 0, 0, rb_f_loop_size);
- - rb_rescue2(loop_i, (VALUE)0, 0, 0, rb_eStopIteration, (VALUE)0);
- - return Qnil; /* dummy */
- + return rb_rescue2(loop_i, (VALUE)0, loop_stop, (VALUE)0, rb_eStopIteration, (VALUE)0);
- }
- #if VMDEBUG
- @@ -2172,6 +2177,7 @@ Init_vm_eval(void)
- rb_define_method(rb_eUncaughtThrow, "value", uncaught_throw_value, 0);
- rb_define_method(rb_eUncaughtThrow, "to_s", uncaught_throw_to_s, 0);
- + id_result = rb_intern_const("result");
- id_tag = rb_intern_const("tag");
- id_value = rb_intern_const("value");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement