28 static ID id_win32_last_error;
31 rb_dl_get_win32_last_error(
VALUE self)
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__");
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)
SSL_METHOD *(* func)(void)
#define TypedData_Get_Struct(obj, type, data_type, sval)
static VALUE INT2NUM(int v)
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)
VALUE rb_tainted_str_new2(const char *)
#define RARRAY_LEN(ARRAY)
static void dlcfunc_free(void *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)
VALUE rb_big2ulong_pack(VALUE x)
static VALUE rb_dlcfunc_set_ctype(VALUE self, VALUE ctype)
VALUE rb_dlcfunc_new(void(*func)(), int type, const char *name, ID calltype)
memset(y->frac+ix+1, 0,(y->Prec-(ix+1))*sizeof(BDIGIT))
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)
void rb_secure_update(VALUE)
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)
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)