[前][次][番号順一覧][スレッド一覧]

ruby-changes:52905

From: usa <ko1@a...>
Date: Wed, 17 Oct 2018 18:25:16 +0900 (JST)
Subject: [ruby-changes:52905] usa:r65118 (ruby_2_4): merge revision(s) 63067, 63068: [Backport #14658]

usa	2018-10-17 18:25:11 +0900 (Wed, 17 Oct 2018)

  New Revision: 65118

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65118

  Log:
    merge revision(s) 63067,63068: [Backport #14658]
    
    Fix Kernel#singleton_method with Module#Prepend
    
    * proc.c (rb_obj_singleton_method): search the method entry from
      the origin class, for fix prepended modules.  [Bug #14658]
    
    From: Vasiliy Ermolovich <younash@g...>
    
    proc.c: fix segfault when no singleton class
    
    * proc.c (rb_obj_singleton_method): bail out if the receiver does
      not have the singleton class without accessing the origin class
      not to segfault.  [Bug #14658]

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/proc.c
    branches/ruby_2_4/test/ruby/test_method.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 65117)
+++ ruby_2_4/version.h	(revision 65118)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.5"
 #define RUBY_RELEASE_DATE "2018-10-17"
-#define RUBY_PATCHLEVEL 332
+#define RUBY_PATCHLEVEL 333
 
 #define RUBY_RELEASE_YEAR 2018
 #define RUBY_RELEASE_MONTH 10
Index: ruby_2_4/test/ruby/test_method.rb
===================================================================
--- ruby_2_4/test/ruby/test_method.rb	(revision 65117)
+++ ruby_2_4/test/ruby/test_method.rb	(revision 65118)
@@ -779,6 +779,19 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_method.rb#L779
     assert_equal(:bar, m.call, feature8391)
   end
 
+  def test_singleton_method_prepend
+    bug14658 = '[Bug #14658]'
+    c1 = Class.new
+    o = c1.new
+    def o.bar; :bar; end
+    class << o; prepend Module.new; end
+    m = assert_nothing_raised(NameError, bug14658) {o.singleton_method(:bar)}
+    assert_equal(:bar, m.call, bug14658)
+
+    o = Object.new
+    assert_raise(NameError, bug14658) {o.singleton_method(:bar)}
+  end
+
   Feature9783 = '[ruby-core:62212] [Feature #9783]'
 
   def assert_curry_three_args(m)
Index: ruby_2_4/proc.c
===================================================================
--- ruby_2_4/proc.c	(revision 65117)
+++ ruby_2_4/proc.c	(revision 65118)
@@ -1766,21 +1766,23 @@ VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_4/proc.c#L1766
 rb_obj_singleton_method(VALUE obj, VALUE vid)
 {
     const rb_method_entry_t *me;
-    VALUE klass;
+    VALUE klass = rb_singleton_class_get(obj);
     ID id = rb_check_id(&vid);
 
+    if (NIL_P(klass) || NIL_P(klass = RCLASS_ORIGIN(klass))) {
+      undef:
+	rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
+			  obj, vid);
+    }
     if (!id) {
-	if (!NIL_P(klass = rb_singleton_class_get(obj)) &&
-	    respond_to_missing_p(klass, obj, vid, FALSE)) {
+	if (respond_to_missing_p(klass, obj, vid, FALSE)) {
 	    id = rb_intern_str(vid);
 	    return mnew_missing(klass, obj, id, rb_cMethod);
 	}
-      undef:
-	rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
-			  obj, vid);
+	goto undef;
     }
-    if (NIL_P(klass = rb_singleton_class_get(obj)) ||
-	UNDEFINED_METHOD_ENTRY_P(me = rb_method_entry_at(klass, id)) ||
+    me = rb_method_entry_at(klass, id);
+    if (UNDEFINED_METHOD_ENTRY_P(me) ||
 	UNDEFINED_REFINED_METHOD_P(me->def)) {
 	vid = ID2SYM(id);
 	goto undef;
Index: ruby_2_4
===================================================================
--- ruby_2_4	(revision 65117)
+++ ruby_2_4	(revision 65118)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r63067-63068

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]