[macruby-changes] [4406] MacRuby/trunk/struct.c

source_changes at macosforge.org source_changes at macosforge.org
Wed Aug 4 17:34:40 PDT 2010


Revision: 4406
          http://trac.macosforge.org/projects/ruby/changeset/4406
Author:   lsansonetti at apple.com
Date:     2010-08-04 17:34:39 -0700 (Wed, 04 Aug 2010)
Log Message:
-----------
fix Struct#eql? on nested structs

Modified Paths:
--------------
    MacRuby/trunk/struct.c

Modified: MacRuby/trunk/struct.c
===================================================================
--- MacRuby/trunk/struct.c	2010-08-04 20:53:09 UTC (rev 4405)
+++ MacRuby/trunk/struct.c	2010-08-05 00:34:39 UTC (rev 4406)
@@ -875,21 +875,35 @@
  */
 
 static VALUE
+rb_struct_eql_r(VALUE s, VALUE s2, int recur)
+{
+    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;
+}
+
+static VALUE
 rb_struct_eql(VALUE s, SEL sel, 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;
+    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);
 }
 
 /*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100804/78d673c9/attachment.html>


More information about the macruby-changes mailing list