* struct.c (rb_struct_equal, rb_struct_eql): Handle comparison of recursive structures [ruby-core:24759]
* range.c (range_eq, range_eql): ditto for ranges git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25010 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8892dd7257
commit
0ebfc1348b
@ -1,3 +1,10 @@
|
|||||||
|
Sun Sep 20 11:11:34 2009 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
|
* struct.c (rb_struct_equal, rb_struct_eql): Handle comparison of
|
||||||
|
recursive structures [ruby-core:24759]
|
||||||
|
|
||||||
|
* range.c (range_eq, range_eql): ditto for ranges
|
||||||
|
|
||||||
Sat Sep 19 17:46:46 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Sep 19 17:46:46 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* vm_core.h (ENABLE_VM_OBJSPACE): socklist needs st_table in
|
* vm_core.h (ENABLE_VM_OBJSPACE): socklist needs st_table in
|
||||||
|
49
range.c
49
range.c
@ -105,6 +105,20 @@ range_exclude_end_p(VALUE range)
|
|||||||
return EXCL(range) ? Qtrue : Qfalse;
|
return EXCL(range) ? Qtrue : Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
recursive_equal(VALUE range, VALUE obj, int recur)
|
||||||
|
{
|
||||||
|
if (recur) return Qtrue; /* Subtle! */
|
||||||
|
if (!rb_equal(RANGE_BEG(range), RANGE_BEG(obj)))
|
||||||
|
return Qfalse;
|
||||||
|
if (!rb_equal(RANGE_END(range), RANGE_END(obj)))
|
||||||
|
return Qfalse;
|
||||||
|
|
||||||
|
if (EXCL(range) != EXCL(obj))
|
||||||
|
return Qfalse;
|
||||||
|
return Qtrue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
@ -128,15 +142,7 @@ range_eq(VALUE range, VALUE obj)
|
|||||||
if (!rb_obj_is_kind_of(obj, rb_cRange))
|
if (!rb_obj_is_kind_of(obj, rb_cRange))
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
|
|
||||||
if (!rb_equal(RANGE_BEG(range), RANGE_BEG(obj)))
|
return rb_exec_recursive_paired(recursive_equal, range, obj, obj);
|
||||||
return Qfalse;
|
|
||||||
if (!rb_equal(RANGE_END(range), RANGE_END(obj)))
|
|
||||||
return Qfalse;
|
|
||||||
|
|
||||||
if (EXCL(range) != EXCL(obj))
|
|
||||||
return Qfalse;
|
|
||||||
|
|
||||||
return Qtrue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -168,6 +174,20 @@ r_le(VALUE a, VALUE b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
recursive_eql(VALUE range, VALUE obj, int recur)
|
||||||
|
{
|
||||||
|
if (recur) return Qtrue; /* Subtle! */
|
||||||
|
if (!rb_eql(RANGE_BEG(range), RANGE_BEG(obj)))
|
||||||
|
return Qfalse;
|
||||||
|
if (!rb_eql(RANGE_END(range), RANGE_END(obj)))
|
||||||
|
return Qfalse;
|
||||||
|
|
||||||
|
if (EXCL(range) != EXCL(obj))
|
||||||
|
return Qfalse;
|
||||||
|
return Qtrue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* rng.eql?(obj) => true or false
|
* rng.eql?(obj) => true or false
|
||||||
@ -189,16 +209,7 @@ range_eql(VALUE range, VALUE obj)
|
|||||||
return Qtrue;
|
return Qtrue;
|
||||||
if (!rb_obj_is_kind_of(obj, rb_cRange))
|
if (!rb_obj_is_kind_of(obj, rb_cRange))
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
|
return rb_exec_recursive_paired(recursive_eql, range, obj, obj);
|
||||||
if (!rb_eql(RANGE_BEG(range), RANGE_BEG(obj)))
|
|
||||||
return Qfalse;
|
|
||||||
if (!rb_eql(RANGE_END(range), RANGE_END(obj)))
|
|
||||||
return Qfalse;
|
|
||||||
|
|
||||||
if (EXCL(range) != EXCL(obj))
|
|
||||||
return Qfalse;
|
|
||||||
|
|
||||||
return Qtrue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
38
struct.c
38
struct.c
@ -768,6 +768,18 @@ rb_struct_select(int argc, VALUE *argv, VALUE s)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
recursive_equal(VALUE s, VALUE s2, int recur)
|
||||||
|
{
|
||||||
|
long i;
|
||||||
|
|
||||||
|
if (recur) return Qtrue; /* Subtle! */
|
||||||
|
for (i=0; i<RSTRUCT_LEN(s); i++) {
|
||||||
|
if (!rb_equal(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse;
|
||||||
|
}
|
||||||
|
return Qtrue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* struct == other_struct => true or false
|
* struct == other_struct => true or false
|
||||||
@ -788,8 +800,6 @@ rb_struct_select(int argc, VALUE *argv, VALUE s)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_struct_equal(VALUE s, VALUE s2)
|
rb_struct_equal(VALUE s, VALUE s2)
|
||||||
{
|
{
|
||||||
long i;
|
|
||||||
|
|
||||||
if (s == s2) return Qtrue;
|
if (s == s2) return Qtrue;
|
||||||
if (TYPE(s2) != T_STRUCT) return Qfalse;
|
if (TYPE(s2) != T_STRUCT) return Qfalse;
|
||||||
if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
|
if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
|
||||||
@ -797,10 +807,7 @@ rb_struct_equal(VALUE s, VALUE s2)
|
|||||||
rb_bug("inconsistent struct"); /* should never happen */
|
rb_bug("inconsistent struct"); /* should never happen */
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<RSTRUCT_LEN(s); i++) {
|
return rb_exec_recursive_paired(recursive_equal, s, s2, s2);
|
||||||
if (!rb_equal(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse;
|
|
||||||
}
|
|
||||||
return Qtrue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -834,6 +841,18 @@ rb_struct_hash(VALUE s)
|
|||||||
return rb_exec_recursive_outer(recursive_hash, s, 0);
|
return rb_exec_recursive_outer(recursive_hash, s, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
recursive_eql(VALUE s, VALUE s2, int recur)
|
||||||
|
{
|
||||||
|
long i;
|
||||||
|
|
||||||
|
if (recur) return Qtrue; /* Subtle! */
|
||||||
|
for (i=0; i<RSTRUCT_LEN(s); i++) {
|
||||||
|
if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse;
|
||||||
|
}
|
||||||
|
return Qtrue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* code-seq:
|
* code-seq:
|
||||||
* struct.eql?(other) => true or false
|
* struct.eql?(other) => true or false
|
||||||
@ -845,8 +864,6 @@ rb_struct_hash(VALUE s)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_struct_eql(VALUE s, VALUE s2)
|
rb_struct_eql(VALUE s, VALUE s2)
|
||||||
{
|
{
|
||||||
long i;
|
|
||||||
|
|
||||||
if (s == s2) return Qtrue;
|
if (s == s2) return Qtrue;
|
||||||
if (TYPE(s2) != T_STRUCT) return Qfalse;
|
if (TYPE(s2) != T_STRUCT) return Qfalse;
|
||||||
if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
|
if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
|
||||||
@ -854,10 +871,7 @@ rb_struct_eql(VALUE s, VALUE s2)
|
|||||||
rb_bug("inconsistent struct"); /* should never happen */
|
rb_bug("inconsistent struct"); /* should never happen */
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<RSTRUCT_LEN(s); i++) {
|
return rb_exec_recursive_paired(recursive_eql, s, s2, s2);
|
||||||
if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse;
|
|
||||||
}
|
|
||||||
return Qtrue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user