From 01051a9879fcd353eaf0d3788a911e774b52798c Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 9 Jul 2015 11:38:34 +0300 Subject: [PATCH] Use AS_IF rather than plain shell "if" in pthread-check. Autoconf generates additional code for the first AC_CHECK_HEADERS call in the script. If the first call is within an if-block, the additional code is put inside the if-block too, even though it is needed by subsequent AC_CHECK_HEADERS checks and should always be executed. When I moved the pthread-related checks earlier in the script, the pthread.h test inside the block became the very first AC_CHECK_HEADERS call in the script, triggering that problem. To fix, use AS_IF instead of plain shell if. AS_IF knows about that issue, and makes sure the additional code is always executed. To be completely safe from this issue (and others), we should always be using AS_IF instead of plain if, but that seems like excessive caution given that this is the first time we have trouble like this. Plain if-then is more readable than AS_IF. This should fix compilation with --disable-thread-safety, and hopefully the buildfarm failure on forgmouth, related to mingw standard headers, too. I backpatched the previous fixes to 9.5, but it's starting to look like these changes are too fiddly to backpatch, so commit this to master only, and revert all the pthread-related configure changes in 9.5. --- configure | 273 ++++++++++++++++++++++++++------------------------- configure.in | 14 ++- 2 files changed, 149 insertions(+), 138 deletions(-) diff --git a/configure b/configure index 2a9a0ff18e..77048e8593 100755 --- a/configure +++ b/configure @@ -7626,7 +7626,142 @@ fi # other libraries can pull in the pthread functions as a side-effect. We # want to use the -pthread or similar flags directly, and not rely on # the side-effects of linking with some other library. -if test "$enable_thread_safety" = yes -a "$PORTNAME" != "win32"; then +# +# note: We have to use AS_IF here rather than plain if. The AC_CHECK_HEADER +# invocation below is the first one in the script, and autoconf generates +# additional code for that, which must not be inside the if-block. AS_IF +# knows how to do that. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +if test "$enable_thread_safety" = yes -a "$PORTNAME" != "win32"; then : + # then ac_ext=c @@ -8081,136 +8216,6 @@ _LIBS="$LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" LIBS="$LIBS $PTHREAD_LIBS" -if test "$PORTNAME" != "win32"; then -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 -$as_echo_n "checking for ANSI C header files... " >&6; } -if ${ac_cv_header_stdc+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -#include -#include -#include - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_header_stdc=yes -else - ac_cv_header_stdc=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "memchr" >/dev/null 2>&1; then : - -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "free" >/dev/null 2>&1; then : - -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then : - : -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -#include -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) \ - (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - return 2; - return 0; -} -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - -else - ac_cv_header_stdc=no -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - -fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 -$as_echo "$ac_cv_header_stdc" >&6; } -if test $ac_cv_header_stdc = yes; then - -$as_echo "#define STDC_HEADERS 1" >>confdefs.h - -fi - -# On IRIX 5.3, sys/types and inttypes.h are conflicting. -for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ - inttypes.h stdint.h unistd.h -do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default -" -if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - ac_fn_c_check_header_mongrel "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default" if test "x$ac_cv_header_pthread_h" = xyes; then : @@ -8220,7 +8225,6 @@ pthread.h not found; use --disable-thread-safety to disable thread safety" "$LI fi -fi for ac_func in strerror_r getpwuid_r gethostbyname_r do : @@ -8276,11 +8280,14 @@ fi CFLAGS="$_CFLAGS" LIBS="$_LIBS" + else + # else # do not use values from template file PTHREAD_CFLAGS= PTHREAD_LIBS= -fi + +fi # fi diff --git a/configure.in b/configure.in index a7eec7f6e8..5724a4df07 100644 --- a/configure.in +++ b/configure.in @@ -961,7 +961,13 @@ fi # other libraries can pull in the pthread functions as a side-effect. We # want to use the -pthread or similar flags directly, and not rely on # the side-effects of linking with some other library. -if test "$enable_thread_safety" = yes -a "$PORTNAME" != "win32"; then +# +# note: We have to use AS_IF here rather than plain if. The AC_CHECK_HEADER +# invocation below is the first one in the script, and autoconf generates +# additional code for that, which must not be inside the if-block. AS_IF +# knows how to do that. +AS_IF([test "$enable_thread_safety" = yes -a "$PORTNAME" != "win32"], +[ # then AX_PTHREAD # set thread flags # Some platforms use these, so just define them. They can't hurt if they @@ -975,10 +981,8 @@ _LIBS="$LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" LIBS="$LIBS $PTHREAD_LIBS" -if test "$PORTNAME" != "win32"; then AC_CHECK_HEADER(pthread.h, [], [AC_MSG_ERROR([ pthread.h not found; use --disable-thread-safety to disable thread safety])]) -fi AC_CHECK_FUNCS([strerror_r getpwuid_r gethostbyname_r]) @@ -988,11 +992,11 @@ PGAC_FUNC_STRERROR_R_INT CFLAGS="$_CFLAGS" LIBS="$_LIBS" -else +], [ # else # do not use values from template file PTHREAD_CFLAGS= PTHREAD_LIBS= -fi +]) # fi AC_SUBST(PTHREAD_CFLAGS) AC_SUBST(PTHREAD_LIBS)