bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH 1/2] limits-h: new module


From: Paul Eggert
Subject: [PATCH 1/2] limits-h: new module
Date: Thu, 15 Sep 2016 15:45:14 -0700

This adds ISO/IEC TS 18661-1:2014 support to limits.h.
* MODULES.html.sh: Add limits-h,and move size_max to stdint section.
* doc/posix-headers/limits.texi: Document new module.
* lib/limits.in.h, m4/limits-h.m4, modules/limits-h:
* modules/limit-h-tests, tests/test-limits-h.c: New files.
---
 ChangeLog                     |  9 +++++++
 MODULES.html.sh               | 20 +++++++-------
 doc/posix-headers/limits.texi |  3 +++
 lib/limits.in.h               | 63 +++++++++++++++++++++++++++++++++++++++++++
 m4/limits-h.m4                | 29 ++++++++++++++++++++
 modules/limits-h              | 44 ++++++++++++++++++++++++++++++
 modules/limits-h-tests        | 12 +++++++++
 tests/test-limits-h.c         | 46 +++++++++++++++++++++++++++++++
 8 files changed, 216 insertions(+), 10 deletions(-)
 create mode 100644 lib/limits.in.h
 create mode 100644 m4/limits-h.m4
 create mode 100644 modules/limits-h
 create mode 100644 modules/limits-h-tests
 create mode 100644 tests/test-limits-h.c

diff --git a/ChangeLog b/ChangeLog
index 8d0b408..9006d19 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2016-09-15  Paul Eggert  <address@hidden>
+
+       limits-h: new module
+       This adds ISO/IEC TS 18661-1:2014 support to limits.h.
+       * MODULES.html.sh: Add limits-h,and move size_max to stdint section.
+       * doc/posix-headers/limits.texi: Document new module.
+       * lib/limits.in.h, m4/limits-h.m4, modules/limits-h:
+       * modules/limit-h-tests, tests/test-limits-h.c: New files.
+
 2016-09-15  Eric Blake  <address@hidden>
 
        sys_types: avoid glibc 2.25 warnings about major()
diff --git a/MODULES.html.sh b/MODULES.html.sh
index 06ee261..e7f2cd6 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2049,16 +2049,6 @@ func_all_modules ()
   func_module vla
   func_end_table
 
-  element="Sizes of integer types <limits.h>"
-  element=`printf "%s" "$element" | sed -e "$sed_lt" -e "$sed_gt"`
-  func_section_wrap isoc_sup_limits
-  func_wrap H3
-  func_echo "$element"
-
-  func_begin_table
-  func_module size_max
-  func_end_table
-
   element="Variable arguments <stdarg.h>"
   element=`printf "%s" "$element" | sed -e "$sed_lt" -e "$sed_gt"`
   func_section_wrap isoc_sup_stdarg
@@ -2096,6 +2086,7 @@ func_all_modules ()
   func_echo "$element"
 
   func_begin_table
+  func_module size_max
   func_module stdint
   func_end_table
 
@@ -2354,6 +2345,15 @@ func_all_modules ()
   func_module stdalign
   func_end_table
 
+  element="Support for standard extensions to ISO C 11"
+  func_section_wrap c11_ext
+  func_wrap H2
+  func_echo "$element"
+
+  func_begin_table
+  func_module limits-h
+  func_end_table
+
   element="Support for obsolete systems lacking POSIX:2008"
   func_section_wrap posix_sup_obsolete
   func_wrap H2
diff --git a/doc/posix-headers/limits.texi b/doc/posix-headers/limits.texi
index 31207ac..7658326 100644
--- a/doc/posix-headers/limits.texi
+++ b/doc/posix-headers/limits.texi
@@ -11,6 +11,9 @@ Portability problems fixed by Gnulib:
 The @code{HOST_NAME_MAX} macro is not defined on some platforms:
 Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, AIX 5.1, HP-UX 11,
 IRIX 6.5, OSF/1 5.1, Solaris 11 2011-11, Cygwin 1.5.x, mingw, MSVC 9, Interix 
3.5, BeOS.
address@hidden
+Macros like @code{CHAR_WIDTH} are not defined on some platforms:
+glibc 2.24, many others.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/limits.in.h b/lib/limits.in.h
new file mode 100644
index 0000000..9a4f9f4
--- /dev/null
+++ b/lib/limits.in.h
@@ -0,0 +1,63 @@
+/* A GNU-like <limits.h>.
+
+   Copyright 2016 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef address@hidden@_LIMITS_H
+
+#if __GNUC__ >= 3
address@hidden@
+#endif
address@hidden@
+
+/* The include_next requires a split double-inclusion guard.  */
address@hidden@ @NEXT_LIMITS_H@
+
+#ifndef address@hidden@_LIMITS_H
+#define address@hidden@_LIMITS_H
+
+/* The number of usable bits in an unsigned or signed integer type
+   with minimum value MIN and maximum value MAX, as an int expression
+   suitable in #if.  Cover all known practical hosts.  This
+   implementation exploits the fact that MAX is 1 less than a power of
+   2, and merely counts the number of 1 bits in MAX; "COBn" means
+   "count the number of 1 bits in the low-order n bits").  */
+#define _GL_INTEGER_WIDTH(min, max) (((min) < 0) + _GL_COB128 (max))
+#define _GL_COB128(n) (_GL_COB64 ((n) >> 31 >> 31 >> 2) + _GL_COB64 (n))
+#define _GL_COB64(n) (_GL_COB32 ((n) >> 31 >> 1) + _GL_COB32 (n))
+#define _GL_COB32(n) (_GL_COB16 ((n) >> 16) + _GL_COB16 (n))
+#define _GL_COB16(n) (_GL_COB8 ((n) >> 8) + _GL_COB8 (n))
+#define _GL_COB8(n) (_GL_COB4 ((n) >> 4) + _GL_COB4 (n))
+#define _GL_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + !!((n) & 1))
+
+/* Macros specified by ISO/IEC TS 18661-1:2014.  */
+
+#if (! defined ULLONG_WIDTH                                             \
+     && (defined _GNU_SOURCE || defined __STDC_WANT_IEC_60559_BFP_EXT__))
+# define CHAR_WIDTH _GL_INTEGER_WIDTH (CHAR_MIN, CHAR_MAX)
+# define SCHAR_WIDTH _GL_INTEGER_WIDTH (SCHAR_MIN, SCHAR_MAX)
+# define UCHAR_WIDTH _GL_INTEGER_WIDTH (0, UCHAR_MAX)
+# define SHRT_WIDTH _GL_INTEGER_WIDTH (SHRT_MIN, SHRT_MAX)
+# define USHRT_WIDTH _GL_INTEGER_WIDTH (0, USHRT_MAX)
+# define INT_WIDTH _GL_INTEGER_WIDTH (INT_MIN, INT_MAX)
+# define UINT_WIDTH _GL_INTEGER_WIDTH (0, UINT_MAX)
+# define LONG_WIDTH _GL_INTEGER_WIDTH (LONG_MIN, LONG_MAX)
+# define ULONG_WIDTH _GL_INTEGER_WIDTH (0, ULONG_MAX)
+# define LLONG_WIDTH _GL_INTEGER_WIDTH (LLONG_MIN, LLONG_MAX)
+# define ULLONG_WIDTH _GL_INTEGER_WIDTH (0, ULLONG_MAX)
+#endif /* !ULLONG_WIDTH && (_GNU_SOURCE || __STDC_WANT_IEC_60559_BFP_EXT__) */
+
+#endif /* address@hidden@_LIMITS_H */
+#endif /* address@hidden@_LIMITS_H */
diff --git a/m4/limits-h.m4 b/m4/limits-h.m4
new file mode 100644
index 0000000..9130786
--- /dev/null
+++ b/m4/limits-h.m4
@@ -0,0 +1,29 @@
+dnl Check whether limits.h has needed features.
+
+dnl Copyright 2016 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.
+
+dnl From Paul Eggert.
+
+AC_DEFUN_ONCE([gl_LIMITS_H],
+[
+  gl_CHECK_NEXT_HEADERS([limits.h])
+
+  AC_CACHE_CHECK([whether limits.h has ULLONG_WIDTH etc.],
+    [gl_cv_header_limits_width],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM([[#define __STDC_WANT_IEC_60559_BFP_EXT__ 1
+                          #include <limits.h>
+                          int ullw = ULLONG_WIDTH;]])],
+       [gl_cv_header_limits_width=yes],
+       [gl_cv_header_limits_width=no])])
+  if test "$gl_cv_header_limits_width" = yes; then
+    LIMITS_H=
+  else
+    LIMITS_H=limits.h
+  fi
+  AC_SUBST([LIMITS_H])
+  AM_CONDITIONAL([GL_GENERATE_LIMITS_H], [test -n "$LIMITS_H"])
+])
diff --git a/modules/limits-h b/modules/limits-h
new file mode 100644
index 0000000..9c60ec9
--- /dev/null
+++ b/modules/limits-h
@@ -0,0 +1,44 @@
+Description:
+A GNU-like <limits.h>.
+
+Files:
+lib/limits.in.h
+m4/limits-h.m4
+
+Depends-on:
+include_next
+
+configure.ac:
+gl_LIMITS_H
+
+Makefile.am:
+BUILT_SOURCES += $(LIMITS_H)
+
+# We need the following in order to create <limits.h> when the system
+# doesn't have one that is compatible with GNU.
+if GL_GENERATE_LIMITS_H
+limits.h: limits.in.h $(top_builddir)/config.status
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+         sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_LIMITS_H''@|$(NEXT_LIMITS_H)|g' \
+             < $(srcdir)/limits.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+else
+limits.h: $(top_builddir)/config.status
+       rm -f $@
+endif
+MOSTLYCLEANFILES += limits.h limits.h-t
+
+Include:
+<limits.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/limits-h-tests b/modules/limits-h-tests
new file mode 100644
index 0000000..cda0de2
--- /dev/null
+++ b/modules/limits-h-tests
@@ -0,0 +1,12 @@
+Files:
+tests/test-limits-h.c
+
+Depends-on:
+extensions
+verify
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-limits-h
+check_PROGRAMS += test-limits-h
diff --git a/tests/test-limits-h.c b/tests/test-limits-h.c
new file mode 100644
index 0000000..597dabf
--- /dev/null
+++ b/tests/test-limits-h.c
@@ -0,0 +1,46 @@
+/* Test of <limits.h> substitute.
+   Copyright 2016 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 <limits.h>
+
+#include "verify.h"
+
+/* Macros specified by ISO/IEC TS 18661-1:2014.  */
+
+#define verify_width(width, min, max) \
+  verify ((max) >> ((width) - 1 - ((min) < 0)) == 1)
+
+verify_width (CHAR_WIDTH, CHAR_MIN, CHAR_MAX);
+verify_width (SCHAR_WIDTH, SCHAR_MIN, SCHAR_MAX);
+verify_width (UCHAR_WIDTH, 0, UCHAR_MAX);
+verify_width (SHRT_WIDTH, SHRT_MIN, SHRT_MAX);
+verify_width (USHRT_WIDTH, 0, USHRT_MAX);
+verify_width (INT_WIDTH, INT_MIN, INT_MAX);
+verify_width (UINT_WIDTH, 0, UINT_MAX);
+verify_width (LONG_WIDTH, LONG_MIN, LONG_MAX);
+verify_width (ULONG_WIDTH, 0, ULONG_MAX);
+verify_width (LLONG_WIDTH, LLONG_MIN, LLONG_MAX);
+verify_width (ULLONG_WIDTH, 0, ULLONG_MAX);
+
+int
+main (void)
+{
+  return 0;
+}
-- 
2.7.4




reply via email to

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