From 3465e37e63242c62c8a86cff16ba156fedf4a202 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 1 Mar 2009 10:02:06 +0000 Subject: * ext/dl/cfunc.c (rb_dlcfunc_call): fix for stdcall and missing argument numbers. [ruby-core:22601] * ext/dl/dl.h (DLSTACK_PROTO0_): added. * ext/dl/mkcallback.rb (gencallback, gen_callback_file), (rb_dl_init_callbacks): omit stdcall functions unless supported. * lib/rubygems/config_file.rb (SHGetFolderPath): stdcall. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dl/cfunc.c | 46 +++++++++++++++++++++++++++------------------- ext/dl/dl.h | 6 ++---- ext/dl/mkcallback.rb | 10 ++++++++-- 3 files changed, 37 insertions(+), 25 deletions(-) (limited to 'ext/dl') diff --git a/ext/dl/cfunc.c b/ext/dl/cfunc.c index 724c290f2f..0ea60b1972 100644 --- a/ext/dl/cfunc.c +++ b/ext/dl/cfunc.c @@ -224,7 +224,9 @@ rb_dlcfunc_inspect(VALUE self) # define DECL_FUNC_CDECL(f,ret,args) ret (FUNC_CDECL(*f))(args) +#ifdef FUNC_STDCALL # define DECL_FUNC_STDCALL(f,ret,args) ret (FUNC_STDCALL(*f))(args) +#endif #define CALL_CASE switch( RARRAY_LEN(ary) ){ \ CASE(0); break; \ @@ -265,7 +267,11 @@ rb_dlcfunc_call(VALUE self, VALUE ary) } /* calltype == CFUNC_CDECL */ - if( cfunc->calltype == CFUNC_CDECL ){ + if( cfunc->calltype == CFUNC_CDECL +#ifndef FUNC_STDCALL + || cfunc->calltype == CFUNC_STDCALL +#endif + ){ switch( cfunc->type ){ case DLTYPE_VOID: #define CASE(n) case n: { \ @@ -329,9 +335,9 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #if HAVE_LONG_LONG /* used in ruby.h */ case DLTYPE_LONG_LONG: #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,LONG_LONG,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_FUNC_CDECL(f,LONG_LONG,DLSTACK_PROTO##n) = cfunc->ptr; \ LONG_LONG ret; \ - ret = f(DLSTACK_ARGS(stack)); \ + ret = f(DLSTACK_ARGS##n(stack)); \ result = LL2NUM(ret); \ } CALL_CASE; @@ -340,9 +346,9 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #endif case DLTYPE_FLOAT: #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,float,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_FUNC_CDECL(f,float,DLSTACK_PROTO##n) = cfunc->ptr; \ float ret; \ - ret = f(DLSTACK_ARGS(stack)); \ + ret = f(DLSTACK_ARGS##n(stack)); \ result = rb_float_new(ret); \ } CALL_CASE; @@ -350,9 +356,9 @@ rb_dlcfunc_call(VALUE self, VALUE ary) break; case DLTYPE_DOUBLE: #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,double,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_FUNC_CDECL(f,double,DLSTACK_PROTO##n) = cfunc->ptr; \ double ret; \ - ret = f(DLSTACK_ARGS(stack)); \ + ret = f(DLSTACK_ARGS##n(stack)); \ result = rb_float_new(ret); \ } CALL_CASE; @@ -362,12 +368,13 @@ rb_dlcfunc_call(VALUE self, VALUE ary) rb_raise(rb_eDLTypeError, "unknown type %d", cfunc->type); } } +#ifdef FUNC_STDCALL else if( cfunc->calltype == CFUNC_STDCALL ){ /* calltype == CFUNC_STDCALL */ switch( cfunc->type ){ case DLTYPE_VOID: #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n##_) = cfunc->ptr; \ f(DLSTACK_ARGS##n(stack)); \ result = Qnil; \ } @@ -376,7 +383,7 @@ rb_dlcfunc_call(VALUE self, VALUE ary) break; case DLTYPE_VOIDP: #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,void*,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_FUNC_STDCALL(f,void*,DLSTACK_PROTO##n##_) = cfunc->ptr; \ void * ret; \ ret = f(DLSTACK_ARGS##n(stack)); \ result = PTR2NUM(ret); \ @@ -386,7 +393,7 @@ rb_dlcfunc_call(VALUE self, VALUE ary) break; case DLTYPE_CHAR: #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,char,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_FUNC_STDCALL(f,char,DLSTACK_PROTO##n##_) = cfunc->ptr; \ char ret; \ ret = f(DLSTACK_ARGS##n(stack)); \ result = CHR2FIX(ret); \ @@ -396,7 +403,7 @@ rb_dlcfunc_call(VALUE self, VALUE ary) break; case DLTYPE_SHORT: #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,short,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_FUNC_STDCALL(f,short,DLSTACK_PROTO##n##_) = cfunc->ptr; \ short ret; \ ret = f(DLSTACK_ARGS##n(stack)); \ result = INT2NUM((int)ret); \ @@ -406,7 +413,7 @@ rb_dlcfunc_call(VALUE self, VALUE ary) break; case DLTYPE_INT: #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,int,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_FUNC_STDCALL(f,int,DLSTACK_PROTO##n##_) = cfunc->ptr; \ int ret; \ ret = f(DLSTACK_ARGS##n(stack)); \ result = INT2NUM(ret); \ @@ -416,7 +423,7 @@ rb_dlcfunc_call(VALUE self, VALUE ary) break; case DLTYPE_LONG: #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,long,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_FUNC_STDCALL(f,long,DLSTACK_PROTO##n##_) = cfunc->ptr; \ long ret; \ ret = f(DLSTACK_ARGS##n(stack)); \ result = LONG2NUM(ret); \ @@ -427,9 +434,9 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #if HAVE_LONG_LONG /* used in ruby.h */ case DLTYPE_LONG_LONG: #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,LONG_LONG,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_FUNC_STDCALL(f,LONG_LONG,DLSTACK_PROTO##n##_) = cfunc->ptr; \ LONG_LONG ret; \ - ret = f(DLSTACK_ARGS(stack)); \ + ret = f(DLSTACK_ARGS##n(stack)); \ result = LL2NUM(ret); \ } CALL_CASE; @@ -438,9 +445,9 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #endif case DLTYPE_FLOAT: #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,float,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_FUNC_STDCALL(f,float,DLSTACK_PROTO##n##_) = cfunc->ptr; \ float ret; \ - ret = f(DLSTACK_ARGS(stack)); \ + ret = f(DLSTACK_ARGS##n(stack)); \ result = rb_float_new(ret); \ } CALL_CASE; @@ -448,9 +455,9 @@ rb_dlcfunc_call(VALUE self, VALUE ary) break; case DLTYPE_DOUBLE: #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,double,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_FUNC_STDCALL(f,double,DLSTACK_PROTO##n##_) = cfunc->ptr; \ double ret; \ - ret = f(DLSTACK_ARGS(stack)); \ + ret = f(DLSTACK_ARGS##n(stack)); \ result = rb_float_new(ret); \ } CALL_CASE; @@ -460,6 +467,7 @@ rb_dlcfunc_call(VALUE self, VALUE ary) rb_raise(rb_eDLTypeError, "unknown type %d", cfunc->type); } } +#endif else{ rb_raise(rb_eDLError, #ifndef LONG_LONG_VALUE diff --git a/ext/dl/dl.h b/ext/dl/dl.h index 87a59946cd..753bd1c976 100644 --- a/ext/dl/dl.h +++ b/ext/dl/dl.h @@ -6,9 +6,6 @@ #if !defined(FUNC_CDECL) # define FUNC_CDECL(x) x #endif -#if !defined(FUNC_STDCALL) -# define FUNC_STDCALL(x) x -#endif #if defined(HAVE_DLFCN_H) # include @@ -49,7 +46,7 @@ stack[10],stack[11],stack[12],stack[13],stack[14],\ stack[15],stack[16],stack[17],stack[18],stack[19] -#define DLSTACK_PROTO0 +#define DLSTACK_PROTO0_ void #define DLSTACK_PROTO1_ DLSTACK_TYPE #define DLSTACK_PROTO2_ DLSTACK_PROTO1_, DLSTACK_TYPE #define DLSTACK_PROTO3_ DLSTACK_PROTO2_, DLSTACK_TYPE @@ -86,6 +83,7 @@ * (...) in the declaration) %al is used as hidden argument to * specify the number of SSE registers used. */ +#define DLSTACK_PROTO0 void #define DLSTACK_PROTO1 DLSTACK_PROTO1_, ... #define DLSTACK_PROTO2 DLSTACK_PROTO2_, ... #define DLSTACK_PROTO3 DLSTACK_PROTO3_, ... diff --git a/ext/dl/mkcallback.rb b/ext/dl/mkcallback.rb index 8809f69f06..1cac0857bb 100644 --- a/ext/dl/mkcallback.rb +++ b/ext/dl/mkcallback.rb @@ -114,7 +114,7 @@ end def gencallback(ty, calltype, proc_entry, argc, n) <<-EOS - +#{calltype == STDCALL ? "\n#ifdef FUNC_STDCALL" : ""} static #{DLTYPE[ty][:type]} FUNC_#{calltype.upcase}(#{func_name(ty,argc,n,calltype)})(#{(0...argc).collect{|i| "DLSTACK_TYPE stack" + i.to_s}.join(", ")}) { @@ -128,7 +128,7 @@ FUNC_#{calltype.upcase}(#{func_name(ty,argc,n,calltype)})(#{(0...argc).collect{| ret = rb_funcall2(cb, rb_dl_cb_call, #{argc}, #{argc > 0 ? 'args' : 'NULL'}); return #{DLTYPE[ty][:conv] ? DLTYPE[ty][:conv] % "ret" : ""}; } - +#{calltype == STDCALL ? "#endif\n" : ""} EOS end @@ -157,7 +157,9 @@ def gen_callback_file(ty) f.puts <<-EOS #include "dl.h" extern VALUE rb_DLCdeclCallbackAddrs, rb_DLCdeclCallbackProcs; +#ifdef FUNC_STDCALL extern VALUE rb_DLStdcallCallbackAddrs, rb_DLStdcallCallbackProcs; +#endif extern ID rb_dl_cb_call; EOS yield f @@ -167,8 +169,10 @@ void { #{gen_push_proc_ary(ty, "rb_DLCdeclCallbackProcs")} #{gen_push_addr_ary(ty, "rb_DLCdeclCallbackAddrs", CDECL)} +#ifdef FUNC_STDCALL #{gen_push_proc_ary(ty, "rb_DLStdcallCallbackProcs")} #{gen_push_addr_ary(ty, "rb_DLStdcallCallbackAddrs", STDCALL)} +#endif } EOS } @@ -201,11 +205,13 @@ rb_dl_init_callbacks() tmp = rb_DLCdeclCallbackAddrs = rb_ary_new(); rb_define_const(rb_mDL, "CdeclCallbackAddrs", tmp); +#ifdef FUNC_STDCALL tmp = rb_DLStdcallCallbackProcs = rb_ary_new(); rb_define_const(rb_mDL, "StdcallCallbackProcs", tmp); tmp = rb_DLStdcallCallbackAddrs = rb_ary_new(); rb_define_const(rb_mDL, "StdcallCallbackAddrs", tmp); +#endif #{ (0...MAX_DLTYPE).collect{|ty| -- cgit v1.2.3