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

ruby-changes:27274

From: drbrain <ko1@a...>
Date: Wed, 20 Feb 2013 08:58:36 +0900 (JST)
Subject: [ruby-changes:27274] drbrain:r39325 (ruby_2_0_0): Merge revision 39292:

drbrain	2013-02-20 08:57:11 +0900 (Wed, 20 Feb 2013)

  New Revision: 39325

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39325

  Log:
    Merge revision 39292:
    
    * compar.c (rb_invcmp): compare by inversed comarison, with preventing
      from infinite recursion.  [ruby-core:52305] [Bug #7870]
    
    * string.c (rb_str_cmp_m), time.c (time_cmp): get rid of infinite
      recursion.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/compar.c
    branches/ruby_2_0_0/internal.h
    branches/ruby_2_0_0/string.c
    branches/ruby_2_0_0/test/ruby/test_comparable.rb
    branches/ruby_2_0_0/time.c

Index: ruby_2_0_0/time.c
===================================================================
--- ruby_2_0_0/time.c	(revision 39324)
+++ ruby_2_0_0/time.c	(revision 39325)
@@ -3365,12 +3365,7 @@ time_cmp(VALUE time1, VALUE time2) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L3365
 	n = wcmp(tobj1->timew, tobj2->timew);
     }
     else {
-	VALUE tmp;
-
-	tmp = rb_funcall(time2, rb_intern("<=>"), 1, time1);
-	if (NIL_P(tmp)) return Qnil;
-
-	n = -rb_cmpint(tmp, time1, time2);
+	return rb_invcmp(time1, time2);
     }
     if (n == 0) return INT2FIX(0);
     if (n > 0) return INT2FIX(1);
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 39324)
+++ ruby_2_0_0/ChangeLog	(revision 39325)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Wed Feb 20 08:05:25 2013 Nobuyoshi Nakada  <nobu@r...>
+
+	* compar.c (rb_invcmp): compare by inversed comarison, with preventing
+	  from infinite recursion.  [ruby-core:52305] [Bug #7870]
+
+	* string.c (rb_str_cmp_m), time.c (time_cmp): get rid of infinite
+	  recursion.
+
 Tue Feb 19 15:49:58 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (unexpand_shvar): regularize a shell variable by
Index: ruby_2_0_0/string.c
===================================================================
--- ruby_2_0_0/string.c	(revision 39324)
+++ ruby_2_0_0/string.c	(revision 39325)
@@ -2389,13 +2389,8 @@ rb_str_cmp_m(VALUE str1, VALUE str2) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/string.c#L2389
 	if (RB_TYPE_P(tmp, T_STRING)) {
 	    result = rb_str_cmp(str1, tmp);
 	}
-	else if ((tmp = rb_check_funcall(str2, rb_intern("<=>"), 1, &str1)) ==
-		 Qundef) {
-	    return Qnil;
-	}
 	else {
-	    if (NIL_P(tmp)) return Qnil;
-	    result = -rb_cmpint(tmp, str1, str2);
+	    return rb_invcmp(str1, str2);
 	}
     }
     else {
Index: ruby_2_0_0/compar.c
===================================================================
--- ruby_2_0_0/compar.c	(revision 39324)
+++ ruby_2_0_0/compar.c	(revision 39325)
@@ -32,6 +32,26 @@ rb_cmperr(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/compar.c#L32
 }
 
 static VALUE
+invcmp_recursive(VALUE x, VALUE y, int recursive)
+{
+    if (recursive) return Qnil;
+    return rb_check_funcall(y, cmp, 1, &x);
+}
+
+VALUE
+rb_invcmp(VALUE x, VALUE y)
+{
+    VALUE invcmp = rb_exec_recursive(invcmp_recursive, x, y);
+    if (invcmp == Qundef || NIL_P(invcmp)) {
+	return Qnil;
+    }
+    else {
+	int result = -rb_cmpint(invcmp, x, y);
+	return INT2FIX(result);
+    }
+}
+
+static VALUE
 cmp_eq(VALUE *a)
 {
     VALUE c = rb_funcall(a[0], cmp, 1, a[1]);
Index: ruby_2_0_0/internal.h
===================================================================
--- ruby_2_0_0/internal.h	(revision 39324)
+++ ruby_2_0_0/internal.h	(revision 39325)
@@ -66,6 +66,9 @@ VALUE rb_special_singleton_class(VALUE); https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/internal.h#L66
 VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach);
 void Init_class_hierarchy(void);
 
+/* compar.c */
+VALUE rb_invcmp(VALUE, VALUE);
+
 /* compile.c */
 int rb_dvar_defined(ID);
 int rb_local_defined(ID);
Index: ruby_2_0_0/test/ruby/test_comparable.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_comparable.rb	(revision 39324)
+++ ruby_2_0_0/test/ruby/test_comparable.rb	(revision 39325)
@@ -69,4 +69,11 @@ class TestComparable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_comparable.rb#L69
     assert_raise(ArgumentError) { 1.0 < nil }
     assert_raise(ArgumentError) { 1.0 < Object.new }
   end
+
+  def test_inversed_compare
+    bug7870 = '[ruby-core:52305] [Bug #7870]'
+    assert_nothing_raised(SystemStackError, bug7870) {
+      assert_nil(Time.new <=> "")
+    }
+  end
 end

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r39292


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

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