4 #define SafeStringValueCStr(v) (rb_check_safe_obj(rb_string_value(&v)), StringValueCStr(v)) 19 MEMORY_BASIC_INFORMATION m;
20 memset(&m, 0,
sizeof(m));
21 if( !VirtualQuery(_errno, &m,
sizeof(m)) )
return NULL;
22 return m.AllocationBase;
27 w32_dlclose(
void *
ptr)
30 if( ptr == w32_coredll() )
return 0;
32 if( FreeLibrary((HMODULE)ptr) )
return 0;
35 #define dlclose(ptr) w32_dlclose(ptr) 39 fiddle_handle_free(
void *
ptr)
43 dlclose(fiddle_handle->
ptr);
49 fiddle_handle_memsize(
const void *
ptr)
56 {0, fiddle_handle_free, fiddle_handle_memsize,},
67 rb_fiddle_handle_close(
VALUE self)
72 if(fiddle_handle->
open) {
73 int ret = dlclose(fiddle_handle->
ptr);
74 fiddle_handle->
open = 0;
78 #if defined(HAVE_DLERROR) 92 rb_fiddle_handle_s_allocate(
VALUE klass)
98 fiddle_handle->
ptr = 0;
99 fiddle_handle->
open = 0;
106 predefined_fiddle_handle(
void *handle)
111 fiddle_handle->
ptr = handle;
112 fiddle_handle->
open = 1;
145 cflag = RTLD_LAZY | RTLD_GLOBAL;
149 cflag = RTLD_LAZY | RTLD_GLOBAL;
156 rb_bug(
"rb_fiddle_handle_new");
161 HANDLE rb_libruby_handle(
void);
162 ptr = rb_libruby_handle();
171 ptr = dlopen(
"coredll.dll", cflag);
179 ptr = dlopen(clib, cflag);
180 #if defined(HAVE_DLERROR) 181 if( !ptr && (err = dlerror()) ){
192 dlclose(fiddle_handle->
ptr);
195 fiddle_handle->
open = 1;
211 rb_fiddle_handle_enable_close(
VALUE self)
226 rb_fiddle_handle_disable_close(
VALUE self)
243 rb_fiddle_handle_close_enabled_p(
VALUE self)
259 rb_fiddle_handle_to_i(
VALUE self)
267 static VALUE fiddle_handle_sym(
void *handle,
VALUE symbol);
282 if( ! fiddle_handle->
open ){
286 return fiddle_handle_sym(fiddle_handle->
ptr, sym);
290 #define RTLD_NEXT NULL 293 #define RTLD_DEFAULT NULL 309 return fiddle_handle_sym(
RTLD_NEXT, sym);
313 fiddle_handle_sym(
void *handle,
VALUE symbol)
315 #if defined(HAVE_DLERROR) 317 # define CHECK_DLERROR if ((err = dlerror()) != 0) { func = 0; } 319 # define CHECK_DLERROR 327 func = (void (*)())(
VALUE)dlsym(handle, name);
329 #if defined(FUNC_STDCALL) 334 #if defined(__CYGWIN__) || defined(_WIN32) || defined(__MINGW32__) 336 char *name_a = (
char*)
xmalloc(len+2);
337 strcpy(name_a, name);
340 name_a[len+1] =
'\0';
341 func = dlsym(handle, name_a);
343 if( func )
goto found;
347 name_n = (
char*)
xmalloc(len+6);
349 memcpy(name_n, name, len);
351 for( i = 0; i < 256; i += 4 ){
352 sprintf(name_n + len,
"%d", i);
353 func = dlsym(handle, name_n);
357 if( func )
goto found;
360 for( i = 0; i < 256; i += 4 ){
361 sprintf(name_n + len,
"%d", i);
362 func = dlsym(handle, name_n);
#define SafeStringValueCStr(v)
void rb_bug(const char *fmt,...)
size_t strlen(const char *)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_raise(VALUE exc, const char *fmt,...)
#define TypedData_Get_Struct(obj, type, data_type, sval)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
An equivalent to ensure clause.
int rb_w32_map_errno(DWORD)
RUBY_EXTERN VALUE rb_cObject
void Init_fiddle_handle(void)
void rb_define_const(VALUE, const char *, VALUE)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
register unsigned int len
#define TypedData_Make_Struct(klass, type, data_type, sval)
#define STRCASECMP(s1, s2)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)