summaryrefslogtreecommitdiff
path: root/ext/dl/cptr.c
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-03 17:12:46 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-03 17:12:46 +0000
commitc30e32d075478c62580c7d3f5699c2c477503b41 (patch)
tree4defc2cf5c47e8b7aa9b0e2247e709ea43733bd7 /ext/dl/cptr.c
parent89f1c60cba94d286e8a72b0f278ab5903ad6031c (diff)
* ext/dl/cptr.c (rb_dlptr_eql, rb_dlptr_cmp): DL::CPtr#== and DL::CPtr#<=>
should not raise an exception when compared to a different object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/cptr.c')
-rw-r--r--ext/dl/cptr.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/ext/dl/cptr.c b/ext/dl/cptr.c
index 466905f69b..94632e8240 100644
--- a/ext/dl/cptr.c
+++ b/ext/dl/cptr.c
@@ -333,21 +333,42 @@ rb_dlptr_inspect(VALUE self)
return rb_str_new2(str);
}
+/*
+ * call-seq:
+ * ptr == other => true or false
+ * ptr.eql?(other) => true or false
+ *
+ * Returns true if +other+ wraps the same pointer, otherwise returns
+ * false.
+ */
VALUE
rb_dlptr_eql(VALUE self, VALUE other)
{
void *ptr1, *ptr2;
+
+ if(!rb_obj_is_kind_of(other, rb_cDLCPtr)) return Qfalse;
+
ptr1 = rb_dlptr2cptr(self);
ptr2 = rb_dlptr2cptr(other);
return ptr1 == ptr2 ? Qtrue : Qfalse;
}
-VALUE
+/*
+ * call-seq:
+ * ptr <=> other => -1, 0, 1, or nil
+ *
+ * Returns -1 if less than, 0 if equal to, 1 if greater than +other+. Returns
+ * nil if +ptr+ cannot be compared to +other+.
+ */
+static VALUE
rb_dlptr_cmp(VALUE self, VALUE other)
{
void *ptr1, *ptr2;
SIGNED_VALUE diff;
+
+ if(!rb_obj_is_kind_of(other, rb_cDLCPtr)) return Qnil;
+
ptr1 = rb_dlptr2cptr(self);
ptr2 = rb_dlptr2cptr(other);
diff = (SIGNED_VALUE)ptr1 - (SIGNED_VALUE)ptr2;