[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: _Exit detection
From: |
Bruno Haible |
Subject: |
Re: _Exit detection |
Date: |
Mon, 12 Jul 2010 18:56:28 +0200 |
User-agent: |
KMail/1.9.9 |
Thien-Thi Nguyen wrote:
> GNU RCS uses gnulib module ‘stdlib’, which AFAICT does not
> detect missing ‘_Exit’, e.g., when using dietlibc:
>
> https://savannah.gnu.org/bugs/?30372
>
> I am unsure where/how to fix this and would be grateful for any tips.
> Specifically:
>
> - Is this something gnulib can/should handle?
Yes, it could do this. gnulib/doc/posix-functions/_Exit_C99.texi lists
the known platform on which this function is missing. The glibc documentation
says:
@deftypefun void _Exit (int @var{status})
The @code{_Exit} function is the @w{ISO C} equivalent to @code{_exit}.
The @w{ISO C} committee members were not sure whether the definitions of
@code{_exit} and @code{_Exit} were compatible so they have not used the
POSIX name.
> - If not, what is the best (gnulib-compatible)
> way to detect missing ‘_Exit’?
AC_CHECK_FUNCS([_Exit])
And if it's not present, include <unistd.h> and do
#define _Exit _exit
But now, I'm adding the module '_Exit'. So all you have to do is to request
this module.
> - Moving laterally, is it poor style to use ‘_Exit’
> (as opposed to plain old ‘_exit’) in the first place?
No, either style is fine. When you use _Exit, you adhere to the ISO C 99
standard; when you use _exit, you use the POSIX standard.
Bruno
2010-07-12 Bruno Haible <address@hidden>
New module '_Exit'.
* lib/stdlib.in.h (__attribute__): New macro.
(_Exit): New declaration.
* lib/_Exit.c: New file.
* m4/_Exit.m4: New file.
* m4/stdlib_h.m4 (gl_STDLIB_H): Check whether _Exit is declared.
(gl_STDLIB_H_DEFAULTS): Initialize GNULIB__EXIT and HAVE__EXIT.
* modules/stdlib (Makefile.am): Substitute GNULIB__EXIT and HAVE__EXIT.
* modules/_Exit: New file.
* tests/test-stdlib-c++.cc (_Exit): Check signature.
* doc/posix-functions/_Exit_C99.texi: Mention the new module.
================================= lib/_Exit.c =================================
/* Copyright (C) 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <stdlib.h>
#include <unistd.h>
void
_Exit (int status)
{
_exit (status);
}
================================= m4/_Exit.m4 =================================
# _Exit.m4 serial 1
dnl Copyright (C) 2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC__EXIT],
[
AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
AC_CHECK_FUNCS([_Exit])
if test $ac_cv_func__Exit = no; then
HAVE__EXIT=0
AC_LIBOBJ([_Exit])
gl_PREREQ__EXIT
fi
])
# Prerequisites of lib/_Exit.c.
AC_DEFUN([gl_PREREQ__EXIT], [
:
])
================================ modules/_Exit ================================
Description:
_Exit() function: terminate current process
Files:
lib/_Exit.c
m4/_Exit.m4
Depends-on:
stdlib
configure.ac:
gl_FUNC__EXIT
gl_STDLIB_MODULE_INDICATOR([_Exit])
Makefile.am:
Include:
<stdlib.h>
License:
LGPL
Maintainer:
all
===============================================================================
--- doc/posix-functions/_Exit_C99.texi.orig Mon Jul 12 18:49:15 2010
+++ doc/posix-functions/_Exit_C99.texi Mon Jul 12 16:41:40 2010
@@ -7,15 +7,15 @@
POSIX specification:
@url{http://www.opengroup.org/onlinepubs/9699919799/functions/_Exit.html}
-Gnulib module: ---
+Gnulib module: _Exit
Portability problems fixed by Gnulib:
@itemize
address@hidden
+This function is missing on some platforms:
+AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 1.5.x, Interix 3.5,
BeOS.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
address@hidden
-This function is missing on some platforms:
-AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 1.5.x, Interix 3.5,
BeOS.
@end itemize
--- lib/stdlib.in.h.orig Mon Jul 12 18:49:15 2010
+++ lib/stdlib.in.h Mon Jul 12 18:49:13 2010
@@ -74,6 +74,12 @@
# include <unistd.h>
#endif
+#ifndef __attribute__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
+# define __attribute__(Spec) /* empty */
+# endif
+#endif
+
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
@@ -95,6 +101,23 @@
#endif
+#if @GNULIB__EXIT@
+/* Terminate the current process with the given return code, without running
+ the 'atexit' handlers. */
+# if address@hidden@
+_GL_FUNCDECL_SYS (_Exit, void, (int status) __attribute__ ((__noreturn__)));
+# endif
+_GL_CXXALIAS_SYS (_Exit, void, (int status));
+_GL_CXXALIASWARN (_Exit);
+#elif defined GNULIB_POSIXCHECK
+# undef _Exit
+# if HAVE_RAW_DECL__EXIT
+_GL_WARN_ON_USE (_Exit, "_Exit is unportable - "
+ "use gnulib module _Exit for portability");
+# endif
+#endif
+
+
#if @GNULIB_ATOLL@
/* Parse a signed decimal integer.
Returns the value of the integer. Errors are not detected. */
--- m4/stdlib_h.m4.orig Mon Jul 12 18:49:15 2010
+++ m4/stdlib_h.m4 Mon Jul 12 16:55:18 2010
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 29
+# stdlib_h.m4 serial 30
dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -33,7 +33,7 @@
#if HAVE_RANDOM_H
# include <random.h>
#endif
- ]], [atoll canonicalize_file_name getloadavg getsubopt grantpt mkdtemp
+ ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt
mkdtemp
mkostemp mkostemps mkstemp mkstemps ptsname random_r initstat_r srandom_r
setstate_r realpath rpmatch setenv strtod strtoll strtoull unlockpt
unsetenv])
@@ -50,6 +50,7 @@
AC_DEFUN([gl_STDLIB_H_DEFAULTS],
[
+ GNULIB__EXIT=0; AC_SUBST([GNULIB__EXIT])
GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL])
GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX])
GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME])
@@ -75,6 +76,7 @@
GNULIB_UNLOCKPT=0; AC_SUBST([GNULIB_UNLOCKPT])
GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV])
dnl Assume proper GNU behavior unless another module says otherwise.
+ HAVE__EXIT=1; AC_SUBST([HAVE__EXIT])
HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL])
HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME])
HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG])
--- modules/stdlib.orig Mon Jul 12 18:49:16 2010
+++ modules/stdlib Mon Jul 12 16:54:28 2010
@@ -28,6 +28,7 @@
sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
-e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
+ -e 's|@''GNULIB__EXIT''@|$(GNULIB__EXIT)|g' \
-e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \
-e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
-e
's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \
@@ -52,6 +53,7 @@
-e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \
-e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
-e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
+ -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
-e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
-e
's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \
-e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
--- tests/test-stdlib-c++.cc.orig Mon Jul 12 18:49:16 2010
+++ tests/test-stdlib-c++.cc Mon Jul 12 17:05:20 2010
@@ -24,6 +24,10 @@
#include "signature.h"
+#if GNULIB_TEST__EXIT
+SIGNATURE_CHECK (GNULIB_NAMESPACE::_Exit, void, (int));
+#endif
+
//SIGNATURE_CHECK (GNULIB_NAMESPACE::atexit, int, (void (*) (void)));
#if GNULIB_TEST_ATOLL