From 1578edbafc8d641a1829cb1949318aa754fc5485 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Sun, 25 Oct 2009 00:11:41 +0000 Subject: * ext/dl/handle.c (rb_dlhandle_close_enabled_p) testing that handles can be enabled and disabled for closure on GC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dl/handle.c | 28 ++++++++++++++++++++++++++++ test/dl/test_handle.rb | 17 +++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/ext/dl/handle.c b/ext/dl/handle.c index 6c2ef37b3d..28be36c099 100644 --- a/ext/dl/handle.c +++ b/ext/dl/handle.c @@ -181,6 +181,11 @@ rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self) return Qnil; } +/* + * call-seq: enable_close + * + * Enable a call to dlclose() when this DL::Handle is garbage collected. + */ VALUE rb_dlhandle_enable_close(VALUE self) { @@ -191,6 +196,11 @@ rb_dlhandle_enable_close(VALUE self) return Qnil; } +/* + * call-seq: disable_close + * + * Disable a call to dlclose() when this DL::Handle is garbage collected. + */ VALUE rb_dlhandle_disable_close(VALUE self) { @@ -201,6 +211,23 @@ rb_dlhandle_disable_close(VALUE self) return Qnil; } +/* + * call-seq: close_enabled? + * + * Returns +true+ if dlclose() will be called when this DL::Handle is + * garbage collected. + */ +static VALUE +rb_dlhandle_close_enabled_p(VALUE self) +{ + struct dl_handle *dlhandle; + + TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle); + + if(dlhandle->enable_close) return Qtrue; + return Qfalse; +} + /* * call-seq: to_i * @@ -338,6 +365,7 @@ Init_dlhandle(void) rb_define_method(rb_cDLHandle, "[]", rb_dlhandle_sym, 1); rb_define_method(rb_cDLHandle, "disable_close", rb_dlhandle_disable_close, 0); rb_define_method(rb_cDLHandle, "enable_close", rb_dlhandle_enable_close, 0); + rb_define_method(rb_cDLHandle, "close_enabled?", rb_dlhandle_close_enabled_p, 0); } /* mode: c; tab-with=8; sw=8; ts=8; noexpandtab: */ diff --git a/test/dl/test_handle.rb b/test/dl/test_handle.rb index a8dcf1952b..487b8d1a34 100644 --- a/test/dl/test_handle.rb +++ b/test/dl/test_handle.rb @@ -105,5 +105,22 @@ module DL handle = DL::Handle.new(LIBC_SO, DL::RTLD_LAZY | DL::RTLD_GLOBAL) assert handle['calloc'] end + + def test_enable_close + handle = DL::Handle.new(LIBC_SO) + assert !handle.close_enabled?, 'close is enabled' + + handle.enable_close + assert handle.close_enabled?, 'close is not enabled' + end + + def test_disable_close + handle = DL::Handle.new(LIBC_SO) + + handle.enable_close + assert handle.close_enabled?, 'close is enabled' + handle.disable_close + assert !handle.close_enabled?, 'close is enabled' + end end end -- cgit v1.2.3