From: Paul Eggert Date: Thu, 15 Sep 2016 18:34:52 +0000 (-0700) Subject: limits-h: new module X-Git-Tag: v1.0~6636 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=0d12d16ab30cc5581ee26a3877351ac3181bca81;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 6609e2b4cc..745133ac48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2016-09-16 Paul Eggert + 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. + stdio: don't redefine __USE_MINGW_ANSI_STDIO * m4/stdio_h.m4 (gl_STDIO_H): Don't define __USE_MINGW_ANSI_STDIO if it is already defined. Apparently GNU Emacs relies on this. See: diff --git a/MODULES.html.sh b/MODULES.html.sh index 06ee261f19..e7f2cd608f 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 " - 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 " 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 31207ac807..7658326b89 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. +@item +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 0000000000..9a4f9f45ec --- /dev/null +++ b/lib/limits.in.h @@ -0,0 +1,63 @@ +/* A GNU-like . + + 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 . */ + +#ifndef _@GUARD_PREFIX@_LIMITS_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* The include_next requires a split double-inclusion guard. */ +#@INCLUDE_NEXT@ @NEXT_LIMITS_H@ + +#ifndef _@GUARD_PREFIX@_LIMITS_H +#define _@GUARD_PREFIX@_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 /* _@GUARD_PREFIX@_LIMITS_H */ +#endif /* _@GUARD_PREFIX@_LIMITS_H */ diff --git a/m4/limits-h.m4 b/m4/limits-h.m4 new file mode 100644 index 0000000000..913078689b --- /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 + 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 0000000000..9c60ec9c04 --- /dev/null +++ b/modules/limits-h @@ -0,0 +1,44 @@ +Description: +A GNU-like . + +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 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 $@-t $@ && \ + { 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; \ + } > $@-t && \ + mv $@-t $@ +else +limits.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += limits.h limits.h-t + +Include: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/limits-h-tests b/modules/limits-h-tests new file mode 100644 index 0000000000..cda0de2225 --- /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 0000000000..597dabfe37 --- /dev/null +++ b/tests/test-limits-h.c @@ -0,0 +1,46 @@ +/* Test of 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 . */ + +/* Written by Paul Eggert. */ + +#include + +#include + +#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; +}