From 6e6417c8d38afced7eb7c10781f20f7b19ebbc89 Mon Sep 17 00:00:00 2001 From: yugui Date: Fri, 27 Nov 2009 02:54:29 +0000 Subject: merges r25010 from trunk into ruby_1_9_1 and adds tests for it. -- * struct.c (rb_struct_equal, rb_struct_eql): Handle comparison of recursive structures [ruby-core:24759] * range.c (range_eq, range_eql): ditto for ranges -- test for r25010 * test/ruby/test_struct.rb (TestStruct#test_comparison_when_recursive): new test. * test/ruby/test_range.rb (TestRange#test_comparison_when_recursive): new test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@25943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- struct.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'struct.c') diff --git a/struct.c b/struct.c index 3d876bb216..79403a5fb6 100644 --- a/struct.c +++ b/struct.c @@ -760,6 +760,18 @@ rb_struct_select(int argc, VALUE *argv, VALUE s) return result; } +static VALUE +recursive_equal(VALUE s, VALUE s2, int recur) +{ + long i; + + if (recur) return Qtrue; /* Subtle! */ + for (i=0; i true or false @@ -780,8 +792,6 @@ rb_struct_select(int argc, VALUE *argv, VALUE s) static VALUE rb_struct_equal(VALUE s, VALUE s2) { - long i; - if (s == s2) return Qtrue; if (TYPE(s2) != T_STRUCT) return Qfalse; if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse; @@ -789,10 +799,7 @@ rb_struct_equal(VALUE s, VALUE s2) rb_bug("inconsistent struct"); /* should never happen */ } - for (i=0; i true or false @@ -828,8 +847,6 @@ rb_struct_hash(VALUE s) static VALUE rb_struct_eql(VALUE s, VALUE s2) { - long i; - if (s == s2) return Qtrue; if (TYPE(s2) != T_STRUCT) return Qfalse; if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse; @@ -837,10 +854,7 @@ rb_struct_eql(VALUE s, VALUE s2) rb_bug("inconsistent struct"); /* should never happen */ } - for (i=0; i