ruby-changes:35785
From: nobu <ko1@a...>
Date: Fri, 10 Oct 2014 23:20:33 +0900 (JST)
Subject: [ruby-changes:35785] nobu:r47867 (trunk): ruby/ruby.h: fix for older gcc
nobu 2014-10-10 23:20:20 +0900 (Fri, 10 Oct 2014) New Revision: 47867 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47867 Log: 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. Modified files: trunk/configure.in trunk/include/ruby/ruby.h Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 47866) +++ include/ruby/ruby.h (revision 47867) @@ -564,11 +564,24 @@ int ruby_safe_level_4_warning(void) __at https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L564 # 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 Index: configure.in =================================================================== --- configure.in (revision 47866) +++ configure.in (revision 47867) @@ -2110,7 +2110,7 @@ main(int argc, char **argv) https://github.com/ruby/ruby/blob/trunk/configure.in#L2110 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, [ https://github.com/ruby/ruby/blob/trunk/configure.in#L2123 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/