summaryrefslogtreecommitdiff
path: root/ext/dl/handle.c
diff options
context:
space:
mode:
authorttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-04 13:49:13 +0000
committerttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-04 13:49:13 +0000
commit45a08a4296b57df13190cb9065ee44974f44c7ce (patch)
tree29fe0a2bb1690ae0a205c790809ec1867714862a /ext/dl/handle.c
parent14859cdf948e6f9ebbb272867f9969fe95c91faa (diff)
Conform to the allocation framework.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/handle.c')
-rw-r--r--ext/dl/handle.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/ext/dl/handle.c b/ext/dl/handle.c
index 6debf5e0c5..0ba4397010 100644
--- a/ext/dl/handle.c
+++ b/ext/dl/handle.c
@@ -26,10 +26,24 @@ rb_dlhandle_close(VALUE self)
}
VALUE
-rb_dlhandle_s_new(int argc, VALUE argv[], VALUE self)
+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);
+ dlhandle->ptr = 0;
+ dlhandle->open = 0;
+ dlhandle->enable_close = 0;
+
+ return obj;
+}
+
+VALUE
+rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
{
void *ptr;
- VALUE val;
struct dl_handle *dlhandle;
VALUE lib, flag;
char *clib;
@@ -60,24 +74,15 @@ rb_dlhandle_s_new(int argc, VALUE argv[], VALUE self)
rb_raise(rb_eRuntimeError, err);
};
#endif
- val = Data_Make_Struct(rb_cDLHandle, struct dl_handle, 0,
- dlhandle_free, dlhandle);
+ Data_Get_Struct(self, struct dl_handle, dlhandle);
dlhandle->ptr = ptr;
dlhandle->open = 1;
dlhandle->enable_close = 0;
- rb_obj_call_init(val, argc, argv);
-
if( rb_block_given_p() ){
- rb_ensure(rb_yield, val, rb_dlhandle_close, val);
+ rb_ensure(rb_yield, self, rb_dlhandle_close, self);
};
- return val;
-}
-
-VALUE
-rb_dlhandle_init(int argc, VALUE argv[], VALUE self)
-{
return Qnil;
}
@@ -153,6 +158,9 @@ rb_dlhandle_sym(int argc, VALUE argv[], VALUE self)
Data_Get_Struct(self, struct dl_handle, dlhandle);
+ if( ! dlhandle->open ){
+ rb_raise(rb_eRuntimeError, "Closed handle.");
+ }
handle = dlhandle->ptr;
func = dlsym(handle, name);
@@ -192,9 +200,9 @@ rb_dlhandle_sym(int argc, VALUE argv[], VALUE self)
void
Init_dlhandle()
{
- rb_cDLHandle = rb_define_class_under(rb_mDL, "Handle", rb_cData);
- rb_define_singleton_method(rb_cDLHandle, "new", rb_dlhandle_s_new, -1);
- rb_define_method(rb_cDLHandle, "initialize", rb_dlhandle_init, -1);
+ rb_cDLHandle = rb_define_class_under(rb_mDL, "Handle", rb_cObject);
+ rb_define_singleton_method(rb_cDLHandle, "allocate", rb_dlhandle_s_allocate, 0);
+ rb_define_method(rb_cDLHandle, "initialize", rb_dlhandle_initialize, -1);
rb_define_method(rb_cDLHandle, "to_i", rb_dlhandle_to_i, 0);
rb_define_method(rb_cDLHandle, "to_ptr", rb_dlhandle_to_ptr, 0);
rb_define_method(rb_cDLHandle, "close", rb_dlhandle_close, 0);