summaryrefslogtreecommitdiffstats
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
commitd85c44a7eaeb52d6903431efef004e2b3605a94f (patch)
tree79823d81475a9659b3c0e21988721c7d6b200d04 /struct.c
parent6423b6642048a20f4660340efefa67baec4ec1c9 (diff)
downloadruby-d85c44a7eaeb52d6903431efef004e2b3605a94f.tar.gz
ruby-d85c44a7eaeb52d6903431efef004e2b3605a94f.tar.xz
ruby-d85c44a7eaeb52d6903431efef004e2b3605a94f.zip
* 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: http://svn.ruby-lang.org/repos/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 d695b15ca..b1fa31fbd 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);