ruby-changes:28561
From: nagachika <ko1@a...>
Date: Wed, 8 May 2013 23:38:57 +0900 (JST)
Subject: [ruby-changes:28561] nagachika:r40613 (ruby_2_0_0): merge revision(s) 40583,40584,40585,40590: [Backport #8367]
nagachika 2013-05-08 23:38:43 +0900 (Wed, 08 May 2013) New Revision: 40613 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40613 Log: merge revision(s) 40583,40584,40585,40590: [Backport #8367] * insns.def (defined): get method entry from the method top level frame, not block frame. [ruby-core:54769] [Bug #8367] * insns.def (defined): use vm_search_superclass() like as normal super call. based on a patch <https://gist.github.com/wanabe/5520026> by wanabe. * vm_insnhelper.c (vm_search_superclass): return error but not raise exceptions. * vm_insnhelper.c (vm_search_super_method): check the result of vm_search_superclass and raise execptions on error. vm_search_superclass and raise exceptions on error. Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/insns.def branches/ruby_2_0_0/test/ruby/test_defined.rb branches/ruby_2_0_0/version.h branches/ruby_2_0_0/vm_insnhelper.c Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 40612) +++ ruby_2_0_0/ChangeLog (revision 40613) @@ -1,3 +1,20 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Wed May 8 23:07:19 2013 Nobuyoshi Nakada <nobu@r...> + + * insns.def (defined): use vm_search_superclass() like as normal super + call. based on a patch <https://gist.github.com/wanabe/5520026> by + wanabe. + + * vm_insnhelper.c (vm_search_superclass): return error but not raise + exceptions. + + * vm_insnhelper.c (vm_search_super_method): check the result of + vm_search_superclass and raise exceptions on error. + +Wed May 8 23:07:19 2013 Nobuyoshi Nakada <nobu@r...> + + * insns.def (defined): get method entry from the method top level + frame, not block frame. [ruby-core:54769] [Bug #8367] + Wed May 8 01:18:41 2013 Tanaka Akira <akr@f...> * internal.h (MUL_OVERFLOW_SIGNED_INTEGER_P): New macro. Index: ruby_2_0_0/insns.def =================================================================== --- ruby_2_0_0/insns.def (revision 40612) +++ ruby_2_0_0/insns.def (revision 40613) @@ -764,10 +764,10 @@ defined https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/insns.def#L764 } break; case DEFINED_ZSUPER:{ - const rb_method_entry_t *me = GET_CFP()->me; - if (me) { - VALUE klass = vm_search_normal_superclass(GET_CFP()->klass); - ID id = me->def ? me->def->original_id : me->called_id; + rb_call_info_t cit; + if (vm_search_superclass(GET_CFP(), GET_ISEQ(), Qnil, &cit) == 0) { + VALUE klass = cit.klass; + ID id = cit.mid; if (rb_method_boundp(klass, id, 0)) { expr_type = DEFINED_ZSUPER; } Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 40612) +++ ruby_2_0_0/version.h (revision 40613) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-05-08" -#define RUBY_PATCHLEVEL 187 +#define RUBY_PATCHLEVEL 188 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 5 Index: ruby_2_0_0/vm_insnhelper.c =================================================================== --- ruby_2_0_0/vm_insnhelper.c (revision 40612) +++ ruby_2_0_0/vm_insnhelper.c (revision 40613) @@ -1927,7 +1927,7 @@ vm_super_outside(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L1927 rb_raise(rb_eNoMethodError, "super called outside of method"); } -static void +static int vm_search_superclass(rb_control_frame_t *reg_cfp, rb_iseq_t *iseq, VALUE sigval, rb_call_info_t *ci) { while (iseq && !iseq->klass) { @@ -1935,7 +1935,7 @@ vm_search_superclass(rb_control_frame_t https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L1935 } if (iseq == 0) { - vm_super_outside(); + return -1; } ci->mid = iseq->defined_method_id; @@ -1946,7 +1946,7 @@ vm_search_superclass(rb_control_frame_t https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L1946 if (!sigval) { /* zsuper */ - rb_raise(rb_eRuntimeError, "implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly."); + return -2; } while (lcfp->iseq != iseq) { @@ -1955,7 +1955,7 @@ vm_search_superclass(rb_control_frame_t https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L1955 while (1) { lcfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(lcfp); if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, lcfp)) { - vm_super_outside(); + return -1; } if (lcfp->ep == tep) { break; @@ -1965,7 +1965,7 @@ vm_search_superclass(rb_control_frame_t https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L1965 /* temporary measure for [Bug #2420] [Bug #3136] */ if (!lcfp->me) { - vm_super_outside(); + return -1; } ci->mid = lcfp->me->def->original_id; @@ -1974,6 +1974,8 @@ vm_search_superclass(rb_control_frame_t https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L1974 else { ci->klass = vm_search_normal_superclass(reg_cfp->klass); } + + return 0; } static void @@ -2003,7 +2005,15 @@ vm_search_super_method(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L2005 rb_obj_classname(ci->recv), rb_class2name(m)); } - vm_search_superclass(GET_CFP(), iseq, sigval, ci); + switch (vm_search_superclass(GET_CFP(), iseq, sigval, ci)) { + case -1: + vm_super_outside(); + case -2: + rb_raise(rb_eRuntimeError, + "implicit argument passing of super from method defined" + " by define_method() is not supported." + " Specify all arguments explicitly."); + } /* TODO: use inline cache */ ci->me = rb_method_entry(ci->klass, ci->mid, &ci->defined_class); Index: ruby_2_0_0/test/ruby/test_defined.rb =================================================================== --- ruby_2_0_0/test/ruby/test_defined.rb (revision 40612) +++ ruby_2_0_0/test/ruby/test_defined.rb (revision 40613) @@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_defined.rb#L1 require 'test/unit' +require_relative 'envutil' class TestDefined < Test::Unit::TestCase class Foo @@ -181,4 +182,24 @@ class TestDefined < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_defined.rb#L182 end assert_equal("super", c.new.m) end + + def test_super_in_block + bug8367 = '[ruby-core:54769] [Bug #8367]' + c = Class.new do + def x; end + end + + m = Module.new do + def b; yield; end + def x; b {return defined?(super)}; end + end + + o = c.new + o.extend(m) + assert_equal("super", o.x) + end + + def test_super_toplevel + assert_separately([], "assert_nil(defined?(super))") + end end Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r40583-40585,40590 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/