From b207e7cd1def68d729ef878dccac8974f0e5b753 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 12 May 2016 18:12:47 +0000 Subject: include/ruby/defines.h (GCC_VERSION_SINCE): moved from internal.h git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ gc.c | 3 +-- include/ruby/defines.h | 11 +++++++++-- include/ruby/ruby.h | 24 ++++++++++++------------ internal.h | 8 +------- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 27d415e4ff..e066b20fb9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri May 13 03:12:09 2016 NARUSE, Yui + + * include/ruby/defines.h (GCC_VERSION_SINCE): moved from internal.h. + Fri May 13 03:11:20 2016 NARUSE, Yui * configure.in (__builtin_constant_p): check. diff --git a/gc.c b/gc.c index 0f1bbc7305..ebfb037c1e 100644 --- a/gc.c +++ b/gc.c @@ -947,8 +947,7 @@ tick(void) return ((unsigned long long)lo)|( ((unsigned long long)hi)<<32); } -#elif defined(__powerpc64__) && \ - (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) +#elif defined(__powerpc64__) && GCC_VERSION_SINCE(4,8,0) typedef unsigned long long tick_t; #define PRItick "llu" diff --git a/include/ruby/defines.h b/include/ruby/defines.h index 74678c34ab..742017ebaf 100644 --- a/include/ruby/defines.h +++ b/include/ruby/defines.h @@ -46,6 +46,13 @@ extern "C" { # define NOINLINE(x) x #endif +#define GCC_VERSION_SINCE(major, minor, patchlevel) \ + (defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__) && \ + ((__GNUC__ > (major)) || \ + ((__GNUC__ == (major) && \ + (__GNUC_MINOR__ > (minor)) || \ + (__GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel)))))) + /* likely */ #if __GNUC__ >= 3 #define RB_LIKELY(x) (__builtin_expect(!!(x), 1)) @@ -152,8 +159,8 @@ RUBY_SYMBOL_EXPORT_BEGIN #define xrealloc2 ruby_xrealloc2 #define xfree ruby_xfree -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) -# define RUBY_ATTR_ALLOC_SIZE(params) __attribute__ ((__alloc_size__ params)) +#if GCC_VERSION_SINCE(4,3,0) +# deine RUBY_ATTR_ALLOC_SIZE(params) __attribute__ ((__alloc_size__ params)) #else # define RUBY_ATTR_ALLOC_SIZE(params) #endif diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index c7b1f41a7f..a05522d309 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -565,7 +565,7 @@ void rb_check_safe_obj(VALUE); StringValue(v);\ rb_check_safe_obj(v);\ } while (0) -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +#if GCC_VERSION_SINCE(4,4,0) void rb_check_safe_str(VALUE) __attribute__((error("rb_check_safe_str() and Check_SafeStr() are obsolete; use SafeStringValue() instead"))); # define Check_SafeStr(v) rb_check_safe_str((VALUE)(v)) #else @@ -590,32 +590,32 @@ VALUE rb_get_path_no_checksafe(VALUE); void rb_secure(int); int rb_safe_level(void); void rb_set_safe_level(int); -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +#if GCC_VERSION_SINCE(4,4,0) int ruby_safe_level_2_error(void) __attribute__((error("$SAFE=2 to 4 are obsolete"))); int ruby_safe_level_2_warning(void) __attribute__((const,warning("$SAFE=2 to 4 are obsolete"))); # ifdef RUBY_EXPORT # define ruby_safe_level_2_warning() ruby_safe_level_2_error() # endif -#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) -# define RUBY_SAFE_LEVEL_INVALID_P(level) \ +# if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +# define RUBY_SAFE_LEVEL_INVALID_P(level) \ __extension__(\ __builtin_choose_expr(\ __builtin_constant_p(level), \ ((level) < 0 || RUBY_SAFE_LEVEL_MAX < (level)), 0)) -# define RUBY_SAFE_LEVEL_CHECK(level, type) \ +# define RUBY_SAFE_LEVEL_CHECK(level, type) \ __extension__(__builtin_choose_expr(RUBY_SAFE_LEVEL_INVALID_P(level), ruby_safe_level_2_##type(), (level))) -#else +# else /* in gcc 4.8 or earlier, __builtin_choose_expr() does not consider * __builtin_constant_p(variable) a constant expression. */ -# define RUBY_SAFE_LEVEL_INVALID_P(level) \ +# define RUBY_SAFE_LEVEL_INVALID_P(level) \ __extension__(__builtin_constant_p(level) && \ ((level) < 0 || RUBY_SAFE_LEVEL_MAX < (level))) -# define RUBY_SAFE_LEVEL_CHECK(level, type) \ +# define RUBY_SAFE_LEVEL_CHECK(level, type) \ (RUBY_SAFE_LEVEL_INVALID_P(level) ? ruby_safe_level_2_##type() : (level)) -#endif -#define rb_secure(level) rb_secure(RUBY_SAFE_LEVEL_CHECK(level, warning)) -#define rb_set_safe_level(level) rb_set_safe_level(RUBY_SAFE_LEVEL_CHECK(level, error)) +# endif +# define rb_secure(level) rb_secure(RUBY_SAFE_LEVEL_CHECK(level, warning)) +# define rb_set_safe_level(level) rb_set_safe_level(RUBY_SAFE_LEVEL_CHECK(level, error)) #endif void rb_set_safe_level_force(int); CONSTFUNC(void rb_secure_update(VALUE)); @@ -1335,7 +1335,7 @@ rb_obj_freeze_inline(VALUE x) } } -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +#if GCC_VERSION_SINCE(4,4,0) # define RUBY_UNTYPED_DATA_FUNC(func) func __attribute__((warning("untyped Data is unsafe; use TypedData instead"))) #else # define RUBY_UNTYPED_DATA_FUNC(func) DEPRECATED(func) diff --git a/internal.h b/internal.h index 001a385a69..78ae77d806 100644 --- a/internal.h +++ b/internal.h @@ -40,7 +40,7 @@ extern "C" { #if __has_attribute(__warn_unused_result__) #define WARN_UNUSED_RESULT(x) x __attribute__((__warn_unused_result__)) -#elif defined(__GNUC__) && (__GNUC__ * 1000 + __GNUC_MINOR__) >= 3004 +#elif GCC_VERSION_SINCE(3,4,0) #define WARN_UNUSED_RESULT(x) x __attribute__((__warn_unused_result__)) #else #define WARN_UNUSED_RESULT(x) x @@ -61,12 +61,6 @@ extern "C" { #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0]))) -#define GCC_VERSION_SINCE(major, minor, patchlevel) \ - (defined(__GNUC__) && !defined(__INTEL_COMPILER) && \ - ((__GNUC__ > (major)) || \ - (__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \ - (__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel)))) - #ifndef __has_feature # define __has_feature(x) 0 #endif -- cgit v1.2.3