Revision: 4406 http://trac.macosforge.org/projects/ruby/changeset/4406 Author: lsansonetti@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); } /*
participants (1)
-
source_changes@macosforge.org