aboutsummaryrefslogtreecommitdiffstats
path: root/ext/dl/cptr.c
diff options
context:
space:
mode:
authorttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-02-06 06:54:12 +0000
committerttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-02-06 06:54:12 +0000
commit93711e5bd35203e6622f89fe72b38b13478b9313 (patch)
tree165dde56bed8257b9f3028135dc50b438f8d5060 /ext/dl/cptr.c
parentb393a2bc5fe07abef59656a6358f7ee7113bbe8b (diff)
downloadruby-93711e5bd35203e6622f89fe72b38b13478b9313.tar.gz
added DL::Importer.sizeof().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/cptr.c')
-rw-r--r--ext/dl/cptr.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ext/dl/cptr.c b/ext/dl/cptr.c
index 27be637a5a..88897ccc86 100644
--- a/ext/dl/cptr.c
+++ b/ext/dl/cptr.c
@@ -10,6 +10,8 @@
VALUE rb_cDLCPtr;
+static ID id_to_ptr;
+
static void
dlptr_free(struct ptr_data *data)
{
@@ -422,6 +424,15 @@ rb_dlptr_s_to_ptr(VALUE self, VALUE val)
#endif
return rb_dlptr_new(fp, sizeof(FILE), NULL);
}
+ else if( rb_respond_to(val, id_to_ptr) ){
+ VALUE vptr = rb_funcall(val, id_to_ptr, 0);
+ if( rb_obj_is_kind_of(vptr, rb_cDLCPtr) ){
+ return vptr;
+ }
+ else{
+ rb_raise(rb_eDLError, "to_ptr should return a CPtr object.");
+ }
+ }
else{
return rb_dlptr_new(NUM2PTR(rb_Integer(val)), 0, NULL);
}
@@ -430,6 +441,8 @@ rb_dlptr_s_to_ptr(VALUE self, VALUE val)
void
Init_dlptr()
{
+ id_to_ptr = rb_intern("to_ptr");
+
rb_cDLCPtr = rb_define_class_under(rb_mDL, "CPtr", rb_cObject);
rb_define_alloc_func(rb_cDLCPtr, rb_dlptr_s_allocate);
rb_define_singleton_method(rb_cDLCPtr, "malloc", rb_dlptr_s_malloc, -1);