From 1796522f10e4bee3db8df77fa66f749084592285 Mon Sep 17 00:00:00 2001 From: marcandre Date: Tue, 15 Sep 2009 21:30:50 +0000 Subject: * 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@24943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- struct.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'struct.c') diff --git a/struct.c b/struct.c index 463fa392b5..f9adfb868b 100644 --- a/struct.c +++ b/struct.c @@ -810,13 +810,12 @@ recursive_hash(VALUE s, VALUE dummy, int recur) st_index_t h; VALUE n; - if (recur) { - rb_raise(rb_eArgError, "recursive key for hash"); - } h = rb_hash_start(rb_hash(rb_obj_class(s))); - for (i = 0; i < RSTRUCT_LEN(s); i++) { - n = rb_hash(RSTRUCT_PTR(s)[i]); - h = rb_hash_uint(h, NUM2LONG(n)); + if (!recur) { + for (i = 0; i < RSTRUCT_LEN(s); i++) { + n = rb_hash(RSTRUCT_PTR(s)[i]); + h = rb_hash_uint(h, NUM2LONG(n)); + } } h = rb_hash_end(h); return INT2FIX(h); @@ -832,7 +831,7 @@ recursive_hash(VALUE s, VALUE dummy, int recur) static VALUE rb_struct_hash(VALUE s) { - return rb_exec_recursive(recursive_hash, s, 0); + return rb_exec_recursive_outer(recursive_hash, s, 0); } /* -- cgit v1.2.3