From: nobu@... Date: 2005-04-29T17:01:12+09:00 Subject: [ruby-dev:26110] Re: check for function attribute なかだです。 At Fri, 29 Apr 2005 14:57:33 +0900, nobu@ruby-lang.org wrote in [ruby-dev:26109]: > 今rubyio.hではgcc 3.3以降のみ__attribute__を使ってDEPRECATED() > を定義していますが、同等のものがMicrosoft Visual C++ 7.0以降に > もあるようです。また、stdcallなど他のものにも対応できるはずです。 gccは知らない__attribute__でも警告を出すだけで通してしまうよう なので、こうしました。また、noinlineも使われているので追加しま した。 Index: configure.in =================================================================== RCS file: /cvs/ruby/src/ruby/configure.in,v retrieving revision 1.274 diff -U2 -p -r1.274 configure.in --- configure.in 20 Apr 2005 21:45:39 -0000 1.274 +++ configure.in 29 Apr 2005 07:48:24 -0000 @@ -264,14 +264,43 @@ if test "$rb_cv_stdarg" = yes; then fi -AC_CACHE_CHECK([for noreturn], rb_cv_noreturn, -[rb_cv_noreturn=x -for mac in "x __attribute__ ((noreturn))" "__declspec(noreturn) x" x; do +AC_DEFUN(RUBY_FUNC_ATTRIBUTE, [dnl +m4_ifval([$2], dnl + [AS_VAR_PUSHDEF([attrib],[$2])], dnl + [AS_VAR_PUSHDEF([attrib],[FUNC_]AS_TR_CPP($1))] dnl +)dnl +m4_ifval([$3], dnl + [AS_VAR_PUSHDEF([rbcv],[$3])], dnl + [AS_VAR_PUSHDEF([rbcv],[rb_cv_func_][$1])]dnl +)dnl +AC_CACHE_CHECK(for [$1] function attribute, rbcv, +[rbcv=x +if test "${ac_c_werror_flag+set}"; then + rb_c_werror_flag="$ac_c_werror_flag" +else + unset rb_c_werror_flag +fi +ac_c_werror_flag=yes +for mac in "x __attribute__ (($1))" "__declspec($1) x" x; do AC_TRY_COMPILE( - [#define NORETURN(x) $mac -NORETURN(void exit(int x));], - [], - [rb_cv_noreturn="$mac"; break]) -done]) -AC_DEFINE_UNQUOTED([NORETURN(x)], $rb_cv_noreturn) + [#define ]attrib[(x) $mac + ]attrib[(void conftest_attribute_check(void));], [], + [rbcv="$mac"; break]) +done +if test "${rb_c_werror_flag+set}"; then + ac_c_werror_flag="$rb_c_werror_flag" +else + unset ac_c_werror_flag +fi +]) +AC_DEFINE_UNQUOTED(attrib[(x)], $rbcv) +AS_VAR_POPDEF([attrib]) +AS_VAR_POPDEF([rbcv]) +]) + +RUBY_FUNC_ATTRIBUTE(noreturn, NORETURN) +RUBY_FUNC_ATTRIBUTE(deprecated, DEPRECATED) +RUBY_FUNC_ATTRIBUTE(noinline, NOINLINE) +RUBY_FUNC_ATTRIBUTE(stdcall) +RUBY_FUNC_ATTRIBUTE(cdecl) dnl Check whether we need to define sys_nerr locally Index: eval.c =================================================================== RCS file: /cvs/ruby/src/ruby/eval.c,v retrieving revision 1.775 diff -U2 -p -r1.775 eval.c --- eval.c 23 Apr 2005 02:45:38 -0000 1.775 +++ eval.c 29 Apr 2005 07:48:52 -0000 @@ -10256,8 +10256,6 @@ rb_thread_switch(n) NORETURN(static void rb_thread_restore_context _((rb_thread_t,int))); +NOINLINE(static void stack_extend _((rb_thread_t, int))); -# if _MSC_VER >= 1300 -__declspec(noinline) static void stack_extend(rb_thread_t, int); -# endif static void stack_extend(th, exit) Index: gc.c =================================================================== RCS file: /cvs/ruby/src/ruby/gc.c,v retrieving revision 1.197 diff -U2 -p -r1.197 gc.c --- gc.c 4 Mar 2005 06:47:43 -0000 1.197 +++ gc.c 29 Apr 2005 07:48:13 -0000 @@ -430,9 +430,6 @@ static unsigned int STACK_LEVEL_MAX = 65 #endif -#ifdef __GNUC__ -# if ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) || __GNUC__ > 3 -__attribute__ ((noinline)) -# endif -#endif +NOINLINE(static void set_stack_end _((VALUE **stack_end_p))); + static void set_stack_end(VALUE **stack_end_p) Index: ruby.h =================================================================== RCS file: /cvs/ruby/src/ruby/ruby.h,v retrieving revision 1.110 diff -U2 -p -r1.110 ruby.h --- ruby.h 2 Mar 2005 08:11:28 -0000 1.110 +++ ruby.h 29 Apr 2005 07:56:18 -0000 @@ -57,4 +57,10 @@ extern "C" { # define NORETURN(x) x #endif +#ifndef DEPRECATED +# define DEPRECATED(x) x +#endif +#ifndef NOINLINE +# define NOINLINE(x) x +#endif #if defined(HAVE_ALLOCA_H) Index: rubyio.h =================================================================== RCS file: /cvs/ruby/src/ruby/rubyio.h,v retrieving revision 1.37 diff -U2 -p -r1.37 rubyio.h --- rubyio.h 7 Feb 2005 14:18:40 -0000 1.37 +++ rubyio.h 29 Apr 2005 05:56:03 -0000 @@ -100,13 +100,4 @@ int rb_io_read_pending _((OpenFile*)); void rb_read_check _((FILE*)); -#ifdef __GNUC__ -# if ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) || __GNUC__ > 3 -# define DEPRECATED(x) x __attribute__ ((deprecated)) -# endif -#endif -#ifndef DEPRECATED -# define DEPRECATED(x) x -#endif - DEPRECATED(int rb_getc _((FILE*))); DEPRECATED(long rb_io_fread _((char *, long, FILE *))); Index: win32/Makefile.sub =================================================================== RCS file: /cvs/ruby/src/ruby/win32/Makefile.sub,v retrieving revision 1.92 diff -U2 -p -r1.92 Makefile.sub --- win32/Makefile.sub 27 Apr 2005 14:42:37 -0000 1.92 +++ win32/Makefile.sub 29 Apr 2005 07:54:19 -0000 @@ -221,4 +221,8 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/ #define NORETURN(x) __declspec(noreturn) x #endif +#if _MSC_VER >= 1300 +#define DEPRECATED(x) __declspec(deprecated) x +#define NOINLINE(x) __declspec(noinline) x +#endif #define HAVE_DECL_SYS_NERR 1 #define HAVE_LIMITS_H 1 Index: wince/Makefile.sub =================================================================== RCS file: /cvs/ruby/src/ruby/wince/Makefile.sub,v retrieving revision 1.36 diff -U2 -p -r1.36 Makefile.sub --- wince/Makefile.sub 20 Apr 2005 21:45:43 -0000 1.36 +++ wince/Makefile.sub 29 Apr 2005 07:49:47 -0000 @@ -224,4 +224,8 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/wince/ #define NORETURN(x) __declspec(noreturn) x #endif +#if _MSC_VER >= 1300 +#define DEPRECATED(x) __declspec(deprecated) x +#define NOINLINE(x) __declspec(noinline) x +#endif #define HAVE_DECL_SYS_NERR 1 #define HAVE_FCNTL_H 1 -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦