29 static ID id_win32_last_error;
32 rb_dl_get_win32_last_error(
VALUE self)
70 size +=
sizeof(*data);
162 saddr = (
void*)(
NUM2PTR(addrnum));
171 data->
wrap = (addrnum == addr) ? 0 : addr;
312 # define DECL_FUNC_CDECL(f,ret,args,val) \ 313 ret (FUNC_CDECL(*(f)))(args) = (ret (FUNC_CDECL(*))(args))(VALUE)(val) 315 # define DECL_FUNC_STDCALL(f,ret,args,val) \ 316 ret (FUNC_STDCALL(*(f)))(args) = (ret (FUNC_STDCALL(*))(args))(VALUE)(val) 319 #define CALL_CASE switch( RARRAY_LEN(ary) ){ \ 321 CASE(1); break; CASE(2); break; CASE(3); break; CASE(4); break; CASE(5); break; \ 322 CASE(6); break; CASE(7); break; CASE(8); break; CASE(9); break; CASE(10);break; \ 323 CASE(11);break; CASE(12);break; CASE(13);break; CASE(14);break; CASE(15);break; \ 324 CASE(16);break; CASE(17);break; CASE(18);break; CASE(19);break; CASE(20);break; \ 325 default: rb_raise(rb_eArgError, "too many arguments"); \ 329 #if defined(_MSC_VER) && defined(_M_AMD64) && _MSC_VER >= 1400 && _MSC_VER < 1600 330 # pragma optimize("", off) 353 if( cfunc->
ptr == 0 ){
369 unsigned long ls[(
sizeof(
DLSTACK_TYPE) +
sizeof(
long) - 1)/
sizeof(
long)];
374 for (j = 0; j < (int)(
sizeof(ls)/
sizeof(*ls)); j++)
389 switch( cfunc->
type ){
391 #define CASE(n) case n: { \ 392 DECL_FUNC_CDECL(f,void,DLSTACK_PROTO##n,cfunc->ptr); \ 393 f(DLSTACK_ARGS##n(stack)); \ 400 #define CASE(n) case n: { \ 401 DECL_FUNC_CDECL(f,void*,DLSTACK_PROTO##n,cfunc->ptr); \ 403 ret = f(DLSTACK_ARGS##n(stack)); \ 404 result = PTR2NUM(ret); \ 410 #define CASE(n) case n: { \ 411 DECL_FUNC_CDECL(f,char,DLSTACK_PROTO##n,cfunc->ptr); \ 413 ret = f(DLSTACK_ARGS##n(stack)); \ 414 result = CHR2FIX(ret); \ 420 #define CASE(n) case n: { \ 421 DECL_FUNC_CDECL(f,short,DLSTACK_PROTO##n,cfunc->ptr); \ 423 ret = f(DLSTACK_ARGS##n(stack)); \ 424 result = INT2NUM((int)ret); \ 430 #define CASE(n) case n: { \ 431 DECL_FUNC_CDECL(f,int,DLSTACK_PROTO##n,cfunc->ptr); \ 433 ret = f(DLSTACK_ARGS##n(stack)); \ 434 result = INT2NUM(ret); \ 440 #define CASE(n) case n: { \ 441 DECL_FUNC_CDECL(f,long,DLSTACK_PROTO##n,cfunc->ptr); \ 443 ret = f(DLSTACK_ARGS##n(stack)); \ 444 result = LONG2NUM(ret); \ 450 case DLTYPE_LONG_LONG:
451 #define CASE(n) case n: { \ 452 DECL_FUNC_CDECL(f,LONG_LONG,DLSTACK_PROTO##n,cfunc->ptr); \ 454 ret = f(DLSTACK_ARGS##n(stack)); \ 455 result = LL2NUM(ret); \ 462 #define CASE(n) case n: { \ 463 DECL_FUNC_CDECL(f,float,DLSTACK_PROTO##n,cfunc->ptr); \ 465 ret = f(DLSTACK_ARGS##n(stack)); \ 466 result = rb_float_new(ret); \ 472 #define CASE(n) case n: { \ 473 DECL_FUNC_CDECL(f,double,DLSTACK_PROTO##n,cfunc->ptr); \ 475 ret = f(DLSTACK_ARGS##n(stack)); \ 476 result = rb_float_new(ret); \ 488 switch( cfunc->
type ){
490 #define CASE(n) case n: { \ 491 DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n##_,cfunc->ptr); \ 492 f(DLSTACK_ARGS##n(stack)); \ 499 #define CASE(n) case n: { \ 500 DECL_FUNC_STDCALL(f,void*,DLSTACK_PROTO##n##_,cfunc->ptr); \ 502 ret = f(DLSTACK_ARGS##n(stack)); \ 503 result = PTR2NUM(ret); \ 509 #define CASE(n) case n: { \ 510 DECL_FUNC_STDCALL(f,char,DLSTACK_PROTO##n##_,cfunc->ptr); \ 512 ret = f(DLSTACK_ARGS##n(stack)); \ 513 result = CHR2FIX(ret); \ 519 #define CASE(n) case n: { \ 520 DECL_FUNC_STDCALL(f,short,DLSTACK_PROTO##n##_,cfunc->ptr); \ 522 ret = f(DLSTACK_ARGS##n(stack)); \ 523 result = INT2NUM((int)ret); \ 529 #define CASE(n) case n: { \ 530 DECL_FUNC_STDCALL(f,int,DLSTACK_PROTO##n##_,cfunc->ptr); \ 532 ret = f(DLSTACK_ARGS##n(stack)); \ 533 result = INT2NUM(ret); \ 539 #define CASE(n) case n: { \ 540 DECL_FUNC_STDCALL(f,long,DLSTACK_PROTO##n##_,cfunc->ptr); \ 542 ret = f(DLSTACK_ARGS##n(stack)); \ 543 result = LONG2NUM(ret); \ 549 case DLTYPE_LONG_LONG:
550 #define CASE(n) case n: { \ 551 DECL_FUNC_STDCALL(f,LONG_LONG,DLSTACK_PROTO##n##_,cfunc->ptr); \ 553 ret = f(DLSTACK_ARGS##n(stack)); \ 554 result = LL2NUM(ret); \ 561 #define CASE(n) case n: { \ 562 DECL_FUNC_STDCALL(f,float,DLSTACK_PROTO##n##_,cfunc->ptr); \ 564 ret = f(DLSTACK_ARGS##n(stack)); \ 565 result = rb_float_new(ret); \ 571 #define CASE(n) case n: { \ 572 DECL_FUNC_STDCALL(f,double,DLSTACK_PROTO##n##_,cfunc->ptr); \ 574 ret = f(DLSTACK_ARGS##n(stack)); \ 575 result = rb_float_new(ret); \ 599 rb_dl_set_win32_last_error(
self,
INT2NUM(GetLastError()));
604 #if defined(_MSC_VER) && defined(_M_AMD64) && _MSC_VER >= 1400 && _MSC_VER < 1600 605 # pragma optimize("", on) 628 id_win32_last_error =
rb_intern(
"__DL2_WIN32_LAST_ERROR__");
int rb_dlcfunc_kind_p(VALUE func)
size_t strlen(const char *)
static VALUE rb_dl_get_last_error(VALUE self)
static VALUE rb_dlcfunc_set_calltype(VALUE self, VALUE sym)
void rb_big_pack(VALUE val, unsigned long *buf, long num_longs)
#define TypedData_Get_Struct(obj, type, data_type, sval)
SSL_METHOD *(* func)(void)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
static VALUE rb_dlcfunc_inspect(VALUE self)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
static void dlcfunc_free(void *ptr)
void rb_gc_mark(VALUE ptr)
static VALUE rb_dlcfunc_set_ptr(VALUE self, VALUE addr)
VALUE rb_thread_local_aref(VALUE, ID)
static VALUE rb_dl_set_last_error(VALUE self, VALUE val)
#define RB_TYPE_P(obj, type)
static VALUE rb_dlcfunc_set_ctype(VALUE self, VALUE ctype)
VALUE rb_dlcfunc_new(void(*func)(), int type, const char *name, ID calltype)
RUBY_EXTERN VALUE rb_cObject
static VALUE rb_dlcfunc_to_i(VALUE self)
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
VALUE rb_thread_current(void)
static VALUE rb_dlcfunc_s_allocate(VALUE klass)
static void dlcfunc_mark(void *ptr)
static VALUE rb_dlcfunc_initialize(int argc, VALUE argv[], VALUE self)
VALUE rb_thread_local_aset(VALUE, ID, VALUE)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
VALUE rb_sprintf(const char *format,...)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static size_t dlcfunc_memsize(const void *ptr)
#define rb_tainted_str_new2
static VALUE rb_dlcfunc_ctype(VALUE self)
static VALUE rb_dlcfunc_ptr(VALUE self)
void rb_check_safe_obj(VALUE)
#define TypedData_Make_Struct(klass, type, data_type, sval)
const char * rb_id2name(ID id)
#define StringValuePtr(v)
static VALUE rb_dlcfunc_name(VALUE self)
const rb_data_type_t dlcfunc_data_type
void * rb_dlcfunc2ptr(VALUE val)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static VALUE rb_dlcfunc_calltype(VALUE self)
static VALUE rb_dlcfunc_call(VALUE self, VALUE ary)