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

ruby-changes:31129

From: nobu <ko1@a...>
Date: Wed, 9 Oct 2013 13:53:25 +0900 (JST)
Subject: [ruby-changes:31129] nobu:r43208 (trunk): compar.c: fail if recursion

nobu	2013-10-09 13:53:18 +0900 (Wed, 09 Oct 2013)

  New Revision: 43208

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

  Log:
    compar.c: fail if recursion
    
    * compar.c (cmp_eq): fail if recursion.  [ruby-core:57736] [Bug #9003]
    * thread.c (rb_exec_recursive_paired_outer): new function which is
      combinnation of paired and outer variants.

  Modified files:
    trunk/ChangeLog
    trunk/compar.c
    trunk/include/ruby/intern.h
    trunk/test/ruby/test_comparable.rb
    trunk/thread.c
Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 43207)
+++ include/ruby/intern.h	(revision 43208)
@@ -448,6 +448,7 @@ void rb_thread_atfork_before_exec(void); https://github.com/ruby/ruby/blob/trunk/include/ruby/intern.h#L448
 VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE);
 VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE,VALUE);
 VALUE rb_exec_recursive_outer(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE);
+VALUE rb_exec_recursive_paired_outer(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE,VALUE);
 /* dir.c */
 VALUE rb_dir_getwd(void);
 /* file.c */
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43207)
+++ ChangeLog	(revision 43208)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Oct  9 13:53:14 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* compar.c (cmp_eq): fail if recursion.  [ruby-core:57736] [Bug #9003]
+
+	* thread.c (rb_exec_recursive_paired_outer): new function which is
+	  combinnation of paired and outer variants.
+
 Wed Oct  9 09:18:14 2013  Koichi Sasada  <ko1@a...>
 
 	* include/ruby/debug.h,
Index: thread.c
===================================================================
--- thread.c	(revision 43207)
+++ thread.c	(revision 43208)
@@ -4954,6 +4954,18 @@ rb_exec_recursive_outer(VALUE (*func) (V https://github.com/ruby/ruby/blob/trunk/thread.c#L4954
 }
 
 /*
+ * If recursion is detected on the current method, obj and paired_obj,
+ * the outermost func will be called with (obj, arg, Qtrue). All inner
+ * func will be short-circuited using throw.
+ */
+
+VALUE
+rb_exec_recursive_paired_outer(VALUE (*func) (VALUE, VALUE, int), VALUE obj, VALUE paired_obj, VALUE arg)
+{
+    return exec_recursive(func, obj, rb_obj_id(paired_obj), arg, 1);
+}
+
+/*
  *  call-seq:
  *     thread.backtrace    -> array
  *
Index: compar.c
===================================================================
--- compar.c	(revision 43207)
+++ compar.c	(revision 43208)
@@ -52,9 +52,16 @@ rb_invcmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/compar.c#L52
 }
 
 static VALUE
+cmp_eq_recursive(VALUE arg1, VALUE arg2, int recursive)
+{
+    if (recursive) return Qfalse;
+    return rb_funcallv(arg1, cmp, 1, &arg2);
+}
+
+static VALUE
 cmp_eq(VALUE *a)
 {
-    VALUE c = rb_funcall(a[0], cmp, 1, a[1]);
+    VALUE c = rb_exec_recursive_paired_outer(cmp_eq_recursive, a[0], a[1], a[1]);
 
     if (NIL_P(c)) return Qfalse;
     if (rb_cmpint(c, a[0], a[1]) == 0) return Qtrue;
Index: test/ruby/test_comparable.rb
===================================================================
--- test/ruby/test_comparable.rb	(revision 43207)
+++ test/ruby/test_comparable.rb	(revision 43208)
@@ -76,4 +76,11 @@ class TestComparable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_comparable.rb#L76
       assert_nil(Time.new <=> "")
     }
   end
+
+  def test_no_cmp
+    bug9003 = '[ruby-core:57736] [Bug #9003]'
+    assert_nothing_raised(SystemStackError, bug9003) {
+      @o <=> @o.dup
+    }
+  end
 end

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

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