Get the address as an Integer for the function named name.
VALUE
rb_dlhandle_s_sym(VALUE self, VALUE sym)
{
return dlhandle_sym(RTLD_NEXT, StringValueCStr(sym));
}
Create a new handler that opens library named lib with flags. If no library is specified, RTLD_DEFAULT is used.
VALUE
rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
{
void *ptr;
struct dl_handle *dlhandle;
VALUE lib, flag;
char *clib;
int cflag;
const char *err;
switch( rb_scan_args(argc, argv, "02", &lib, &flag) ){
case 0:
clib = NULL;
cflag = RTLD_LAZY | RTLD_GLOBAL;
break;
case 1:
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
cflag = RTLD_LAZY | RTLD_GLOBAL;
break;
case 2:
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
cflag = NUM2INT(flag);
break;
default:
rb_bug("rb_dlhandle_new");
}
rb_secure(2);
#if defined(_WIN32)
if( !clib ){
HANDLE rb_libruby_handle(void);
ptr = rb_libruby_handle();
}
else if( STRCASECMP(clib, "libc") == 0
# ifdef RUBY_COREDLL
|| STRCASECMP(clib, RUBY_COREDLL) == 0
|| STRCASECMP(clib, RUBY_COREDLL".dll") == 0
# endif
){
# ifdef _WIN32_WCE
ptr = dlopen("coredll.dll", cflag);
# else
ptr = w32_coredll();
# endif
}
else
#endif
ptr = dlopen(clib, cflag);
#if defined(HAVE_DLERROR)
if( !ptr && (err = dlerror()) ){
rb_raise(rb_eDLError, "%s", err);
}
#else
if( !ptr ){
err = dlerror();
rb_raise(rb_eDLError, "%s", err);
}
#endif
TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
dlclose(dlhandle->ptr);
}
dlhandle->ptr = ptr;
dlhandle->open = 1;
dlhandle->enable_close = 0;
if( rb_block_given_p() ){
rb_ensure(rb_yield, self, rb_dlhandle_close, self);
}
return Qnil;
}
Get the address as an Integer for the function named name.
VALUE
rb_dlhandle_sym(VALUE self, VALUE sym)
{
struct dl_handle *dlhandle;
TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
if( ! dlhandle->open ){
rb_raise(rb_eDLError, "closed handle");
}
return dlhandle_sym(dlhandle->ptr, StringValueCStr(sym));
}
Close this DL::Handle. Calling close more than once will raise a DL::DLError exception.
VALUE
rb_dlhandle_close(VALUE self)
{
struct dl_handle *dlhandle;
TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
if(dlhandle->open) {
int ret = dlclose(dlhandle->ptr);
dlhandle->open = 0;
/* Check dlclose for successful return value */
if(ret) {
#if defined(HAVE_DLERROR)
rb_raise(rb_eDLError, "%s", dlerror());
#else
rb_raise(rb_eDLError, "could not close handle");
#endif
}
return INT2NUM(ret);
}
rb_raise(rb_eDLError, "dlclose() called too many times");
}
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;
}
Disable a call to dlclose() when this DL::Handle is garbage collected.
VALUE
rb_dlhandle_disable_close(VALUE self)
{
struct dl_handle *dlhandle;
TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
dlhandle->enable_close = 0;
return Qnil;
}
Enable a call to dlclose() when this DL::Handle is garbage collected.
VALUE
rb_dlhandle_enable_close(VALUE self)
{
struct dl_handle *dlhandle;
TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
dlhandle->enable_close = 1;
return Qnil;
}
Document-method: []
Get the address as an Integer for the function named name.
VALUE
rb_dlhandle_sym(VALUE self, VALUE sym)
{
struct dl_handle *dlhandle;
TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
if( ! dlhandle->open ){
rb_raise(rb_eDLError, "closed handle");
}
return dlhandle_sym(dlhandle->ptr, StringValueCStr(sym));
}