aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-26 17:20:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-26 17:20:16 +0000
commit94f01c55dfd2d1ce49fb253432267d87cca64cd1 (patch)
treeabc9c61dd4e9384bd67e1db4b1244138fefaf872
parentd503381ce8ac41d91c195313ea1da5f67ba8250c (diff)
downloadruby-94f01c55dfd2d1ce49fb253432267d87cca64cd1.tar.gz
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog14
-rw-r--r--array.c2
-rw-r--r--ext/-test-/recursion/extconf.rb2
-rw-r--r--ext/-test-/recursion/recursion.c28
-rw-r--r--hash.c2
-rw-r--r--range.c2
-rw-r--r--struct.c2
-rw-r--r--test/-ext-/test_recursion.rb36
-rw-r--r--test/ruby/test_array.rb2
-rw-r--r--test/ruby/test_thread.rb13
10 files changed, 85 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 7ab05f951b..b0d5acd3ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Wed Nov 27 02:20:13 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* hash.c (rb_hash): cut off if recursion detected to get rid of stack
diff --git a/array.c b/array.c
index baf6118a18..b27ae299f4 100644
--- a/array.c
+++ b/array.c
@@ -3807,7 +3807,7 @@ recursive_hash(VALUE ary, VALUE dummy, int recur)
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);
}
/*
diff --git a/ext/-test-/recursion/extconf.rb b/ext/-test-/recursion/extconf.rb
new file mode 100644
index 0000000000..92b28657f0
--- /dev/null
+++ b/ext/-test-/recursion/extconf.rb
@@ -0,0 +1,2 @@
+require 'mkmf'
+create_makefile("-test-/recursion")
diff --git a/ext/-test-/recursion/recursion.c b/ext/-test-/recursion/recursion.c
new file mode 100644
index 0000000000..13d41f0ba8
--- /dev/null
+++ b/ext/-test-/recursion/recursion.c
@@ -0,0 +1,28 @@
+#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);
+}
diff --git a/hash.c b/hash.c
index 1694a031c0..9944b5f4b1 100644
--- a/hash.c
+++ b/hash.c
@@ -1944,7 +1944,7 @@ recursive_hash(VALUE hash, VALUE dummy, int recur)
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
diff --git a/range.c b/range.c
index ebd0811a98..c772347c37 100644
--- a/range.c
+++ b/range.c
@@ -274,7 +274,7 @@ recursive_hash(VALUE range, VALUE dummy, int recur)
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
diff --git a/struct.c b/struct.c
index a961ac8600..bad339ffbb 100644
--- a/struct.c
+++ b/struct.c
@@ -980,7 +980,7 @@ recursive_hash(VALUE s, VALUE dummy, int recur)
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
diff --git a/test/-ext-/test_recursion.rb b/test/-ext-/test_recursion.rb
new file mode 100644
index 0000000000..43a256f942
--- /dev/null
+++ b/test/-ext-/test_recursion.rb
@@ -0,0 +1,36 @@
+# -*- 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
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index d7e1c365dd..9411c6a088 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -2012,9 +2012,9 @@ class TestArray < Test::Unit::TestCase
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
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index ab1b81a8fe..f74c4ec9cb 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -467,19 +467,6 @@ class TestThread < Test::Unit::TestCase
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)