bug-gnulib
[Top][All Lists]
Advanced

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

stdint on MSVC


From: Bruno Haible
Subject: stdint on MSVC
Date: Sat, 17 Dec 2016 18:48:56 +0100
User-agent: KMail/4.8.5 (Linux/3.8.0-44-generic; KDE/4.8.5; x86_64; ; )

In an MSVC 14 build, test-stdint fails to compile:
test-stdint.c(312): error C2034: '_gl_verify_error_if_negative': type of bit 
field too small for number of bits

The reason is that gnulib's <wchar.h> (or it could also be <wctype.h)
defines wint_t as rpl_wint_t, but the definition of WINT_MAX as 0xffff
from MSVC's <stdint.h> is still in effect. This fixes it.


2016-12-17  Bruno Haible  <address@hidden>

        stdint: Fix WINT_MAX to match the gnulib provided wint_t on MSVC.
        * m4/stdint.m4 (gl_STDINT_H): Define GNULIB_OVERRIDES_WINT_T.
        * modules/stdint (Makefile.am): Substitute GNULIB_OVERRIDES_WINT_T.
        * lib/stdint.in.h [GNULIB_OVERRIDES_WINT_T]: Redefine WINT_MIN and
        WINT_MAX.

diff --git a/lib/stdint.in.h b/lib/stdint.in.h
index f168e3e..5060dab 100644
--- a/lib/stdint.in.h
+++ b/lib/stdint.in.h
@@ -83,6 +83,15 @@
    LONG_MIN, LONG_MAX, ULONG_MAX, _GL_INTEGER_WIDTH.  */
 #include <limits.h>
 
+/* Override WINT_MIN and WINT_MAX if gnulib's <wchar.h> or <wctype.h> overrides
+   wint_t.  */
+#if @GNULIB_OVERRIDES_WINT_T@
+# undef WINT_MIN
+# undef WINT_MAX
+# define WINT_MIN 0x0U
+# define WINT_MAX 0xffffffffU
+#endif
+
 #if ! @HAVE_C99_STDINT_H@
 
 /* <sys/types.h> defines some of the stdint.h types as well, on glibc,
diff --git a/m4/stdint.m4 b/m4/stdint.m4
index 05b6ab7..b972ee4 100644
--- a/m4/stdint.m4
+++ b/m4/stdint.m4
@@ -1,4 +1,4 @@
-# stdint.m4 serial 48
+# stdint.m4 serial 49
 dnl Copyright (C) 2001-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,
@@ -354,7 +354,33 @@ int32_t i32 = INT32_C (0x7fffffff);
     gl_STDINT_TYPE_PROPERTIES
   fi
 
-  # The substitute stdint.h needs the substitute limit.h's _GL_INTEGER_WIDTH.
+  dnl Determine whether gnulib's <wchar.h> or <wctype.h> would, if present,
+  dnl override 'wint_t'.
+  AC_CACHE_CHECK([whether wint_t is too small],
+    [gl_cv_type_wint_t_too_small],
+    [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM([[
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+   <wchar.h>.
+   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+   included before <wchar.h>.  */
+#if !(defined __GLIBC__ && !defined __UCLIBC__)
+# include <stddef.h>
+# include <stdio.h>
+# include <time.h>
+#endif
+#include <wchar.h>
+            int verify[sizeof (wint_t) < sizeof (int) ? -1 : 1];
+            ]])],
+         [gl_cv_type_wint_t_too_small=no],
+         [gl_cv_type_wint_t_too_small=yes])])
+  if test $gl_cv_type_wint_t_too_small = yes; then
+    GNULIB_OVERRIDES_WINT_T=1
+  else
+    GNULIB_OVERRIDES_WINT_T=0
+  fi
+
+  dnl The substitute stdint.h needs the substitute limit.h's _GL_INTEGER_WIDTH.
   LIMITS_H=limits.h
   AM_CONDITIONAL([GL_GENERATE_LIMITS_H], [test -n "$LIMITS_H"])
 
@@ -362,6 +388,7 @@ int32_t i32 = INT32_C (0x7fffffff);
   AC_SUBST([HAVE_SYS_BITYPES_H])
   AC_SUBST([HAVE_SYS_INTTYPES_H])
   AC_SUBST([STDINT_H])
+  AC_SUBST([GNULIB_OVERRIDES_WINT_T])
   AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"])
 ])
 
diff --git a/modules/stdint b/modules/stdint
index a12c5df..75ce257 100644
--- a/modules/stdint
+++ b/modules/stdint
@@ -58,6 +58,7 @@ stdint.h: stdint.in.h $(top_builddir)/config.status
              -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \
              -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \
              -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \
+             -e 's/@''GNULIB_OVERRIDES_WINT_T''@/$(GNULIB_OVERRIDES_WINT_T)/g' 
\
              < $(srcdir)/stdint.in.h; \
        } > address@hidden && \
        mv address@hidden $@




reply via email to

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