aboutsummaryrefslogtreecommitdiffstats
path: root/ext/dl/handle.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-09 12:19:28 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-09 12:19:28 +0000
commitc754c0b23796be43fb7b4d8d4cc1d44af3ebd793 (patch)
tree3aebe1084ceb239f98dfe1c31dfbbc49d277bdf6 /ext/dl/handle.c
parent098d8d11e180e49493004685a46389bc91a75250 (diff)
downloadruby-c754c0b23796be43fb7b4d8d4cc1d44af3ebd793.tar.gz
* ext/dl/cfunc.c (dlcfunc_data_type): typed.
* ext/dl/cptr.c (dlptr_data_type): ditto. * ext/dl/handle.c (dlhandle_data_type): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/handle.c')
-rw-r--r--ext/dl/handle.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/ext/dl/handle.c b/ext/dl/handle.c
index 14a5299223..0db66c70b4 100644
--- a/ext/dl/handle.c
+++ b/ext/dl/handle.c
@@ -31,20 +31,32 @@ w32_dlclose(void *ptr)
#define dlclose(ptr) w32_dlclose(ptr)
#endif
-void
-dlhandle_free(struct dl_handle *dlhandle)
+static void
+dlhandle_free(void *ptr)
{
+ struct dl_handle *dlhandle = ptr;
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
dlclose(dlhandle->ptr);
}
}
+static size_t
+dlhandle_memsize(const void *ptr)
+{
+ return ptr ? sizeof(struct dl_handle) : 0;
+}
+
+static const rb_data_type_t dlhandle_data_type = {
+ "dl/handle",
+ 0, dlhandle_free, dlhandle_memsize,
+};
+
VALUE
rb_dlhandle_close(VALUE self)
{
struct dl_handle *dlhandle;
- Data_Get_Struct(self, struct dl_handle, dlhandle);
+ TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
dlhandle->open = 0;
return INT2NUM(dlclose(dlhandle->ptr));
}
@@ -55,8 +67,7 @@ rb_dlhandle_s_allocate(VALUE klass)
VALUE obj;
struct dl_handle *dlhandle;
- obj = Data_Make_Struct(rb_cDLHandle, struct dl_handle, 0,
- dlhandle_free, dlhandle);
+ obj = TypedData_Make_Struct(rb_cDLHandle, struct dl_handle, &dlhandle_data_type, dlhandle);
dlhandle->ptr = 0;
dlhandle->open = 0;
dlhandle->enable_close = 0;
@@ -133,7 +144,7 @@ rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
rb_raise(rb_eDLError, "%s", err);
}
#endif
- Data_Get_Struct(self, struct dl_handle, dlhandle);
+ TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
dlclose(dlhandle->ptr);
}
@@ -153,7 +164,7 @@ rb_dlhandle_enable_close(VALUE self)
{
struct dl_handle *dlhandle;
- Data_Get_Struct(self, struct dl_handle, dlhandle);
+ TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
dlhandle->enable_close = 1;
return Qnil;
}
@@ -163,7 +174,7 @@ rb_dlhandle_disable_close(VALUE self)
{
struct dl_handle *dlhandle;
- Data_Get_Struct(self, struct dl_handle, dlhandle);
+ TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
dlhandle->enable_close = 0;
return Qnil;
}
@@ -173,7 +184,7 @@ rb_dlhandle_to_i(VALUE self)
{
struct dl_handle *dlhandle;
- Data_Get_Struct(self, struct dl_handle, dlhandle);
+ TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
return PTR2NUM(dlhandle);
}
@@ -189,7 +200,7 @@ rb_dlhandle_sym(VALUE self, VALUE sym)
name = StringValuePtr(sym);
- Data_Get_Struct(self, struct dl_handle, dlhandle);
+ TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
if( ! dlhandle->open ){
rb_raise(rb_eDLError, "closed handle");
}