Skip to content
Browse files

fix Struct#eql? on nested structs

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4406 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 4bcda95 commit 32f8948631746054353b919041086ebabe1f2a1a Laurent Sansonetti committed Aug 5, 2010
Showing with 24 additions and 10 deletions.
  1. +24 −10 struct.c
View
34 struct.c
@@ -875,21 +875,35 @@ rb_struct_hash(VALUE s, SEL sel)
*/
static VALUE
-rb_struct_eql(VALUE s, SEL sel, VALUE s2)
+rb_struct_eql_r(VALUE s, VALUE s2, int recur)
{
- long i;
+ if (recur) {
+ return Qtrue;
+ }
+ for (int i = 0; i < RSTRUCT_LEN(s); i++) {
+ if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) {
+ return Qfalse;
+ }
+ }
+ return Qtrue;
+}
- if (s == s2) return Qtrue;
- if (TYPE(s2) != T_STRUCT) return Qfalse;
- if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
+static VALUE
+rb_struct_eql(VALUE s, SEL sel, VALUE s2)
+{
+ if (s == s2) {
+ return Qtrue;
+ }
+ if (TYPE(s2) != T_STRUCT) {
+ return Qfalse;
+ }
+ if (rb_obj_class(s) != rb_obj_class(s2)) {
+ return Qfalse;
+ }
if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
rb_bug("inconsistent struct"); /* should never happen */
}
-
- for (i=0; i<RSTRUCT_LEN(s); i++) {
- if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse;
- }
- return Qtrue;
+ return rb_exec_recursive(rb_struct_eql_r, s, s2);
}
/*

0 comments on commit 32f8948

Please sign in to comment.
Something went wrong with that request. Please try again.