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);
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;
302 val =
rb_sprintf(
"#<DL::CFunc:%p ptr=%p type=%d name='%s'>",
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 ){
360 if( i >= DLSTACK_SIZE ){
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__");