From 357d903fda1d768a14f47fd7a36e1491a0fd0efb Mon Sep 17 00:00:00 2001 From: marcandre Date: Sun, 20 Sep 2009 02:14:02 +0000 Subject: * 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 git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25010 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 f9adfb868..0001ad825 100644 --- a/struct.c +++ b/struct.c @@ -768,6 +768,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 @@ -788,8 +800,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; @@ -797,10 +807,7 @@ rb_struct_equal(VALUE s, VALUE s2) rb_bug("inconsistent struct"); /* should never happen */ } - for (i=0; i true or false @@ -845,8 +864,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; @@ -854,10 +871,7 @@ rb_struct_eql(VALUE s, VALUE s2) rb_bug("inconsistent struct"); /* should never happen */ } - for (i=0; i