summaryrefslogtreecommitdiff
path: root/ext/dl/cptr.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-10 02:13:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-10 02:13:20 +0000
commit8812fe1a973e66130a560708b15a76bd2e08e5a7 (patch)
treeabc1774c2925fdb60c35b2f86c613c949d652120 /ext/dl/cptr.c
parent07b5520752bfe9217ff906189a32c878717a3917 (diff)
downloadruby-8812fe1a973e66130a560708b15a76bd2e08e5a7.tar.gz
* ext/dl/cfunc.c (rb_dlcfunc_instance_p): new function to check if
the argument is an instance of DL::CFunc. * ext/dl/cptr.c (rb_dlptr_initialize, rb_dlptr_s_malloc): checks if DL::CFunc. [ruby-dev:38403]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/cptr.c')
-rw-r--r--ext/dl/cptr.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/ext/dl/cptr.c b/ext/dl/cptr.c
index 4f1456d164..d2fa07771d 100644
--- a/ext/dl/cptr.c
+++ b/ext/dl/cptr.c
@@ -9,6 +9,18 @@
VALUE rb_cDLCPtr;
+static inline freefunc_t
+get_freefunc(VALUE func)
+{
+ if (NIL_P(func)) {
+ return NULL;
+ }
+ if (rb_dlcfunc_kind_p(func)) {
+ return RCFUNC_DATA(func)->ptr;
+ }
+ return NUM2PTR(rb_Integer(func));
+}
+
static ID id_to_ptr;
static void
@@ -124,7 +136,7 @@ rb_dlptr_initialize(int argc, VALUE argv[], VALUE self)
case 3:
p = (void*)(NUM2PTR(rb_Integer(ptr)));
s = NUM2LONG(size);
- f = NIL_P(sym) ? NULL : RCFUNC_DATA(sym)->ptr;
+ f = get_freefunc(sym);
break;
default:
rb_bug("rb_dlptr_initialize");
@@ -158,7 +170,7 @@ rb_dlptr_s_malloc(int argc, VALUE argv[], VALUE klass)
break;
case 2:
s = NUM2LONG(size);
- f = RCFUNC_DATA(sym)->ptr;
+ f = get_freefunc(sym);
break;
default:
rb_bug("rb_dlptr_s_malloc");
@@ -217,15 +229,9 @@ VALUE
rb_dlptr_free_set(VALUE self, VALUE val)
{
struct ptr_data *data;
- extern VALUE rb_cDLCFunc;
Data_Get_Struct(self, struct ptr_data, data);
- if( rb_obj_is_kind_of(val, rb_cDLCFunc) == Qtrue ){
- data->free = RCFUNC_DATA(val)->ptr;
- }
- else{
- data->free = NUM2PTR(rb_Integer(val));
- }
+ data->free = get_freefunc(val);
return Qnil;
}