From: "U.Nakamura" Date: 2006-07-03T21:10:57+09:00 Subject: [ruby-dev:28943] Re: FUNC_CDECL/FUNC_STDCALL are not defined? こんにちは、なかむら(う)です。 In message "[ruby-dev:28942] FUNC_CDECL/FUNC_STDCALL are not defined?" on Jul.03,2006 19:53:15, wrote: | 1.8.5-preview1の話題に割り込む形で申し訳ありませんが、さきほど | CVS HEAD のコンパイルを試みたところ(VC++ 7.1 Windows 2000SP4)、 | ext/dl のコンパイルでcallback.hに関して大量にコンパイルエラーが | 発生してビルドに失敗しました。 再現しました。 ちなみに、VC++以外でも、手元のNetBSDでも In file included from ../../../current/ext/dl/dl.c:77: callback.h:9: error: parse error before '{' token callback.h:12: error: initializer element is not constant callback.h:12: warning: data definition has no type or storage class とかになってコンパイルに失敗します。 chkbuildのNetBSD 2.0.1では成功してるので、gccのバージョンかな んかが影響してそうではありますが。 | ChangeLogをみてもここ数日で ext/dl が修正された気配はないのですが、 [ruby-cvs:17051]ですね。一昨日の未明になります。 | とりあえずむりやりこれら二つのマクロを適当に定義してやることでコンパイル | はでき、nmake test も通りました。 木村さんはどう定義しました? 私がやると、FUNC_なんたらを定義することを避けちゃってこんなん になりそうですが、かっこわるい... Index: ext/dl/cfunc.c =================================================================== RCS file: /home/cvs/ruby/ext/dl/cfunc.c,v retrieving revision 1.5 diff -u -1 -p -r1.5 cfunc.c --- ext/dl/cfunc.c 30 Jun 2006 18:05:34 -0000 1.5 +++ ext/dl/cfunc.c 3 Jul 2006 12:03:23 -0000 @@ -225,8 +225,8 @@ rb_dlcfunc_inspect(VALUE self) #if defined(__GNUC__) -# define DECL_FUNC_CDECL(f,ret,args) FUNC_CDECL(ret (*f)(args)) -# define DECL_FUNC_STDCALL(f,ret,args) FUNC_STDCALL(ret (*f)(args)) +# define DECL_PFUNC_CDECL(f,ret,args) FUNC_CDECL(ret (*f)(args)) +# define DECL_PFUNC_STDCALL(f,ret,args) FUNC_STDCALL(ret (*f)(args)) /* # define DECL_FUNC(f,ret,args,calltype) ret (*f)(args) */ #elif defined(_MSC_VER) || defined(__BORLANDC__) -# define DECL_FUNC_CDECL(f,ret,args) ret (__cdecl *f)(args) -# define DECL_FUNC_STDCALL(f,ret,args) ret (__stdcall *f)(args) +# define DECL_PFUNC_CDECL(f,ret,args) ret (__cdecl *f)(args) +# define DECL_PFUNC_STDCALL(f,ret,args) ret (__stdcall *f)(args) #else @@ -277,3 +277,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,void,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_CDECL(f,void,DLSTACK_PROTO##n) = cfunc->ptr; \ f(DLSTACK_ARGS##n(stack)); \ @@ -286,3 +286,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,void*,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_CDECL(f,void*,DLSTACK_PROTO##n) = cfunc->ptr; \ void * ret; \ @@ -296,3 +296,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,char,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_CDECL(f,char,DLSTACK_PROTO##n) = cfunc->ptr; \ char ret; \ @@ -306,3 +306,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,short,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_CDECL(f,short,DLSTACK_PROTO##n) = cfunc->ptr; \ short ret; \ @@ -316,3 +316,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,int,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_CDECL(f,int,DLSTACK_PROTO##n) = cfunc->ptr; \ int ret; \ @@ -326,3 +326,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,long,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_CDECL(f,long,DLSTACK_PROTO##n) = cfunc->ptr; \ long ret; \ @@ -337,3 +337,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,LONG_LONG,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_PFUNC_CDECL(f,LONG_LONG,DLSTACK_PROTO) = cfunc->ptr; \ LONG_LONG ret; \ @@ -348,3 +348,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,float,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_PFUNC_CDECL(f,float,DLSTACK_PROTO) = cfunc->ptr; \ float ret; \ @@ -358,3 +358,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_CDECL(f,double,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_PFUNC_CDECL(f,double,DLSTACK_PROTO) = cfunc->ptr; \ double ret; \ @@ -375,3 +375,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_STDCALL(f,void,DLSTACK_PROTO##n) = cfunc->ptr; \ f(DLSTACK_ARGS##n(stack)); \ @@ -384,3 +384,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,void*,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_STDCALL(f,void*,DLSTACK_PROTO##n) = cfunc->ptr; \ void * ret; \ @@ -394,3 +394,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,char,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_STDCALL(f,char,DLSTACK_PROTO##n) = cfunc->ptr; \ char ret; \ @@ -404,3 +404,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,short,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_STDCALL(f,short,DLSTACK_PROTO##n) = cfunc->ptr; \ short ret; \ @@ -414,3 +414,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,int,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_STDCALL(f,int,DLSTACK_PROTO##n) = cfunc->ptr; \ int ret; \ @@ -424,3 +424,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,long,DLSTACK_PROTO##n) = cfunc->ptr; \ + DECL_PFUNC_STDCALL(f,long,DLSTACK_PROTO##n) = cfunc->ptr; \ long ret; \ @@ -435,3 +435,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,LONG_LONG,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_PFUNC_STDCALL(f,LONG_LONG,DLSTACK_PROTO) = cfunc->ptr; \ LONG_LONG ret; \ @@ -446,3 +446,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,float,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_PFUNC_STDCALL(f,float,DLSTACK_PROTO) = cfunc->ptr; \ float ret; \ @@ -456,3 +456,3 @@ rb_dlcfunc_call(VALUE self, VALUE ary) #define CASE(n) case n: { \ - DECL_FUNC_STDCALL(f,double,DLSTACK_PROTO) = cfunc->ptr; \ + DECL_PFUNC_STDCALL(f,double,DLSTACK_PROTO) = cfunc->ptr; \ double ret; \ Index: ext/dl/dl.h =================================================================== RCS file: /home/cvs/ruby/ext/dl/dl.h,v retrieving revision 1.13 diff -u -1 -p -r1.13 dl.h --- ext/dl/dl.h 5 Feb 2005 13:58:08 -0000 1.13 +++ ext/dl/dl.h 3 Jul 2006 12:03:23 -0000 @@ -182,2 +182,13 @@ VALUE rb_dlptr_malloc(long size, freefun +#if defined(__GNUC__) +# define DECL_FUNC_CDECL(f,ret,args) FUNC_CDECL(ret f(args)) +# define DECL_FUNC_STDCALL(f,ret,args) FUNC_STDCALL(ret f(args)) +/* # define DECL_FUNC(f,ret,args,calltype) ret (*f)(args) */ +#elif defined(_MSC_VER) || defined(__BORLANDC__) +# define DECL_FUNC_CDECL(f,ret,args) ret __cdecl f args +# define DECL_FUNC_STDCALL(f,ret,args) ret __stdcall f args +#else +# error "unsupported compiler." +#endif + #endif Index: ext/dl/mkcallback.rb =================================================================== RCS file: /home/cvs/ruby/ext/dl/mkcallback.rb,v retrieving revision 1.10 diff -u -1 -p -r1.10 mkcallback.rb --- ext/dl/mkcallback.rb 30 Jun 2006 18:05:34 -0000 1.10 +++ ext/dl/mkcallback.rb 3 Jul 2006 12:03:23 -0000 @@ -113,4 +113,3 @@ for calltype in CALLTYPES -FUNC_#{calltype.upcase}(static #{DLTYPE[ty][:type]} -#{func_name(ty,argc,n,calltype)}(#{(0...argc).collect{|i| "DLSTACK_TYPE stack" + i.to_s}.join(", ")})) +DECL_FUNC_#{calltype.upcase}(#{func_name(ty,argc,n,calltype)},static #{DLTYPE[ty][:type]},(#{(0...argc).collect{|i| "DLSTACK_TYPE stack" + i.to_s}.join(", ")})) { それでは。 -- U.Nakamura