bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] stdnoreturn: new module


From: Paul Eggert
Subject: [PATCH] stdnoreturn: new module
Date: Fri, 24 Feb 2012 14:09:50 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20120131 Thunderbird/10.0

This implements a replacement for C11's <stdnoreturn.h>.
* doc/gnulib.texi (Header File Substitutes): Add stdnoreturn.
* doc/posix-headers/stdnoreturn.texi, lib/stdnoreturn.in.h:
* m4/stdnoreturn.m4, modules/stdnoreturn, modules/stdnoreturn-tests:
* tests/test-stdnoreturn.c: New files.
---
 ChangeLog                          |    9 +++++++
 doc/gnulib.texi                    |    2 +
 doc/posix-headers/stdnoreturn.texi |   24 ++++++++++++++++++++
 lib/stdnoreturn.in.h               |   38 ++++++++++++++++++++++++++++++++
 m4/stdnoreturn.m4                  |   42 ++++++++++++++++++++++++++++++++++++
 modules/stdnoreturn                |   40 ++++++++++++++++++++++++++++++++++
 modules/stdnoreturn-tests          |   10 ++++++++
 tests/test-stdnoreturn.c           |   35 ++++++++++++++++++++++++++++++
 8 files changed, 200 insertions(+), 0 deletions(-)
 create mode 100644 doc/posix-headers/stdnoreturn.texi
 create mode 100644 lib/stdnoreturn.in.h
 create mode 100644 m4/stdnoreturn.m4
 create mode 100644 modules/stdnoreturn
 create mode 100644 modules/stdnoreturn-tests
 create mode 100644 tests/test-stdnoreturn.c

diff --git a/ChangeLog b/ChangeLog
index 53680d8..c7a6e10 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-02-24  Paul Eggert  <address@hidden>
+
+       stdnoreturn: new module
+       This implements a replacement for C11's <stdnoreturn.h>.
+       * doc/gnulib.texi (Header File Substitutes): Add stdnoreturn.
+       * doc/posix-headers/stdnoreturn.texi, lib/stdnoreturn.in.h:
+       * m4/stdnoreturn.m4, modules/stdnoreturn, modules/stdnoreturn-tests:
+       * tests/test-stdnoreturn.c: New files.
+
 2012-02-24  Stanislav Brabec  <address@hidden>  (tiny change)
 
        regex: fix false multibyte matches in some regular expressions
diff --git a/doc/gnulib.texi b/doc/gnulib.texi
index 1581942..cd95864 100644
--- a/doc/gnulib.texi
+++ b/doc/gnulib.texi
@@ -1194,6 +1194,7 @@ which (known) portability problems are not worked around 
by Gnulib.
 * stdint.h::
 * stdio.h::
 * stdlib.h::
+* stdnoreturn.h::
 * string.h::
 * strings.h::
 * stropts.h::
@@ -1281,6 +1282,7 @@ which (known) portability problems are not worked around 
by Gnulib.
 @include posix-headers/stdint.texi
 @include posix-headers/stdio.texi
 @include posix-headers/stdlib.texi
address@hidden posix-headers/stdnoreturn.texi
 @include posix-headers/string.texi
 @include posix-headers/strings.texi
 @include posix-headers/stropts.texi
diff --git a/doc/posix-headers/stdnoreturn.texi 
b/doc/posix-headers/stdnoreturn.texi
new file mode 100644
index 0000000..f49d663
--- /dev/null
+++ b/doc/posix-headers/stdnoreturn.texi
@@ -0,0 +1,24 @@
address@hidden stdnoreturn.h
address@hidden @file{stdnoreturn.h}
+
+POSIX specification:@* Not in POSIX yet, but we expect it will be.
+ISO C11 (latest free draft
address@hidden://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf})
+sections 7.23.
+
+Gnulib module: stdnoreturn
+
+Portability problems fixed by Gnulib:
address@hidden
address@hidden
+This header file is missing on most circa-2012 platforms.
address@hidden itemize
+
+Portability problems not fixed by Gnulib:
address@hidden
address@hidden
address@hidden<stdnoreturn.h>} should be #included before @samp{_Noreturn} is 
used.
address@hidden
+You cannot assume that @code{_Noreturn} is a reserved word;
+it might be a macro.
address@hidden itemize
diff --git a/lib/stdnoreturn.in.h b/lib/stdnoreturn.in.h
new file mode 100644
index 0000000..5ca3063
--- /dev/null
+++ b/lib/stdnoreturn.in.h
@@ -0,0 +1,38 @@
+/* A substitute for ISO C11 <stdnoreturn.h>.
+
+   Copyright 2012 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 2, 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/>.  */
+
+/* Written by Paul Eggert.  */
+
+#ifndef noreturn
+
+/* ISO C11 <stdnoreturn.h> for platforms that lack it.
+
+   References:
+   ISO C11 (latest free draft
+   <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>)
+   section 7.23 */
+
+/* The definition of _Noreturn is copied here.  */
+
+#define noreturn _Noreturn
+
+/* Did he ever return?
+   No he never returned
+   And his fate is still unlearn'd ...
+     -- Steiner J, Hawes BL.  M.T.A. (1949)  */
+
+#endif /* noreturn */
diff --git a/m4/stdnoreturn.m4 b/m4/stdnoreturn.m4
new file mode 100644
index 0000000..6e10b12
--- /dev/null
+++ b/m4/stdnoreturn.m4
@@ -0,0 +1,42 @@
+# Check for stdnoreturn.h that conforms to C11.
+
+dnl Copyright 2012 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.
+
+# Prepare for substituting <stdnoreturn.h> if it is not supported.
+
+AC_DEFUN([gl_STDNORETURN_H],
+[
+  AC_CACHE_CHECK([for working stdnoreturn.h],
+    [gl_cv_header_working_stdnoreturn_h],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <stdlib.h>
+            #include <stdnoreturn.h>
+            void noreturn foo1 (void) { exit (0); }
+            void _Noreturn foo2 (void) { exit (0); }
+            noreturn void foo3 (void) { exit (0); }
+            _Noreturn void foo4 (void) { exit (0); }
+            int main (int argc, char **argv) {
+              if (argc & 1)
+                return 0;
+              ((argv[0][0]
+                ? (argv[0][1] ? foo1 : foo2)
+                : (argv[0][1] ? foo3 : foo4))
+               ());
+            }
+          ]])],
+       [gl_cv_header_working_stdnoreturn_h=yes],
+       [gl_cv_header_working_stdnoreturn_h=no])])
+
+  if test $gl_cv_header_working_stdnoreturn_h = yes; then
+    STDNORETURN_H=''
+  else
+    STDNORETURN_H='stdnoreturn.h'
+  fi
+
+  AC_SUBST([STDNORETURN_H])
+  AM_CONDITIONAL([GL_GENERATE_STDNORETURN_H], [test -n "$STDNORETURN_H"])
+])
diff --git a/modules/stdnoreturn b/modules/stdnoreturn
new file mode 100644
index 0000000..acd661b
--- /dev/null
+++ b/modules/stdnoreturn
@@ -0,0 +1,40 @@
+Description:
+A <stdnoreturn.h> that nearly conforms to ISO C11.
+
+Files:
+lib/stdnoreturn.in.h
+m4/stdnoreturn.m4
+
+Depends-on:
+snippet/_Noreturn
+
+configure.ac:
+gl_STDNORETURN_H
+
+Makefile.am:
+BUILT_SOURCES += $(STDNORETURN_H)
+
+# We need the following in order to create <stdnoreturn.h> when the system
+# doesn't have one that works.
+if GL_GENERATE_STDNORETURN_H
+stdnoreturn.h: stdnoreturn.in.h $(top_builddir)/config.status $(_NORETURN_H)
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+         sed -e '/definition of _Noreturn/r $(_NORETURN_H)' \
+              < $(srcdir)/stdnoreturn.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+else
+stdnoreturn.h: $(top_builddir)/config.status
+       rm -f $@
+endif
+MOSTLYCLEANFILES += stdnoreturn.h stdnoreturn.h-t
+
+Include:
+<stdnoreturn.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Paul Eggert
diff --git a/modules/stdnoreturn-tests b/modules/stdnoreturn-tests
new file mode 100644
index 0000000..1d1f820
--- /dev/null
+++ b/modules/stdnoreturn-tests
@@ -0,0 +1,10 @@
+Files:
+tests/test-stdnoreturn.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-stdnoreturn
+check_PROGRAMS += test-stdnoreturn
diff --git a/tests/test-stdnoreturn.c b/tests/test-stdnoreturn.c
new file mode 100644
index 0000000..e8422ef
--- /dev/null
+++ b/tests/test-stdnoreturn.c
@@ -0,0 +1,35 @@
+/* Test of <stdnoreturn.h>.
+   Copyright 2012 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/>.  */
+
+/* Written by Paul Eggert.  */
+
+#include <config.h>
+
+#include <stdnoreturn.h>
+
+#include <stdlib.h>
+
+noreturn void
+does_not_return (void)
+{
+  exit (0);
+}
+
+int
+main (void)
+{
+  does_not_return ();
+}
-- 
1.7.6.5




reply via email to

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