From 21d0b0785c4be76fac8c421af009aa57fbbb85f5 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 16 Sep 1999 09:40:33 +0000 Subject: 1.4.1 git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- compar.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'compar.c') diff --git a/compar.c b/compar.c index 50e4fa3a8..677b6a3cb 100644 --- a/compar.c +++ b/compar.c @@ -17,16 +17,34 @@ 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; return Qfalse; } +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); -- cgit