bug-gnulib
[Top][All Lists]
Advanced

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

Re: Solaris 8 mbrtowc failure (was: snapshot 3 in preparation for 1.4.13


From: Bruno Haible
Subject: Re: Solaris 8 mbrtowc failure (was: snapshot 3 in preparation for 1.4.13)
Date: Thu, 26 Feb 2009 02:30:51 +0100
User-agent: KMail/1.9.9

Hi Gary,

> % cc -I. -mr -Qn -xstrconst -xO2 -xtarget=ultra2 -xarch=v8plusa \
> -o foo1 foo1.c
> % LC_ALL=zh_CN.GB18030 ./foo1
> 0x000000F0 2
> 
> % cc -I. -mr -Qn -xstrconst -xO2 -xtarget=ultra2 -xarch=v8plusa \
> -o foo2 foo2.c
> % LC_ALL=zh_CN.GB18030 ./foo2
> 0x00005EDC 4
> 
> > The expected output for both is:
> >  0x000000DF 4
> 
> Hmm.  Well, I hope that makes more sense to you than it does
> to me!!

Thanks for these results. The output on Solaris 9, for both programs, is
0x00005EDC 4
So that must be the right result. It means there is a bug in mbrtowc that is
not present in mbtowc. I'm applying the appended patch, to make gnulib use
the mbrtowc emulation with mbtowc in this case.

> >  checking whether mbrtowc handles incomplete characters... yes
> >  checking whether mbrtowc handles a NULL string argument... yes
> >  checking whether mbrtowc has a correct return value... no
> >  checking whether mbrtowc returns 0 when parsing a NUL character... 
> > guessing yes
> >  checking whether mbrtowc handles incomplete characters... (cached) yes
> >
> >  What was it in your case?
> 
> checking whether mbrtowc handles incomplete characters... guessing yes
> checking whether mbrtowc handles a NULL string argument... guessing yes
> checking whether mbrtowc has a correct return value... guessing no
> checking whether mbrtowc returns 0 when parsing a NUL character... no
> checking whether mbrtowc handles incomplete characters... (cached) guessing 
> yes

Oh, one of these five tests guessed wrong (in the absence of the locale that
is present on your system). I'm committing the second attached patch.


2009-02-25  Bruno Haible  <address@hidden>

        Work around mbrtowc bug in zh_CN.GB18030 locale on Solaris 8.
        * m4/mbrtowc.m4 (gl_MBRTOWC_SANITYCHECK): New macro.
        (gl_MBSTATE_T_BROKEN): Invoke it. Replace mbstate_t when it says "no".
        * doc/posix-functions/mbrtowc.texi: Document the Solaris 8 bug.
        Reported by Gary V. Vaughan <address@hidden>.

--- doc/posix-functions/mbrtowc.texi.orig       2009-02-26 02:18:07.000000000 
+0100
+++ doc/posix-functions/mbrtowc.texi    2009-02-26 01:42:55.000000000 +0100
@@ -16,6 +16,10 @@
 incomplete multibyte character on some platforms:
 AIX 5.1, OSF/1 5.1.
 @item
+This function does not produce correct results in the zh_CN.GB18030 locale on
+some platforms:
+Solaris 8.
address@hidden
 This function does not ignore the @code{pwc} argument if the string argument is
 NULL on some platforms:
 OSF/1 5.1.
--- m4/mbrtowc.m4.orig  2009-02-26 02:18:07.000000000 +0100
+++ m4/mbrtowc.m4       2009-02-26 02:14:24.000000000 +0100
@@ -1,4 +1,4 @@
-# mbrtowc.m4 serial 13
+# mbrtowc.m4 serial 14
 dnl Copyright (C) 2001-2002, 2004-2005, 2008, 2009 Free Software Foundation, 
Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -65,9 +65,15 @@
   AC_CHECK_FUNCS_ONCE([mbrtowc])
   if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then
     gl_MBRTOWC_INCOMPLETE_STATE
+    gl_MBRTOWC_SANITYCHECK
+    REPLACE_MBSTATE_T=0
     case "$gl_cv_func_mbrtowc_incomplete_state" in
-      *yes) REPLACE_MBSTATE_T=0 ;;
-      *)    REPLACE_MBSTATE_T=1 ;;
+      *yes) ;;
+      *) REPLACE_MBSTATE_T=1 ;;
+    esac
+    case "$gl_cv_func_mbrtowc_sanitycheck" in
+      *yes) ;;
+      *) REPLACE_MBSTATE_T=1 ;;
     esac
   else
     REPLACE_MBSTATE_T=1
@@ -126,6 +132,57 @@
     ])
 ])
 
+dnl Test whether mbrtowc works not worse than mbtowc.
+dnl Result is gl_cv_func_mbrtowc_sanitycheck.
+
+AC_DEFUN([gl_MBRTOWC_SANITYCHECK],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_ZH_CN])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc],
+    [gl_cv_func_mbrtowc_sanitycheck],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+                    # Guess no on Solaris 8.
+        solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;;
+                    # Guess yes otherwise.
+        *)          gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_ZH_CN != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  /* This fails on Solaris 8:
+     mbrtowc returns 2, and sets wc to 0x00F0.
+     mbtowc returns 4 (correct) and sets wc to 0x5EDC.  */
+  if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+    {
+      char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
+      mbstate_t state;
+      wchar_t wc;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (&wc, input + 3, 6, &state) != 4
+          && mbtowc (&wc, input + 3, 6) == 4)
+        return 1;
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrtowc_sanitycheck=yes],
+          [gl_cv_func_mbrtowc_sanitycheck=no],
+          [])
+      fi
+    ])
+])
+
 dnl Test whether mbrtowc supports a NULL string argument correctly.
 dnl Result is gl_cv_func_mbrtowc_null_arg.
 


2009-02-25  Bruno Haible  <address@hidden>

        * m4/mbrtowc.m4 (gl_MBRTOWC_NUL_RETVAL): Update guess for Solaris 8
        with known value.
        Reported by Gary V. Vaughan <address@hidden>.

--- m4/mbrtowc.m4.orig  2009-02-26 02:28:44.000000000 +0100
+++ m4/mbrtowc.m4       2009-02-26 02:27:12.000000000 +0100
@@ -315,10 +315,10 @@
       dnl is present.
 changequote(,)dnl
       case "$host_os" in
-                    # Guess no on Solaris 9.
-        solaris2.9) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
-                    # Guess yes otherwise.
-        *)          gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
+                       # Guess no on Solaris 8 and 9.
+        solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
+                       # Guess yes otherwise.
+        *)             gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
       esac
 changequote([,])dnl
       if test $LOCALE_ZH_CN != none; then
@@ -328,7 +328,7 @@
 #include <wchar.h>
 int main ()
 {
-  /* This fails on Solaris 9.  */
+  /* This fails on Solaris 8 and 9.  */
   if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
     {
       mbstate_t state;




reply via email to

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