1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-05-23 12:49:00 +00:00
parent 96e6cfb835
commit 34cf45ab19
2 changed files with 54 additions and 10 deletions

View file

@ -1,3 +1,11 @@
Sat May 23 21:48:58 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* ext/dl/lib/dl/cparser.rb (DL::CParser#parse_struct_signature):

View file

@ -64,6 +64,18 @@ rb_dlhandle_s_allocate(VALUE klass)
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 @@ rb_dlhandle_to_i(VALUE self)
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 @@ rb_dlhandle_sym(VALUE self, VALUE sym)
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 @@ Init_dlhandle(void)
{
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);