1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2014-10-10 14:20:20 +00:00
parent 50b78ebb98
commit 97d3b04c9b
2 changed files with 18 additions and 4 deletions

View file

@ -2110,7 +2110,7 @@ main(int argc, char **argv)
AC_DEFUN([RUBY_CHECK_BUILTIN_FUNC], [dnl
AC_CACHE_CHECK([for $1], AS_TR_SH(rb_cv_builtin_$1),
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM([], [$2;])],
[AC_LANG_PROGRAM([int foo;], [$2;])],
[AS_TR_SH(rb_cv_builtin_$1)=yes],
[AS_TR_SH(rb_cv_builtin_$1)=no])])
if test "${AS_TR_SH(rb_cv_builtin_$1)}" != no; then
@ -2123,6 +2123,7 @@ RUBY_CHECK_BUILTIN_FUNC(__builtin_clz, [__builtin_clz(0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_clzl, [__builtin_clzl(0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_clzll, [__builtin_clzll(0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_choose_expr, [__builtin_choose_expr(0, 0, 0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_choose_expr_constant_p, [__builtin_choose_expr(__builtin_constant_p(foo), 0, 0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_types_compatible_p, [__builtin_types_compatible_p(int, int)])
if test "$ac_cv_func_qsort_r" != no; then

View file

@ -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