summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-15 21:30:50 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-15 21:30:50 +0000
commit128c696c505bfd4ecf0a01bae546bfc720787fc2 (patch)
tree8efee8e6cc94d15eb0206a5837830290e4cfee22 /hash.c
parent03c6b39e8ea9a13663c485129a053fadd0cc148d (diff)
downloadruby-128c696c505bfd4ecf0a01bae546bfc720787fc2.tar.gz
ruby-128c696c505bfd4ecf0a01bae546bfc720787fc2.tar.xz
ruby-128c696c505bfd4ecf0a01bae546bfc720787fc2.zip
* thread.c (rb_exec_recursive_outer, rb_exec_recursive): Added method to short-circuit to the outermost level in case of recursion
* test/ruby/test_thread.rb (test_recursive_outer): Test for above * hash.c (rb_hash_hash): Return a sensible hash for in case of recursion [ruby-core:24648] * range.c (rb_range_hash): ditto * struct.c (rb_struct_hash): ditto * array.c (rb_array_hash): ditto * test/ruby/test_array.rb (test_hash2): test for above git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/hash.c b/hash.c
index bc0a2511e..184ea909a 100644
--- a/hash.c
+++ b/hash.c
@@ -1556,13 +1556,13 @@ recursive_hash(VALUE hash, VALUE dummy, int recur)
{
st_index_t hval;
- if (recur) {
- rb_raise(rb_eArgError, "recursive key for hash");
- }
if (!RHASH(hash)->ntbl)
return LONG2FIX(0);
hval = RHASH(hash)->ntbl->num_entries;
- rb_hash_foreach(hash, hash_i, (VALUE)&hval);
+ if (recur)
+ hval = rb_hash_end(rb_hash_uint(rb_hash_start(rb_hash(rb_cHash)), hval));
+ else
+ rb_hash_foreach(hash, hash_i, (VALUE)&hval);
return INT2FIX(hval);
}
@@ -1577,7 +1577,7 @@ recursive_hash(VALUE hash, VALUE dummy, int recur)
static VALUE
rb_hash_hash(VALUE hash)
{
- return rb_exec_recursive(recursive_hash, hash, 0);
+ return rb_exec_recursive_outer(recursive_hash, hash, 0);
}
static int