29 static ID id_win32_last_error;
32 rb_dl_get_win32_last_error(
VALUE self)
38 rb_dl_set_win32_last_error(
VALUE self,
VALUE val)
70 size +=
sizeof(*data);
114 else if( val ==
Qnil ){
160 rb_scan_args(argc, argv,
"13", &addr, &type, &name, &calltype);
163 saddr = (
void*)(
NUM2PTR(addrnum));
172 data->
wrap = (addrnum == addr) ? 0 : addr;
301 val =
rb_sprintf(
"#<DL::CFunc:%p ptr=%p type=%d name='%s'>",
311 # define DECL_FUNC_CDECL(f,ret,args,val) \
312 ret (FUNC_CDECL(*(f)))(args) = (ret (FUNC_CDECL(*))(args))(VALUE)(val)
314 # define DECL_FUNC_STDCALL(f,ret,args,val) \
315 ret (FUNC_STDCALL(*(f)))(args) = (ret (FUNC_STDCALL(*))(args))(VALUE)(val)
318 #define CALL_CASE switch( RARRAY_LEN(ary) ){ \
320 CASE(1); break; CASE(2); break; CASE(3); break; CASE(4); break; CASE(5); break; \
321 CASE(6); break; CASE(7); break; CASE(8); break; CASE(9); break; CASE(10);break; \
322 CASE(11);break; CASE(12);break; CASE(13);break; CASE(14);break; CASE(15);break; \
323 CASE(16);break; CASE(17);break; CASE(18);break; CASE(19);break; CASE(20);break; \
324 default: rb_raise(rb_eArgError, "too many arguments"); \
328 #if defined(_MSC_VER) && defined(_M_AMD64) && _MSC_VER >= 1400 && _MSC_VER < 1600
329 # pragma optimize("", off)
354 if( cfunc->
ptr == 0 ){
361 if( i >= DLSTACK_SIZE ){
370 #if SIZEOF_VOIDP == SIZEOF_LONG
387 switch( cfunc->
type ){
389 #define CASE(n) case n: { \
390 DECL_FUNC_CDECL(f,void,DLSTACK_PROTO##n,cfunc->ptr); \
391 f(DLSTACK_ARGS##n(stack)); \
398 #define CASE(n) case n: { \
399 DECL_FUNC_CDECL(f,void*,DLSTACK_PROTO##n,cfunc->ptr); \
401 ret = f(DLSTACK_ARGS##n(stack)); \
402 result = PTR2NUM(ret); \
408 #define CASE(n) case n: { \
409 DECL_FUNC_CDECL(f,char,DLSTACK_PROTO##n,cfunc->ptr); \
411 ret = f(DLSTACK_ARGS##n(stack)); \
412 result = CHR2FIX(ret); \
418 #define CASE(n) case n: { \
419 DECL_FUNC_CDECL(f,short,DLSTACK_PROTO##n,cfunc->ptr); \
421 ret = f(DLSTACK_ARGS##n(stack)); \
422 result = INT2NUM((int)ret); \
428 #define CASE(n) case n: { \
429 DECL_FUNC_CDECL(f,int,DLSTACK_PROTO##n,cfunc->ptr); \
431 ret = f(DLSTACK_ARGS##n(stack)); \
432 result = INT2NUM(ret); \
438 #define CASE(n) case n: { \
439 DECL_FUNC_CDECL(f,long,DLSTACK_PROTO##n,cfunc->ptr); \
441 ret = f(DLSTACK_ARGS##n(stack)); \
442 result = LONG2NUM(ret); \
448 case DLTYPE_LONG_LONG:
449 #define CASE(n) case n: { \
450 DECL_FUNC_CDECL(f,LONG_LONG,DLSTACK_PROTO##n,cfunc->ptr); \
452 ret = f(DLSTACK_ARGS##n(stack)); \
453 result = LL2NUM(ret); \
460 #define CASE(n) case n: { \
461 DECL_FUNC_CDECL(f,float,DLSTACK_PROTO##n,cfunc->ptr); \
463 ret = f(DLSTACK_ARGS##n(stack)); \
464 result = rb_float_new(ret); \
470 #define CASE(n) case n: { \
471 DECL_FUNC_CDECL(f,double,DLSTACK_PROTO##n,cfunc->ptr); \
473 ret = f(DLSTACK_ARGS##n(stack)); \
474 result = rb_float_new(ret); \
486 switch( cfunc->
type ){
488 #define CASE(n) case n: { \
489 DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n##_,cfunc->ptr); \
490 f(DLSTACK_ARGS##n(stack)); \
497 #define CASE(n) case n: { \
498 DECL_FUNC_STDCALL(f,void*,DLSTACK_PROTO##n##_,cfunc->ptr); \
500 ret = f(DLSTACK_ARGS##n(stack)); \
501 result = PTR2NUM(ret); \
507 #define CASE(n) case n: { \
508 DECL_FUNC_STDCALL(f,char,DLSTACK_PROTO##n##_,cfunc->ptr); \
510 ret = f(DLSTACK_ARGS##n(stack)); \
511 result = CHR2FIX(ret); \
517 #define CASE(n) case n: { \
518 DECL_FUNC_STDCALL(f,short,DLSTACK_PROTO##n##_,cfunc->ptr); \
520 ret = f(DLSTACK_ARGS##n(stack)); \
521 result = INT2NUM((int)ret); \
527 #define CASE(n) case n: { \
528 DECL_FUNC_STDCALL(f,int,DLSTACK_PROTO##n##_,cfunc->ptr); \
530 ret = f(DLSTACK_ARGS##n(stack)); \
531 result = INT2NUM(ret); \
537 #define CASE(n) case n: { \
538 DECL_FUNC_STDCALL(f,long,DLSTACK_PROTO##n##_,cfunc->ptr); \
540 ret = f(DLSTACK_ARGS##n(stack)); \
541 result = LONG2NUM(ret); \
547 case DLTYPE_LONG_LONG:
548 #define CASE(n) case n: { \
549 DECL_FUNC_STDCALL(f,LONG_LONG,DLSTACK_PROTO##n##_,cfunc->ptr); \
551 ret = f(DLSTACK_ARGS##n(stack)); \
552 result = LL2NUM(ret); \
559 #define CASE(n) case n: { \
560 DECL_FUNC_STDCALL(f,float,DLSTACK_PROTO##n##_,cfunc->ptr); \
562 ret = f(DLSTACK_ARGS##n(stack)); \
563 result = rb_float_new(ret); \
569 #define CASE(n) case n: { \
570 DECL_FUNC_STDCALL(f,double,DLSTACK_PROTO##n##_,cfunc->ptr); \
572 ret = f(DLSTACK_ARGS##n(stack)); \
573 result = rb_float_new(ret); \
597 rb_dl_set_win32_last_error(
self,
INT2NUM(GetLastError()));
602 #if defined(_MSC_VER) && defined(_M_AMD64) && _MSC_VER >= 1400 && _MSC_VER < 1600
603 # pragma optimize("", on)
626 id_win32_last_error =
rb_intern(
"__DL2_WIN32_LAST_ERROR__");