summaryrefslogtreecommitdiffstats
path: root/compar.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-09-16 09:40:33 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-09-16 09:40:33 +0000
commit21d0b0785c4be76fac8c421af009aa57fbbb85f5 (patch)
treeea994af7deeef43977f60a9ab26131e8cd90a9a0 /compar.c
parent1f72ff9b643dff5f4c5a40bf672a2525d66bd99f (diff)
downloadruby-21d0b0785c4be76fac8c421af009aa57fbbb85f5.tar.gz
ruby-21d0b0785c4be76fac8c421af009aa57fbbb85f5.tar.xz
ruby-21d0b0785c4be76fac8c421af009aa57fbbb85f5.zip
1.4.1
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compar.c')
-rw-r--r--compar.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/compar.c b/compar.c
index 50e4fa3a8..677b6a3cb 100644
--- a/compar.c
+++ b/compar.c
@@ -17,10 +17,10 @@ VALUE rb_mComparable;
static ID cmp;
static VALUE
-cmp_eq(x, y)
- VALUE x, y;
+cmp_eq(a)
+ VALUE *a;
{
- VALUE c = rb_funcall(x, cmp, 1, y);
+ VALUE c = rb_funcall(a[0], cmp, 1, a[1]);
int t = NUM2INT(c);
if (t == 0) return Qtrue;
@@ -28,6 +28,24 @@ cmp_eq(x, y)
}
static VALUE
+cmp_failed()
+{
+ return Qfalse;
+}
+
+static VALUE
+cmp_equal(x, y)
+ VALUE x, y;
+{
+ VALUE a[2];
+
+ if (x == y) return Qtrue;
+
+ a[0] = x; a[1] = y;
+ return rb_rescue(cmp_eq, (VALUE)a, cmp_failed, 0);
+}
+
+static VALUE
cmp_gt(x, y)
VALUE x, y;
{
@@ -89,7 +107,7 @@ void
Init_Comparable()
{
rb_mComparable = rb_define_module("Comparable");
- rb_define_method(rb_mComparable, "==", cmp_eq, 1);
+ rb_define_method(rb_mComparable, "==", cmp_equal, 1);
rb_define_method(rb_mComparable, ">", cmp_gt, 1);
rb_define_method(rb_mComparable, ">=", cmp_ge, 1);
rb_define_method(rb_mComparable, "<", cmp_lt, 1);