28 static ID id_win32_last_error;
31 rb_dl_get_win32_last_error(
VALUE self)
37 rb_dl_set_win32_last_error(
VALUE self,
VALUE val)
69 size +=
sizeof(*data);
113 else if( val ==
Qnil ){
159 rb_scan_args(argc, argv,
"13", &addr, &type, &name, &calltype);
162 saddr = (
void*)(
NUM2PTR(addrnum));
171 data->
wrap = (addrnum == addr) ? 0 : addr;
300 val =
rb_sprintf(
"#<DL::CFunc:%p ptr=%p type=%d name='%s'>",
310 # define DECL_FUNC_CDECL(f,ret,args,val) \
311 ret (FUNC_CDECL(*(f)))(args) = (ret (FUNC_CDECL(*))(args))(VALUE)(val)
313 # define DECL_FUNC_STDCALL(f,ret,args,val) \
314 ret (FUNC_STDCALL(*(f)))(args) = (ret (FUNC_STDCALL(*))(args))(VALUE)(val)
317 #define CALL_CASE switch( RARRAY_LEN(ary) ){ \
319 CASE(1); break; CASE(2); break; CASE(3); break; CASE(4); break; CASE(5); break; \
320 CASE(6); break; CASE(7); break; CASE(8); break; CASE(9); break; CASE(10);break; \
321 CASE(11);break; CASE(12);break; CASE(13);break; CASE(14);break; CASE(15);break; \
322 CASE(16);break; CASE(17);break; CASE(18);break; CASE(19);break; CASE(20);break; \
323 default: rb_raise(rb_eArgError, "too many arguments"); \
327 #if defined(_MSC_VER) && defined(_M_AMD64) && _MSC_VER >= 1400 && _MSC_VER < 1600
328 # pragma optimize("", off)
353 if( cfunc->
ptr == 0 ){
360 if( i >= DLSTACK_SIZE ){
369 #if SIZEOF_VOIDP == SIZEOF_LONG
386 switch( cfunc->
type ){
388 #define CASE(n) case n: { \
389 DECL_FUNC_CDECL(f,void,DLSTACK_PROTO##n,cfunc->ptr); \
390 f(DLSTACK_ARGS##n(stack)); \
397 #define CASE(n) case n: { \
398 DECL_FUNC_CDECL(f,void*,DLSTACK_PROTO##n,cfunc->ptr); \
400 ret = f(DLSTACK_ARGS##n(stack)); \
401 result = PTR2NUM(ret); \
407 #define CASE(n) case n: { \
408 DECL_FUNC_CDECL(f,char,DLSTACK_PROTO##n,cfunc->ptr); \
410 ret = f(DLSTACK_ARGS##n(stack)); \
411 result = CHR2FIX(ret); \
417 #define CASE(n) case n: { \
418 DECL_FUNC_CDECL(f,short,DLSTACK_PROTO##n,cfunc->ptr); \
420 ret = f(DLSTACK_ARGS##n(stack)); \
421 result = INT2NUM((int)ret); \
427 #define CASE(n) case n: { \
428 DECL_FUNC_CDECL(f,int,DLSTACK_PROTO##n,cfunc->ptr); \
430 ret = f(DLSTACK_ARGS##n(stack)); \
431 result = INT2NUM(ret); \
437 #define CASE(n) case n: { \
438 DECL_FUNC_CDECL(f,long,DLSTACK_PROTO##n,cfunc->ptr); \
440 ret = f(DLSTACK_ARGS##n(stack)); \
441 result = LONG2NUM(ret); \
447 case DLTYPE_LONG_LONG:
448 #define CASE(n) case n: { \
449 DECL_FUNC_CDECL(f,LONG_LONG,DLSTACK_PROTO##n,cfunc->ptr); \
451 ret = f(DLSTACK_ARGS##n(stack)); \
452 result = LL2NUM(ret); \
459 #define CASE(n) case n: { \
460 DECL_FUNC_CDECL(f,float,DLSTACK_PROTO##n,cfunc->ptr); \
462 ret = f(DLSTACK_ARGS##n(stack)); \
463 result = rb_float_new(ret); \
469 #define CASE(n) case n: { \
470 DECL_FUNC_CDECL(f,double,DLSTACK_PROTO##n,cfunc->ptr); \
472 ret = f(DLSTACK_ARGS##n(stack)); \
473 result = rb_float_new(ret); \
485 switch( cfunc->
type ){
487 #define CASE(n) case n: { \
488 DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n##_,cfunc->ptr); \
489 f(DLSTACK_ARGS##n(stack)); \
496 #define CASE(n) case n: { \
497 DECL_FUNC_STDCALL(f,void*,DLSTACK_PROTO##n##_,cfunc->ptr); \
499 ret = f(DLSTACK_ARGS##n(stack)); \
500 result = PTR2NUM(ret); \
506 #define CASE(n) case n: { \
507 DECL_FUNC_STDCALL(f,char,DLSTACK_PROTO##n##_,cfunc->ptr); \
509 ret = f(DLSTACK_ARGS##n(stack)); \
510 result = CHR2FIX(ret); \
516 #define CASE(n) case n: { \
517 DECL_FUNC_STDCALL(f,short,DLSTACK_PROTO##n##_,cfunc->ptr); \
519 ret = f(DLSTACK_ARGS##n(stack)); \
520 result = INT2NUM((int)ret); \
526 #define CASE(n) case n: { \
527 DECL_FUNC_STDCALL(f,int,DLSTACK_PROTO##n##_,cfunc->ptr); \
529 ret = f(DLSTACK_ARGS##n(stack)); \
530 result = INT2NUM(ret); \
536 #define CASE(n) case n: { \
537 DECL_FUNC_STDCALL(f,long,DLSTACK_PROTO##n##_,cfunc->ptr); \
539 ret = f(DLSTACK_ARGS##n(stack)); \
540 result = LONG2NUM(ret); \
546 case DLTYPE_LONG_LONG:
547 #define CASE(n) case n: { \
548 DECL_FUNC_STDCALL(f,LONG_LONG,DLSTACK_PROTO##n##_,cfunc->ptr); \
550 ret = f(DLSTACK_ARGS##n(stack)); \
551 result = LL2NUM(ret); \
558 #define CASE(n) case n: { \
559 DECL_FUNC_STDCALL(f,float,DLSTACK_PROTO##n##_,cfunc->ptr); \
561 ret = f(DLSTACK_ARGS##n(stack)); \
562 result = rb_float_new(ret); \
568 #define CASE(n) case n: { \
569 DECL_FUNC_STDCALL(f,double,DLSTACK_PROTO##n##_,cfunc->ptr); \
571 ret = f(DLSTACK_ARGS##n(stack)); \
572 result = rb_float_new(ret); \
596 rb_dl_set_win32_last_error(
self,
INT2NUM(GetLastError()));
601 #if defined(_MSC_VER) && defined(_M_AMD64) && _MSC_VER >= 1400 && _MSC_VER < 1600
602 # pragma optimize("", on)
625 id_win32_last_error =
rb_intern(
"__DL2_WIN32_LAST_ERROR__");