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

ruby-changes:44401

From: nobu <ko1@a...>
Date: Sat, 22 Oct 2016 22:33:41 +0900 (JST)
Subject: [ruby-changes:44401] nobu:r56474 (trunk): numeric.c: fix up r55891

nobu	2016-10-22 22:33:34 +0900 (Sat, 22 Oct 2016)

  New Revision: 56474

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

  Log:
    numeric.c: fix up r55891
    
    * numeric.c (num_funcall1): check recursion by inverse pair, to
      fix fake infinite recursion.  [ruby-core:77713] [Bug #12864]

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
    trunk/test/ruby/test_numeric.rb
Index: test/ruby/test_numeric.rb
===================================================================
--- test/ruby/test_numeric.rb	(revision 56473)
+++ test/ruby/test_numeric.rb	(revision 56474)
@@ -353,4 +353,31 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L353
       assert_raise(ArgumentError) {1.remainder(x)}
     end;
   end
+
+  def test_comparison_comparable
+    bug12864 = '[ruby-core:77713] [Bug #12864]'
+
+    myinteger = Class.new do
+      include Comparable
+
+      def initialize(i)
+        @i = i.to_i
+      end
+      attr_reader :i
+
+      def <=>(other)
+        @i <=> (other.is_a?(self.class) ? other.i : other)
+      end
+    end
+
+    all_assertions(bug12864) do |a|
+      [5, 2**62, 2**61].each do |i|
+        a.for("%#x"%i) do
+          m = myinteger.new(i)
+          assert_equal(i, m)
+          assert_equal(m, i)
+        end
+      end
+    end
+  end
 end
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56473)
+++ ChangeLog	(revision 56474)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Oct 22 22:33:32 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (num_funcall1): check recursion by inverse pair, to
+	  fix fake infinite recursion.  [ruby-core:77713] [Bug #12864]
+
 Sat Oct 22 18:52:32 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* hash.c (rb_hash_compact_bang): should return nil if no elements
Index: numeric.c
===================================================================
--- numeric.c	(revision 56473)
+++ numeric.c	(revision 56474)
@@ -294,10 +294,10 @@ num_funcall0(VALUE x, ID func) https://github.com/ruby/ruby/blob/trunk/numeric.c#L294
 }
 
 static VALUE
-num_funcall_op_1(VALUE x, VALUE arg, int recursive)
+num_funcall_op_1(VALUE y, VALUE arg, int recursive)
 {
     ID func = (ID)((VALUE *)arg)[0];
-    VALUE y = ((VALUE *)arg)[1];
+    VALUE x = ((VALUE *)arg)[1];
     if (recursive) {
 	const char *name = rb_id2name(func);
 	if (ISALNUM(name[0])) {
@@ -317,8 +317,8 @@ num_funcall1(VALUE x, ID func, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L317
 {
     VALUE args[2];
     args[0] = (VALUE)func;
-    args[1] = y;
-    return rb_exec_recursive_paired(num_funcall_op_1, x, y, (VALUE)args);
+    args[1] = x;
+    return rb_exec_recursive_paired(num_funcall_op_1, y, x, (VALUE)args);
 }
 
 /*

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

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