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

ruby-changes:31781

From: nobu <ko1@a...>
Date: Wed, 27 Nov 2013 02:20:26 +0900 (JST)
Subject: [ruby-changes:31781] nobu:r43860 (trunk): should not ignore the rest of recursive constructs

nobu	2013-11-27 02:20:16 +0900 (Wed, 27 Nov 2013)

  New Revision: 43860

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

  Log:
    should not ignore the rest of recursive constructs
    
    * array.c (rb_ary_hash): should not ignore the rest of recursive
      constructs.
    * hash.c (rb_hash_hash): ditto.
    * range.c (range_hash): ditto.
    * struct.c (rb_struct_hash): ditto.
    * test/-ext-/test_recursion.rb (TestRecursion): separate from
      test/ruby/test_thread.rb.

  Added directories:
    trunk/ext/-test-/recursion/
  Added files:
    trunk/ext/-test-/recursion/extconf.rb
    trunk/ext/-test-/recursion/recursion.c
    trunk/test/-ext-/test_recursion.rb
  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/hash.c
    trunk/range.c
    trunk/struct.c
    trunk/test/ruby/test_array.rb
    trunk/test/ruby/test_thread.rb
Index: array.c
===================================================================
--- array.c	(revision 43859)
+++ array.c	(revision 43860)
@@ -3807,7 +3807,7 @@ recursive_hash(VALUE ary, VALUE dummy, i https://github.com/ruby/ruby/blob/trunk/array.c#L3807
 static VALUE
 rb_ary_hash(VALUE ary)
 {
-    return rb_exec_recursive_outer(recursive_hash, ary, 0);
+    return rb_exec_recursive_paired(recursive_hash, ary, ary, 0);
 }
 
 /*
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43859)
+++ ChangeLog	(revision 43860)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Nov 27 02:20:13 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* array.c (rb_ary_hash): should not ignore the rest of recursive
+	  constructs.
+
+	* hash.c (rb_hash_hash): ditto.
+
+	* range.c (range_hash): ditto.
+
+	* struct.c (rb_struct_hash): ditto.
+
+	* test/-ext-/test_recursion.rb (TestRecursion): separate from
+	  test/ruby/test_thread.rb.
+
 Tue Nov 26 22:43:36 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* hash.c (rb_hash): cut off if recursion detected to get rid of stack
Index: range.c
===================================================================
--- range.c	(revision 43859)
+++ range.c	(revision 43860)
@@ -274,7 +274,7 @@ recursive_hash(VALUE range, VALUE dummy, https://github.com/ruby/ruby/blob/trunk/range.c#L274
 static VALUE
 range_hash(VALUE range)
 {
-    return rb_exec_recursive_outer(recursive_hash, range, 0);
+    return rb_exec_recursive_paired(recursive_hash, range, range, 0);
 }
 
 static void
Index: struct.c
===================================================================
--- struct.c	(revision 43859)
+++ struct.c	(revision 43860)
@@ -980,7 +980,7 @@ recursive_hash(VALUE s, VALUE dummy, int https://github.com/ruby/ruby/blob/trunk/struct.c#L980
 static VALUE
 rb_struct_hash(VALUE s)
 {
-    return rb_exec_recursive_outer(recursive_hash, s, 0);
+    return rb_exec_recursive_paired(recursive_hash, s, s, 0);
 }
 
 static VALUE
Index: ext/-test-/recursion/extconf.rb
===================================================================
--- ext/-test-/recursion/extconf.rb	(revision 0)
+++ ext/-test-/recursion/extconf.rb	(revision 43860)
@@ -0,0 +1,2 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/recursion/extconf.rb#L1
+require 'mkmf'
+create_makefile("-test-/recursion")

Property changes on: ext/-test-/recursion/extconf.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ext/-test-/recursion/recursion.c
===================================================================
--- ext/-test-/recursion/recursion.c	(revision 0)
+++ ext/-test-/recursion/recursion.c	(revision 43860)
@@ -0,0 +1,28 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/recursion/recursion.c#L1
+#include <ruby.h>
+
+static VALUE
+recursive_i(VALUE obj, VALUE mid, int recur)
+{
+    if (recur) return Qnil;
+    return rb_funcallv(obj, rb_to_id(mid), 0, 0);
+}
+
+static VALUE
+exec_recursive(VALUE self, VALUE mid)
+{
+    return rb_exec_recursive(recursive_i, self, mid);
+}
+
+static VALUE
+exec_recursive_outer(VALUE self, VALUE mid)
+{
+    return rb_exec_recursive_outer(recursive_i, self, mid);
+}
+
+void
+Init_recursion(void)
+{
+    VALUE m = rb_define_module_under(rb_define_module("Bug"), "Recursive");
+    rb_define_method(m, "exec_recursive", exec_recursive, 1);
+    rb_define_method(m, "exec_recursive_outer", exec_recursive_outer, 1);
+}

Property changes on: ext/-test-/recursion/recursion.c
___________________________________________________________________
Added: svn:eol-style
   + LF


Property changes on: ext/-test-/recursion
___________________________________________________________________
Added: svn:ignore
   + Makefile
extconf.h
mkmf.log


Index: hash.c
===================================================================
--- hash.c	(revision 43859)
+++ hash.c	(revision 43860)
@@ -1944,7 +1944,7 @@ recursive_hash(VALUE hash, VALUE dummy, https://github.com/ruby/ruby/blob/trunk/hash.c#L1944
 static VALUE
 rb_hash_hash(VALUE hash)
 {
-    return rb_exec_recursive_outer(recursive_hash, hash, 0);
+    return rb_exec_recursive_paired(recursive_hash, hash, hash, 0);
 }
 
 static int
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb	(revision 43859)
+++ test/ruby/test_array.rb	(revision 43860)
@@ -2012,9 +2012,9 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L2012
   end
 
   def test_hash2
+    assert_not_equal([[1]].hash, [[2]].hash)
     a = []
     a << a
-    assert_equal([[a]].hash, a.hash)
     assert_not_equal([a, a].hash, a.hash) # Implementation dependent
   end
 
Index: test/ruby/test_thread.rb
===================================================================
--- test/ruby/test_thread.rb	(revision 43859)
+++ test/ruby/test_thread.rb	(revision 43860)
@@ -467,19 +467,6 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L467
     m.unlock
   end
 
-  def test_recursive_outer
-    arr = []
-    obj = Struct.new(:foo, :visited).new(arr, false)
-    arr << obj
-    def obj.hash
-      self[:visited] = true
-      super
-      raise "recursive_outer should short circuit intermediate calls"
-    end
-    assert_nothing_raised {arr.hash}
-    assert(obj[:visited], "obj.hash was not called")
-  end
-
   def test_thread_instance_variable
     bug4389 = '[ruby-core:35192]'
     assert_in_out_err([], <<-INPUT, %w(), [], bug4389)
Index: test/-ext-/test_recursion.rb
===================================================================
--- test/-ext-/test_recursion.rb	(revision 0)
+++ test/-ext-/test_recursion.rb	(revision 43860)
@@ -0,0 +1,36 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/test_recursion.rb#L1
+# -*- coding: us-ascii -*-
+require 'test/unit'
+require_relative '../ruby/envutil'
+
+class TestRecursion < Test::Unit::TestCase
+  require '-test-/recursion'
+
+  def setup
+    @obj = Struct.new(:visited).new(false)
+    @obj.extend(Bug::Recursive)
+  end
+
+  def test_recursive
+    def @obj.doit
+      self.visited = true
+      exec_recursive(:doit)
+      raise "recursive"
+    end
+    assert_raise_with_message(RuntimeError, "recursive") {
+      @obj.exec_recursive(:doit)
+    }
+    assert(@obj.visited, "obj.hash was not called")
+  end
+
+  def test_recursive_outer
+    def @obj.doit
+      self.visited = true
+      exec_recursive_outer(:doit)
+      raise "recursive_outer should short circuit intermediate calls"
+    end
+    assert_nothing_raised {
+      @obj.exec_recursive_outer(:doit)
+    }
+    assert(@obj.visited, "obj.hash was not called")
+  end
+end

Property changes on: test/-ext-/test_recursion.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


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

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