[前][次][番号順一覧][スレッド一覧]

ruby-changes:11891

From: nobu <ko1@a...>
Date: Sat, 23 May 2009 21:49:18 +0900 (JST)
Subject: [ruby-changes:11891] Ruby:r23551 (trunk): * ext/dl/handle.c (rb_dlhandle_s_sym): added a method to access

nobu	2009-05-23 21:49:00 +0900 (Sat, 23 May 2009)

  New Revision: 23551

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23551

  Log:
    * ext/dl/handle.c (rb_dlhandle_s_sym): added a method to access
      using RTLD_NEXT.  [ruby-dev:38152]
    * ext/dl/handle.c (Init_dlhandle): added constants DEFAULT and
      NEXT which correspond to RTLD_DEFAULT and RTLD_NEXT.

  Modified files:
    trunk/ChangeLog
    trunk/ext/dl/handle.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23550)
+++ ChangeLog	(revision 23551)
@@ -1,3 +1,11 @@
+Sat May 23 21:48:58 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/dl/handle.c (rb_dlhandle_s_sym): added a method to access
+	  using RTLD_NEXT.  [ruby-dev:38152]
+
+	* ext/dl/handle.c (Init_dlhandle): added constants DEFAULT and
+	  NEXT which correspond to RTLD_DEFAULT and RTLD_NEXT.
+
 Sat May 23 18:53:13 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/dl/lib/dl/cparser.rb (DL::CParser#parse_struct_signature):
Index: ext/dl/handle.c
===================================================================
--- ext/dl/handle.c	(revision 23550)
+++ ext/dl/handle.c	(revision 23551)
@@ -64,6 +64,18 @@
     return obj;
 }
 
+static VALUE
+predefined_dlhandle(void *handle)
+{
+    VALUE obj = rb_dlhandle_s_allocate(rb_cDLHandle);
+    struct dl_handle *dlhandle = DATA_PTR(obj);
+
+    dlhandle->ptr = handle;
+    dlhandle->open = 1;
+    OBJ_FREEZE(obj);
+    return obj;
+}
+
 VALUE
 rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
 {
@@ -165,19 +177,13 @@
     return PTR2NUM(dlhandle);
 }
 
+static VALUE dlhandle_sym(void *handle, const char *symbol);
+
 VALUE
 rb_dlhandle_sym(VALUE self, VALUE sym)
 {
-    void (*func)();
     struct dl_handle *dlhandle;
-    void *handle;
     const char *name;
-#if defined(HAVE_DLERROR)
-    const char *err;
-# define CHECK_DLERROR if( err = dlerror() ){ func = 0; }
-#else
-# define CHECK_DLERROR
-#endif
 
     rb_secure(2);
 
@@ -187,9 +193,35 @@
     if( ! dlhandle->open ){
 	rb_raise(rb_eDLError, "closed handle");
     }
-    handle = dlhandle->ptr;
 
-    func = dlsym(handle, name);
+    return dlhandle_sym(dlhandle->ptr, StringValueCStr(sym));
+}
+
+#ifndef RTLD_NEXT
+#define RTLD_NEXT NULL
+#endif
+#ifndef RTLD_DEFAULT
+#define RTLD_DEFAULT NULL
+#endif
+
+VALUE
+rb_dlhandle_s_sym(VALUE self, VALUE sym)
+{
+    rb_secure(2);
+    return dlhandle_sym(RTLD_NEXT, StringValueCStr(sym));
+}
+
+static VALUE
+dlhandle_sym(void *handle, const char *name)
+{
+#if defined(HAVE_DLERROR)
+    const char *err;
+# define CHECK_DLERROR if( err = dlerror() ){ func = 0; }
+#else
+# define CHECK_DLERROR
+#endif
+    void (*func)() = dlsym(handle, name);
+
     CHECK_DLERROR;
 #if defined(FUNC_STDCALL)
     if( !func ){
@@ -244,6 +276,10 @@
 {
     rb_cDLHandle = rb_define_class_under(rb_mDL, "Handle", rb_cObject);
     rb_define_alloc_func(rb_cDLHandle, rb_dlhandle_s_allocate);
+    rb_define_singleton_method(rb_cDLHandle, "sym", rb_dlhandle_s_sym, 1);
+    rb_define_singleton_method(rb_cDLHandle, "[]", rb_dlhandle_s_sym,  1);
+    rb_define_const(rb_cDLHandle, "NEXT", predefined_dlhandle(RTLD_NEXT));
+    rb_define_const(rb_cDLHandle, "DEFAULT", predefined_dlhandle(RTLD_DEFAULT));
     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, "close", rb_dlhandle_close, 0);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]