summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--ext/dl/cfunc.c10
-rw-r--r--ext/dl/cptr.c24
-rw-r--r--ext/dl/dl.h1
4 files changed, 32 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index dc15391614d..7eabd9ea3e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
-Sun May 10 10:40:02 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun May 10 11:13:19 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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].
* ext/dl/lib/dl/cparser.rb (DL::CParser#parse_signature): strips
spaces. based on a patch from Takashi Tamura in [ruby-dev:38398].
diff --git a/ext/dl/cfunc.c b/ext/dl/cfunc.c
index 20d3f537669..6110e14f557 100644
--- a/ext/dl/cfunc.c
+++ b/ext/dl/cfunc.c
@@ -43,8 +43,9 @@ rb_dl_set_win32_last_error(VALUE self, VALUE val)
void
-dlcfunc_free(struct cfunc_data *data)
+dlcfunc_free(void *ptr)
{
+ struct cfunc_data *data = ptr;
if( data->name ){
xfree(data->name);
}
@@ -107,6 +108,13 @@ rb_dlcfunc_s_allocate(VALUE klass)
return obj;
}
+int
+rb_dlcfunc_kind_p(VALUE func)
+{
+ if (TYPE(func) == T_DATA) return 0;
+ return RDATA(func)->dfree == dlcfunc_free;
+}
+
VALUE
rb_dlcfunc_initialize(int argc, VALUE argv[], VALUE self)
{
diff --git a/ext/dl/cptr.c b/ext/dl/cptr.c
index 4f1456d1647..d2fa07771dd 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;
}
diff --git a/ext/dl/dl.h b/ext/dl/dl.h
index d47a3aa729d..d06cad4e6b6 100644
--- a/ext/dl/dl.h
+++ b/ext/dl/dl.h
@@ -216,6 +216,7 @@ struct ptr_data {
#define RPTR_DATA(obj) ((struct ptr_data *)(DATA_PTR(obj)))
VALUE rb_dlcfunc_new(void (*func)(), int dltype, const char * name, ID calltype);
+int rb_dlcfunc_kind_p(VALUE func);
VALUE rb_dlptr_new(void *ptr, long size, freefunc_t func);
VALUE rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func);
VALUE rb_dlptr_malloc(long size, freefunc_t func);