[patch] do not use `exit' in tests
Upcoming Autoconf-2.60 will not provide a declaration for exit; it has turned out that tracking MSVC incompatibilites here is a lot of work. Instead, returning from main is suggested as a viable alternative (the systems where that was not portable are not likely to be used any more). The following patch does that for the macros in CLN. Cheers, Ralf * m4/longdouble.m4 (CL_LONGDOUBLE): `return', rather than `exit' from main. * m4/longlong.m4 (CL_LONGLONG): Likewise. * m4/times.m4 (CL_TIMES_CLOCK): Likewise. * m4/general.m4 (CL_CC_WORKS): Likewise, do this for a C test to work when users set `$CC' to a C++ compiler. Index: m4/general.m4 =================================================================== RCS file: /home/cvs/cln/m4/general.m4,v retrieving revision 1.1 diff -u -r1.1 general.m4 --- m4/general.m4 29 Aug 2005 13:18:40 -0000 1.1 +++ m4/general.m4 11 Apr 2006 10:04:22 -0000 @@ -93,7 +93,7 @@ [AC_CACHE_CHECK(whether CC works at all, cl_cv_prog_cc_works, [ AC_LANG_SAVE() AC_LANG_C() -AC_TRY_RUN([int main() { exit(0); }], +AC_TRY_RUN([int main() { return 0; }], cl_cv_prog_cc_works=yes, cl_cv_prog_cc_works=no, AC_TRY_LINK([], [], cl_cv_prog_cc_works=yes, cl_cv_prog_cc_works=no)) AC_LANG_RESTORE() Index: m4/longdouble.m4 =================================================================== RCS file: /home/cvs/cln/m4/longdouble.m4,v retrieving revision 1.1 diff -u -r1.1 longdouble.m4 --- m4/longdouble.m4 29 Aug 2005 13:18:40 -0000 1.1 +++ m4/longdouble.m4 11 Apr 2006 10:04:22 -0000 @@ -12,7 +12,7 @@ AC_DEFUN([CL_LONGDOUBLE], [AC_CACHE_CHECK(for long double type, cl_cv_c_longdouble, [ AC_TRY_RUN([int main() -{ long double x = 2.7182818284590452354L; x = x*x; exit (x==0.0L); }], +{ long double x = 2.7182818284590452354L; x = x*x; return x==0.0L; }], cl_cv_c_longdouble=yes, cl_cv_c_longdouble=no, [ dnl When cross-compiling, use the test from gnulib. AC_TRY_COMPILE([ Index: m4/longlong.m4 =================================================================== RCS file: /home/cvs/cln/m4/longlong.m4,v retrieving revision 1.1 diff -u -r1.1 longlong.m4 --- m4/longlong.m4 29 Aug 2005 13:18:40 -0000 1.1 +++ m4/longlong.m4 11 Apr 2006 10:04:22 -0000 @@ -19,11 +19,11 @@ miscompiled. */ #if defined(__m68k__) || (defined(_IBMR2) || defined(__powerpc)) #if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ <= 7) - exit(1); + return 1; #endif #endif { long x = 944938507; long y = 737962842; long z = 162359677; - exit(!(((long long) x)*((long long) y)>>32 == z)); + return !(((long long) x)*((long long) y)>>32 == z); } }], cl_cv_c_longlong=yes, cl_cv_c_longlong=no, [ Index: m4/times.m4 =================================================================== RCS file: /home/cvs/cln/m4/times.m4,v retrieving revision 1.1 diff -u -r1.1 times.m4 --- m4/times.m4 29 Aug 2005 13:18:40 -0000 1.1 +++ m4/times.m4 11 Apr 2006 10:04:22 -0000 @@ -29,12 +29,12 @@ clock_t result2; int ticks; result1 = times(&buffer); - if ((result1 == (clock_t)0) || (result1 == (clock_t)(-1))) exit(1); + if ((result1 == (clock_t)0) || (result1 == (clock_t)(-1))) return 1; sleep(1); result2 = times(&buffer); - if ((result2 == (clock_t)0) || (result2 == (clock_t)(-1))) exit(1); + if ((result2 == (clock_t)0) || (result2 == (clock_t)(-1))) return 1; ticks = result2 - result1; - exit(!((ticks >= CLK_TCK/2) && (ticks <= 3*CLK_TCK/2))); + return !((ticks >= CLK_TCK/2) && (ticks <= 3*CLK_TCK/2)); }], cl_cv_func_times_return=yes, cl_cv_func_times_return=no, dnl When cross-compiling, don't assume anything. cl_cv_func_times_return="guessing no")
Ralf Wildenhues wrote:
Upcoming Autoconf-2.60 will not provide a declaration for exit; it has turned out that tracking MSVC incompatibilites here is a lot of work. Instead, returning from main is suggested as a viable alternative (the systems where that was not portable are not likely to be used any more).
CLN is meant to run only on modern systems, where the <stdlib.h> file is made compatible for C++. Therefore, and because 'return' is more restricted than 'exit' (it can only be used in the main() function, not in other functions invoked by main()), I'm changing CLN to simply do a #include <stdlib.h> where needed. Thanks for reporting the problem. Bruno 2006-04-19 Bruno Haible <bruno@clisp.org> Prepare for autoconf-2.60. * general.m4 (CL_CC_WORKS): Include <stdlib.h>, for exit() declaration. * longdouble.m4 (CL_LONGDOUBLE): Likewise. * longlong.m4 (CL_LONGLONG): Likewise. * times.m4 (CL_TIMES_CLOCK): Likewise. Reported by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>. diff -c -3 -r1.1 general.m4 *** m4/general.m4 29 Aug 2005 13:18:40 -0000 1.1 --- m4/general.m4 19 Apr 2006 16:09:53 -0000 *************** *** 93,99 **** [AC_CACHE_CHECK(whether CC works at all, cl_cv_prog_cc_works, [ AC_LANG_SAVE() AC_LANG_C() ! AC_TRY_RUN([int main() { exit(0); }], cl_cv_prog_cc_works=yes, cl_cv_prog_cc_works=no, AC_TRY_LINK([], [], cl_cv_prog_cc_works=yes, cl_cv_prog_cc_works=no)) AC_LANG_RESTORE() --- 93,102 ---- [AC_CACHE_CHECK(whether CC works at all, cl_cv_prog_cc_works, [ AC_LANG_SAVE() AC_LANG_C() ! AC_TRY_RUN([ ! #include <stdlib.h> ! int main() { exit(0); } ! ], cl_cv_prog_cc_works=yes, cl_cv_prog_cc_works=no, AC_TRY_LINK([], [], cl_cv_prog_cc_works=yes, cl_cv_prog_cc_works=no)) AC_LANG_RESTORE() diff -c -3 -r1.1 longdouble.m4 *** m4/longdouble.m4 29 Aug 2005 13:18:40 -0000 1.1 --- m4/longdouble.m4 19 Apr 2006 16:09:53 -0000 *************** *** 11,18 **** AC_DEFUN([CL_LONGDOUBLE], [AC_CACHE_CHECK(for long double type, cl_cv_c_longdouble, [ ! AC_TRY_RUN([int main() ! { long double x = 2.7182818284590452354L; x = x*x; exit (x==0.0L); }], cl_cv_c_longdouble=yes, cl_cv_c_longdouble=no, [ dnl When cross-compiling, use the test from gnulib. AC_TRY_COMPILE([ --- 11,21 ---- AC_DEFUN([CL_LONGDOUBLE], [AC_CACHE_CHECK(for long double type, cl_cv_c_longdouble, [ ! AC_TRY_RUN([ ! #include <stdlib.h> ! int main() ! { long double x = 2.7182818284590452354L; x = x*x; exit (x==0.0L); } ! ], cl_cv_c_longdouble=yes, cl_cv_c_longdouble=no, [ dnl When cross-compiling, use the test from gnulib. AC_TRY_COMPILE([ diff -c -3 -r1.1 longlong.m4 *** m4/longlong.m4 29 Aug 2005 13:18:40 -0000 1.1 --- m4/longlong.m4 19 Apr 2006 16:09:53 -0000 *************** *** 12,18 **** AC_DEFUN([CL_LONGLONG], [AC_CACHE_CHECK(for long long type, cl_cv_c_longlong, [ ! AC_TRY_RUN([int main() { /* long longs don't work right with gcc-2.7.2 on m68k */ /* long longs don't work right with gcc-2.7.2 on rs6000: avcall/tests.c gets --- 12,20 ---- AC_DEFUN([CL_LONGLONG], [AC_CACHE_CHECK(for long long type, cl_cv_c_longlong, [ ! AC_TRY_RUN([ ! #include <stdlib.h> ! int main() { /* long longs don't work right with gcc-2.7.2 on m68k */ /* long longs don't work right with gcc-2.7.2 on rs6000: avcall/tests.c gets diff -c -3 -r1.1 times.m4 *** m4/times.m4 29 Aug 2005 13:18:40 -0000 1.1 --- m4/times.m4 19 Apr 2006 16:09:53 -0000 *************** *** 17,22 **** --- 17,23 ---- if test -z "$no_times"; then AC_CACHE_CHECK(for times return value, cl_cv_func_times_return, [ AC_TRY_RUN([ + #include <stdlib.h> /* needed for exit() */ #include <sys/types.h> #include <time.h> /* needed for CLK_TCK */ #ifndef CLK_TCK
participants (2)
-
Bruno Haible
-
Ralf Wildenhues