aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ext/dl/handle.c28
-rw-r--r--test/dl/test_handle.rb17
2 files changed, 45 insertions, 0 deletions
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)
{
@@ -202,6 +212,23 @@ rb_dlhandle_disable_close(VALUE self)
}
/*
+ * 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 @@ 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