summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-04-18 18:05:11 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-04-18 18:05:11 +0000
commit6987b0806e970c7e4b19800c2a2effc290947b78 (patch)
tree79823d81475a9659b3c0e21988721c7d6b200d04 /struct.c
parent18cdaa6828045306da4aa95f3828f634a8c9d0ee (diff)
* struct.c (rb_struct_eql): should compare values with "eql?".
* range.c (range_check): <=> returns nil for invalid values; should check. * regex.c (re_compile_pattern): should not set RE_OPTIMIZE_ANCHOR, if anychar_repeat is enclosed by parentheses. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/struct.c b/struct.c
index d695b15caf..b1fa31fbd2 100644
--- a/struct.c
+++ b/struct.c
@@ -593,6 +593,25 @@ rb_struct_hash(s)
}
static VALUE
+rb_struct_eql(s, s2)
+ VALUE s, 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 (RSTRUCT(s)->len != RSTRUCT(s2)->len) {
+ rb_bug("inconsistent struct"); /* should never happen */
+ }
+
+ for (i=0; i<RSTRUCT(s)->len; i++) {
+ if (!rb_eql(RSTRUCT(s)->ptr[i], RSTRUCT(s2)->ptr[i])) return Qfalse;
+ }
+ return Qtrue;
+}
+
+static VALUE
rb_struct_size(s)
VALUE s;
{
@@ -612,7 +631,7 @@ Init_Struct()
rb_define_method(rb_cStruct, "copy_object", rb_struct_copy_object, 1);
rb_define_method(rb_cStruct, "==", rb_struct_equal, 1);
- rb_define_method(rb_cStruct, "eql?", rb_struct_equal, 1);
+ rb_define_method(rb_cStruct, "eql?", rb_struct_eql, 1);
rb_define_method(rb_cStruct, "hash", rb_struct_hash, 0);
rb_define_method(rb_cStruct, "to_s", rb_struct_to_s, 0);