summaryrefslogtreecommitdiff
path: root/include/ruby/ruby.h
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-10 14:20:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-10 14:20:20 +0000
commit97d3b04c9b4ac50f9110001a772d59590a6f6274 (patch)
treed157ceda039154a8d2859bbdad2f859bb999c7ba /include/ruby/ruby.h
parent50b78ebb982b9e3e3639967c27786557aa5faf14 (diff)
ruby/ruby.h: fix for older gcc
* configure.in (__builtin_choose_expr_constant_p): in gcc 4.8 or earlier, __builtin_choose_expr() does not consider __builtin_constant_p(variable) a constant expression. * include/ruby/ruby.h (RUBY_SAFE_LEVEL_CHECK): fix for older gcc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include/ruby/ruby.h')
-rw-r--r--include/ruby/ruby.h19
1 files changed, 16 insertions, 3 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index dbea8e4c67..539c1b3f63 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -564,11 +564,24 @@ int ruby_safe_level_4_warning(void) __attribute__((warning("$SAFE=4 is obsolete"
# ifdef RUBY_EXPORT
# define ruby_safe_level_4_warning() ruby_safe_level_4_error()
# endif
-#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) \
+ __extension__(__builtin_choose_expr(RUBY_SAFE_LEVEL_INVALID_P(level), ruby_safe_level_4_##type(), (level)))
+#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) \
__extension__(__builtin_constant_p(level) && \
((level) < 0 || RUBY_SAFE_LEVEL_MAX < (level)))
-#define RUBY_SAFE_LEVEL_CHECK(level, type) \
- __extension__(__builtin_choose_expr(RUBY_SAFE_LEVEL_INVALID_P(level), ruby_safe_level_4_##type(), (level)))
+# define RUBY_SAFE_LEVEL_CHECK(level, type) \
+ (RUBY_SAFE_LEVEL_INVALID_P(level) ? ruby_safe_level_4_##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