Bug #1267 ยป dlhandle.diff
ext/dl/handle.c (working copy) | ||
---|---|---|
}
|
||
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);
|
||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||
if( ! dlhandle->open ){
|
||
rb_raise(rb_eDLError, "closed handle");
|
||
}
|
||
return dlhandle_sym(dlhandle->ptr, StringValuePtr(sym));
|
||
}
|
||
if( sym == Qnil ){
|
||
#if defined(RTLD_NEXT)
|
||
name = RTLD_NEXT;
|
||
VALUE
|
||
rb_dlhandle_s_sym(VALUE self, VALUE sym)
|
||
{
|
||
#ifdef RTLD_NEXT
|
||
void *handle = RTLD_NEXT;
|
||
#else
|
||
name = NULL;
|
||
void *handle = NULL;
|
||
#endif
|
||
}
|
||
else{
|
||
name = StringValuePtr(sym);
|
||
}
|
||
rb_secure(2);
|
||
return dlhandle_sym(handle, StringValuePtr(sym));
|
||
}
|
||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||
if( ! dlhandle->open ){
|
||
rb_raise(rb_eDLError, "closed handle");
|
||
}
|
||
handle = dlhandle->ptr;
|
||
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);
|
||
func = dlsym(handle, name);
|
||
CHECK_DLERROR;
|
||
#if defined(FUNC_STDCALL)
|
||
... | ... | |
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_method(rb_cDLHandle, "initialize", rb_dlhandle_initialize, -1);
|
||
rb_define_method(rb_cDLHandle, "to_i", rb_dlhandle_to_i, 0);
|