summaryrefslogtreecommitdiff
path: root/compar.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-09-16 09:40:33 (GMT)
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-09-16 09:40:33 (GMT)
commit9e3d9a2a009d2a0281802a84e1c5cc1c887edc71 (patch)
treeea994af7deeef43977f60a9ab26131e8cd90a9a0 /compar.c
parent69a3aaf154948d653fa3653cd2b3c3b3af979769 (diff)
1.4.1
git-svn-id: svn+ssh://ci.ruby-lang.org/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 50e4fa3..677b6a3 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);