bug-gnulib
[Top][All Lists]
Advanced

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

Re: stdint on MSVC


From: Bruno Haible
Subject: Re: stdint on MSVC
Date: Mon, 19 Dec 2016 21:13:40 +0100
User-agent: KMail/4.8.5 (Linux/3.8.0-44-generic; KDE/4.8.5; x86_64; ; )

> 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.

Oops, this breaks test-stdint on mingw.

Here the situation is that gnulib determines that it would override wint_t,
and therefore it overrides WINT_MAX to 0xffffffffU. But wint_t is not
actually being overridden, because there is a "#if defined _MSC_VER" that
guards the override. This fixes it.


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

        stdint: Fix WINT_MAX to match the gnulib provided wint_t on minw.
        * m4/wint_t.m4 (gt_TYPE_WINT_T): Define GNULIB_OVERRIDES_WINT_T here.
        * m4/stdint.m4 (gl_STDINT_H): Don't define GNULIB_OVERRIDES_WINT_T.
        Invoke gt_TYPE_WINT_T instead.
        (gl_STDINT_TYPE_PROPERTIES): Test GNULIB_OVERRIDES_WINT_T.
        * modules/stdint (Files): Add m4/wint_t.m4.
        * modules/wchar (Makefile.am): Substitute GNULIB_OVERRIDES_WINT_T.
        * modules/wctype-h (Makefile.am): Likewise.
        * lib/wchar.in.h (wint_t): Override if GNULIB_OVERRIDES_WINT_T is set,
        not only on MSVC.
        * lib/wctype.in.h (wint_t): Likewise.

diff --git a/lib/wchar.in.h b/lib/wchar.in.h
index 346a307..8200c86 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -113,10 +113,10 @@
 #  define WEOF -1
 # endif
 #else
-/* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>.
+/* mingw and MSVC define wint_t as 'unsigned short' in <crtdefs.h>.
    This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be
    "unchanged by default argument promotions".  Override it.  */
-# if defined _MSC_VER
+# if @GNULIB_OVERRIDES_WINT_T@
 #  if !GNULIB_defined_wint_t
 #   include <crtdefs.h>
 typedef unsigned int rpl_wint_t;
diff --git a/lib/wctype.in.h b/lib/wctype.in.h
index ddc34d0..615cdc8 100644
--- a/lib/wctype.in.h
+++ b/lib/wctype.in.h
@@ -105,10 +105,10 @@ _GL_INLINE_HEADER_BEGIN
 #  define WEOF -1
 # endif
 #else
-/* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>.
+/* mingw and MSVC define wint_t as 'unsigned short' in <crtdefs.h>.
    This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be
    "unchanged by default argument promotions".  Override it.  */
-# if defined _MSC_VER
+# if @GNULIB_OVERRIDES_WINT_T@
 #  if !GNULIB_defined_wint_t
 #   include <crtdefs.h>
 typedef unsigned int rpl_wint_t;
diff --git a/m4/stdint.m4 b/m4/stdint.m4
index b972ee4..1d0d951 100644
--- a/m4/stdint.m4
+++ b/m4/stdint.m4
@@ -1,4 +1,4 @@
-# stdint.m4 serial 49
+# stdint.m4 serial 50
 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,
@@ -12,6 +12,7 @@ AC_DEFUN_ONCE([gl_STDINT_H],
   AC_PREREQ([2.59])dnl
 
   AC_REQUIRE([gl_LIMITS_H])
+  AC_REQUIRE([gt_TYPE_WINT_T])
 
   dnl Check for long long int and unsigned long long int.
   AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
@@ -354,32 +355,6 @@ int32_t i32 = INT32_C (0x7fffffff);
     gl_STDINT_TYPE_PROPERTIES
   fi
 
-  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"])
@@ -388,7 +363,6 @@ 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"])
 ])
 
@@ -555,7 +529,7 @@ AC_DEFUN([gl_STDINT_TYPE_PROPERTIES],
   dnl requirement that wint_t is "unchanged by default argument promotions".
   dnl In this case gnulib's <wchar.h> and <wctype.h> override wint_t.
   dnl Set the variable BITSIZEOF_WINT_T accordingly.
-  if test $BITSIZEOF_WINT_T -lt 32; then
+  if test $GNULIB_OVERRIDES_WINT_T = 1; then
     BITSIZEOF_WINT_T=32
   fi
 ])
diff --git a/m4/wint_t.m4 b/m4/wint_t.m4
index 8ff2a5b..59b22bf 100644
--- a/m4/wint_t.m4
+++ b/m4/wint_t.m4
@@ -1,11 +1,12 @@
-# wint_t.m4 serial 5 (gettext-0.18.2)
+# wint_t.m4 serial 6
 dnl Copyright (C) 2003, 2007-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 Bruno Haible.
-dnl Test whether <wchar.h> has the 'wint_t' type.
+dnl Test whether <wchar.h> has the 'wint_t' type and whether gnulib's
+dnl <wchar.h> or <wctype.h> would, if present, override 'wint_t'.
 dnl Prerequisite: AC_PROG_CC
 
 AC_DEFUN([gt_TYPE_WINT_T],
@@ -28,5 +29,34 @@ AC_DEFUN([gt_TYPE_WINT_T],
        [gt_cv_c_wint_t=no])])
   if test $gt_cv_c_wint_t = yes; then
     AC_DEFINE([HAVE_WINT_T], [1], [Define if you have the 'wint_t' type.])
+
+    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
+  else
+    GNULIB_OVERRIDES_WINT_T=0
   fi
+  AC_SUBST([GNULIB_OVERRIDES_WINT_T])
 ])
diff --git a/modules/stdint b/modules/stdint
index 75ce257..d50b453 100644
--- a/modules/stdint
+++ b/modules/stdint
@@ -10,6 +10,7 @@ Macros are used instead of typedefs.
 Files:
 lib/stdint.in.h
 m4/stdint.m4
+m4/wint_t.m4
 m4/longlong.m4
 
 Depends-on:
diff --git a/modules/wchar b/modules/wchar
index abaf6b7..f29b200 100644
--- a/modules/wchar
+++ b/modules/wchar
@@ -31,6 +31,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \
              -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \
              -e 's|@''HAVE_WCHAR_H''@|$(HAVE_WCHAR_H)|g' \
+             -e 's/@''GNULIB_OVERRIDES_WINT_T''@/$(GNULIB_OVERRIDES_WINT_T)/g' 
\
              -e 's/@''GNULIB_BTOWC''@/$(GNULIB_BTOWC)/g' \
              -e 's/@''GNULIB_WCTOB''@/$(GNULIB_WCTOB)/g' \
              -e 's/@''GNULIB_MBSINIT''@/$(GNULIB_MBSINIT)/g' \
diff --git a/modules/wctype-h b/modules/wctype-h
index b2cbdcd..adfb218 100644
--- a/modules/wctype-h
+++ b/modules/wctype-h
@@ -31,6 +31,7 @@ wctype.h: wctype.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(WARN_ON_USE_H
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \
+             -e 's/@''GNULIB_OVERRIDES_WINT_T''@/$(GNULIB_OVERRIDES_WINT_T)/g' 
\
              -e 's/@''GNULIB_ISWBLANK''@/$(GNULIB_ISWBLANK)/g' \
              -e 's/@''GNULIB_WCTYPE''@/$(GNULIB_WCTYPE)/g' \
              -e 's/@''GNULIB_ISWCTYPE''@/$(GNULIB_ISWCTYPE)/g' \




reply via email to

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