autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

91-c++-exit-decl.patch


From: Akim Demaille
Subject: 91-c++-exit-decl.patch
Date: Sat, 23 Dec 2000 09:32:57 +0100

Here is my proposal for the `exit++' problem.  I'm not fluent enough
in portable C++ to know if the order in which the possibilities are
tested is right or not, Alexandre will know better, but I wrote it
from most specific to least specific.  I do not include stdlib.h, I
keep only a declaration of exit which is compatible so that the user
can include or not include stdlib.h without any risk of conflict or
lack of prototype.

I ran the testsuite with CC=g++ on my machine, with 100% success using
G++ 2.95.2. config.log reveals that it chose this:

   #ifdef __cplusplus
   extern "C" void std::exit (int) throw (); using std::exit;
   #endif

I'm not sure I will be able to apply this patch.  If it is approved,
don't hesitate to apply it, or to fix and apply it.

Cheers,

        Akim

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * aclang.m4 (_AC_PROG_CXX_EXIT_DECLARATION): New.
        (AC_PROG_CC, AC_PROG_CXX): Use it.
        (AC_PROG_CC_STDC): Be sure to remove tmp files.
        * tests/compile.at (AC_TRY_LINK_FUNC): Don't use exit to test it,
        since it produces a prototype which conflicts with the one
        computed by _AC_PROG_CXX_EXIT_DECLARATION.
        * tests/semantics.at (AC_CHECK_FUNCS, AC_HAVE_FUNCS): Likewise.
        (AC_HAVE_FUNCS): Test AC_HAVE_FUNCS!

Index: TODO
--- TODO Sun, 12 Nov 2000 15:44:01 +0100 akim (ace/29_TODO 1.59 644)
+++ TODO Sat, 23 Dec 2000 09:40:32 +0100 akim (ace/29_TODO 1.59 644)
@@ -40,6 +40,12 @@
 Chose a means to declare patterns to catch, means to escape the
 control, and document it.

+** AC_CHECK_FUNCS and AC_TRY_LINK_FUNC
+I have still not understood what's the difference  between the two
+which requires to have two different sources: AC_LANG_CALL and
+AC_LANG_FUNC_LINK_TRY (which names seem to be inappropriate).
+Wouldn't one be enough?
+
 * Autoconf 2.51 or so

 ** AC_FUNC_GETLOADAVG
Index: aclang.m4
--- aclang.m4 Fri, 22 Dec 2000 19:21:09 +0100 akim (ace/b/32_aclang.m4 1.5.3.63 
644)
+++ aclang.m4 Sat, 23 Dec 2000 09:41:30 +0100 akim (ace/b/32_aclang.m4 1.5.3.63 
644)
@@ -405,7 +405,7 @@ m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
 # We need `stdio.h' to open a `FILE', so the prologue defaults to the
 # inclusion of `stdio.h'.
 m4_define([AC_LANG_INT_SAVE(C)],
-[AC_LANG_PROGRAM([m4_default([$1], address@hidden:@include "stdio.h"])],
+[AC_LANG_PROGRAM([m4_default([$1], address@hidden:@include <stdio.h>])],
 [FILE *f = fopen ("conftestval", "w");
 if (!f)
   exit (1);
@@ -419,42 +419,31 @@ m4_define([AC_LANG_INT_SAVE(C)],

 # AC_LANG_SOURCE(C++)(BODY)
 # -------------------------
-m4_define([AC_LANG_SOURCE(C++)],
-[#line __oline__ "configure"
-#include "confdefs.h"
-#ifdef __cplusplus
-extern "C" void exit (int);
-#endif
-$1])
+m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(C++)])


 # AC_LANG_PROGRAM(C++)([PROLOGUE], [BODY])
 # ----------------------------------------
-# Same as C.
 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(C++)])


 # AC_LANG_CALL(C++)(PROLOGUE, FUNCTION)
 # -------------------------------------
-# Same as C.
 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(C++)])


 # AC_LANG_FUNC_LINK_TRY(C++)(FUNCTION)
 # ------------------------------------
-# Same as C.
 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(C++)])


 # AC_LANG_BOOL_COMPILE_TRY(C++)(PROLOGUE, EXPRESSION)
 # ---------------------------------------------------
-# Same as C.
 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(C++)])


 # AC_LANG_INT_SAVE(C++)(PROLOGUE, EXPRESSION)
 # -------------------------------------------
-# Same as C.
 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(C++)])


@@ -879,6 +868,14 @@ AC_DEFUN([AC_PROG_CC],
 AC_EXPAND_ONCE([_AC_COMPILER_OBJEXT])[]dnl
 AC_EXPAND_ONCE([_AC_COMPILER_EXEEXT])[]dnl
 _AC_PROG_CC_G
+# Some people use a C++ compiler to compile C.  Since we use `exit',
+# in C++ we need to quote it.  In case someone uses the same compiler
+# for both compiling C and C++ we need to have the C++ compiler decide
+# the declaration of exit, since it's the most requiring environment.
+_AC_COMPILE_IFELSE(address@hidden:@ifndef __cplusplus
+  choke me
address@hidden:@endif],
+                   [_AC_PROG_CXX_EXIT_DECLARATION])
 AC_LANG_POP
 ])# AC_PROG_CC

@@ -987,7 +984,6 @@ AC_DEFUN([AC_PROG_CC_C_O],
 ])# AC_PROG_CC_C_O


-
 # ---------------------- #
 # 3c. The C++ compiler.  #
 # ---------------------- #
@@ -1076,6 +1072,7 @@ AC_DEFUN([AC_PROG_CXX],
 AC_EXPAND_ONCE([_AC_COMPILER_OBJEXT])[]dnl
 AC_EXPAND_ONCE([_AC_COMPILER_EXEEXT])[]dnl
 _AC_PROG_CXX_G
+_AC_PROG_CXX_EXIT_DECLARATION
 AC_LANG_POP
 ])# AC_PROG_CXX

@@ -1111,6 +1108,36 @@ m4_define([_AC_PROG_CXX_G],
 ])# _AC_PROG_CXX_G


+# _AC_PROG_CXX_EXIT_DECLARATION
+# -----------------------------
+# Find a valid prototype for exit and declare it in confdefs.h.
+m4_define([_AC_PROG_CXX_EXIT_DECLARATION],
+[for ac_include in \
+   '#include <cstdlib>
+#include <stdlib.h>' \
+   '#include <cstdlib>' \
+   '#include <stdlib.h>' \
+   ''
+do
+  for ac_declaration in \
+     'extern "C" void std::exit (int) throw (); using std::exit;' \
+     'extern "C" void std::exit (int); using std::exit;' \
+     'extern "C" void exit (int) throw ();' \
+     'extern "C" void exit (int);' \
+     'void exit (int);' \
+     ''
+  do
+    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$ac_include
+$ac_declaration],
+                                         [exit (42);])],
+                       [break 2])
+  done
+done
+echo '#ifdef __cplusplus' >>confdefs.h
+echo $ac_declaration      >>confdefs.h
+echo '#endif'             >>confdefs.h
+])# _AC_PROG_CXX_EXIT_DECLARATION
+

 # ----------------------------- #
 # 3d. The Fortran 77 compiler.  #
@@ -1317,9 +1344,9 @@ AC_DEFUN([AC_PROG_CC_STDC],
   CC="$ac_save_CC $ac_arg"
   AC_COMPILE_IFELSE([],
                     [ac_cv_prog_cc_stdc=$ac_arg
-rm -f conftest.$ac_ext conftest.$ac_objext
 break])
 done
+rm -f conftest.$ac_ext conftest.$ac_objext
 CC=$ac_save_CC
 ])
 case "x$ac_cv_prog_cc_stdc" in
Index: tests/compile.at
--- tests/compile.at Fri, 22 Dec 2000 18:31:03 +0100 akim (ace/b/50_compile.at 
1.6 644)
+++ tests/compile.at Sat, 23 Dec 2000 09:34:29 +0100 akim (ace/b/50_compile.at 
1.6 644)
@@ -109,8 +109,8 @@
 ## ------------------ ##

 AT_CHECK_MACRO([AC_TRY_LINK_FUNC],
-[AC_TRY_LINK_FUNC(exit,,
-                  [AC_MSG_ERROR([cannot find `exit'])])
+[AC_TRY_LINK_FUNC(printf,,
+                  [AC_MSG_ERROR([cannot find `printf'])])
 AC_TRY_LINK_FUNC(Be_doomed_if_your_libc_has_a_function_named_like_this,
                  [AC_MSG_ERROR([found a nonexistent function])])])

Index: tests/semantics.at
--- tests/semantics.at Sun, 17 Dec 2000 10:45:11 +0100 akim 
(ace/b/25_semantics. 1.30 644)
+++ tests/semantics.at Sat, 23 Dec 2000 09:38:44 +0100 akim 
(ace/b/25_semantics. 1.30 644)
@@ -38,12 +38,12 @@
 # AC_CHECK_FUNCS
 # --------------
 # Check that it performs the correct actions:
-# Must define HAVE_EXIT, but not HAVE_AUTOCONF_TIXE
+# Must define HAVE_PRINTF, but not HAVE_AUTOCONF_FTNIRP
 AT_CHECK_MACRO([AC_CHECK_FUNCS],
-[AC_CHECK_FUNCS(exit autoconf_tixe)],
+[AC_CHECK_FUNCS(printf autoconf_ftnirp)],
 [AT_CHECK_DEFINES(
-[/* #undef HAVE_AUTOCONF_TIXE */
-#define HAVE_EXIT 1
+[/* #undef HAVE_AUTOCONF_FTNIRP */
+#define HAVE_PRINTF 1
 ])])


@@ -52,10 +52,10 @@
 # This macro is an obsolete version of AC_CHECK_FUNCS.  Running this
 # test allows to check that AU_ALIAS'ed macros work properly.
 AT_CHECK_MACRO([AC_HAVE_FUNCS],
-[AC_CHECK_FUNCS(exit autoconf_tixe)],
+[AC_HAVE_FUNCS(printf autoconf_ftnirp)],
 [AT_CHECK_DEFINES(
-[/* #undef HAVE_AUTOCONF_TIXE */
-#define HAVE_EXIT 1
+[/* #undef HAVE_AUTOCONF_FTNIRP */
+#define HAVE_PRINTF 1
 ])])



reply via email to

[Prev in Thread] Current Thread [Next in Thread]