ruby-changes:13677
From: tenderlove <ko1@a...>
Date: Sun, 25 Oct 2009 09:11:53 +0900 (JST)
Subject: [ruby-changes:13677] Ruby:r25462 (trunk): * ext/dl/handle.c (rb_dlhandle_close_enabled_p) testing that handles can
tenderlove 2009-10-25 09:11:41 +0900 (Sun, 25 Oct 2009) New Revision: 25462 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25462 Log: * ext/dl/handle.c (rb_dlhandle_close_enabled_p) testing that handles can be enabled and disabled for closure on GC. Modified files: trunk/ext/dl/handle.c trunk/test/dl/test_handle.rb Index: ext/dl/handle.c =================================================================== --- ext/dl/handle.c (revision 25461) +++ ext/dl/handle.c (revision 25462) @@ -181,6 +181,11 @@ 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 @@ 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) { @@ -202,6 +212,23 @@ } /* + * 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 * * Returns the memory address for this handle. @@ -338,6 +365,7 @@ 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: */ Index: test/dl/test_handle.rb =================================================================== --- test/dl/test_handle.rb (revision 25461) +++ test/dl/test_handle.rb (revision 25462) @@ -105,5 +105,22 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/