]> Savannah Git Hosting - gnulib.git/commitdiff
mbrtowc: Don't replace mbstate_t on MSVC.
authorBruno Haible <bruno@clisp.org>
Thu, 2 Jan 2020 17:36:29 +0000 (18:36 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 2 Jan 2020 17:36:29 +0000 (18:36 +0100)
* m4/mbrtowc.m4 (gl_MBSTATE_T_BROKEN): Require AC_CANONICAL_HOST. Ignore
a missing mbsinit function on native Windows.
* m4/wcrtomb.m4 (gl_FUNC_WCRTOMB): Strengthen the test, to detect an
MSVC bug.
* doc/posix-functions/wcrtomb.texi: Mention the MSVC bug.

ChangeLog
doc/posix-functions/wcrtomb.texi
m4/mbrtowc.m4
m4/wcrtomb.m4

index b128313405945f40dd723d01f51b5b9802b86828..143b5eb65e4a6458d4958f46ef6506409ea4b200 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-01-02  Bruno Haible  <bruno@clisp.org>
+
+       mbrtowc: Don't replace mbstate_t on MSVC.
+       * m4/mbrtowc.m4 (gl_MBSTATE_T_BROKEN): Require AC_CANONICAL_HOST. Ignore
+       a missing mbsinit function on native Windows.
+       * m4/wcrtomb.m4 (gl_FUNC_WCRTOMB): Strengthen the test, to detect an
+       MSVC bug.
+       * doc/posix-functions/wcrtomb.texi: Mention the MSVC bug.
+
 2020-01-02  Bruno Haible  <bruno@clisp.org>
 
        setlocale-null: Avoid crashing the MSVC linker.
index 20902e997b1efb080a2ef33f47d87dcfba3e6f7e..232bea4278d9bd676ab9db7812be836735cccffa 100644 (file)
@@ -17,6 +17,9 @@ Android 4.3.
 @item
 This function returns 0 when the first argument is NULL in some locales on some platforms:
 Solaris 11.3.
+@item
+This function does not ignore the second argument when the first argument is NULL on some platforms:
+MSVC 14.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index c747ea2093c48956fc32e3231372429a51504edb..af4e25d75abab2b5d354fc8512fd0d8aef76b99d 100644 (file)
@@ -1,4 +1,4 @@
-# mbrtowc.m4 serial 34  -*- coding: utf-8 -*-
+# mbrtowc.m4 serial 35  -*- coding: utf-8 -*-
 dnl Copyright (C) 2001-2002, 2004-2005, 2008-2020 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -97,11 +97,19 @@ dnl avoid inconsistencies.
 AC_DEFUN([gl_MBSTATE_T_BROKEN],
 [
   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
 
   AC_REQUIRE([AC_TYPE_MBSTATE_T])
   AC_CHECK_FUNCS_ONCE([mbsinit])
   AC_CHECK_FUNCS_ONCE([mbrtowc])
-  if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then
+  dnl On native Windows, we know exactly how mbsinit() behaves and don't need
+  dnl to override it, even if - like on MSVC - mbsinit() is only defined as
+  dnl an inline function, not as a global function.
+  if case "$host_os" in
+       mingw*) true ;;
+       *) test $ac_cv_func_mbsinit = yes ;;
+     esac \
+    && test $ac_cv_func_mbrtowc = yes; then
     gl_MBRTOWC_INCOMPLETE_STATE
     gl_MBRTOWC_SANITYCHECK
     REPLACE_MBSTATE_T=0
index 73c551bcf002f3e2ad0c09a4a767ed838aa9960f..64e5110f44914cd6f1af7bde6ea7b91ed8d762e3 100644 (file)
@@ -1,4 +1,4 @@
-# wcrtomb.m4 serial 14
+# wcrtomb.m4 serial 15
 dnl Copyright (C) 2008-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -90,12 +90,10 @@ int main ()
           dnl is present.
 changequote(,)dnl
           case "$host_os" in
-                                     # Guess no on AIX 4, OSF/1 and Solaris.
-            aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;;
-                                     # Guess yes on native Windows.
-            mingw*)                  gl_cv_func_wcrtomb_retval="guessing yes" ;;
-                                     # Guess yes otherwise.
-            *)                       gl_cv_func_wcrtomb_retval="guessing yes" ;;
+            # Guess no on AIX 4, OSF/1, Solaris, native Windows.
+            aix4* | osf* | solaris* | mingw*) gl_cv_func_wcrtomb_retval="guessing no" ;;
+            # Guess yes otherwise.
+            *)                                gl_cv_func_wcrtomb_retval="guessing yes" ;;
           esac
 changequote([,])dnl
           if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
@@ -111,6 +109,7 @@ changequote([,])dnl
 #include <stdio.h>
 #include <time.h>
 #include <wchar.h>
+#include <stdlib.h>
 int main ()
 {
   int result = 0;
@@ -123,6 +122,12 @@ int main ()
     {
       if (wcrtomb (NULL, 0, NULL) != 1)
         result |= 2;
+      {
+        wchar_t wc = (wchar_t) 0xBADFACE;
+        if (mbtowc (&wc, "\303\274", 2) == 2)
+          if (wcrtomb (NULL, wc, NULL) != 1)
+            result |= 2;
+      }
     }
   if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
     {