Hi all,
The following patch solve several locale multibyte tests failures. 
It has been tested and works fine.
The patch applies to the latest trunk revision.

Any comment are welcome.

Best Regards,
Filippo.

This patch fixes several locale tests:

libc/stdlib/_strtod.c   -> tst_wcstod;
libc/stdlib/stdlib.c    -> tst_mblen, tst_mbtowc, tst_wctomb;
libc/stdio/_scanf.c     -> tst_swscanf;
libc/string/strncmp.c   -> tst_wcsncmp;
libc/misc/wchar/wchar.c -> tst_mbrlen, tst_mbrtowc, tst_wcswidth.

Signed-off-by: Filippo Arcidiacono <[EMAIL PROTECTED]>

Index: libc/stdlib/_strtod.c
===================================================================
--- libc/stdlib/_strtod.c       (revision 22698)
+++ libc/stdlib/_strtod.c       (working copy)
@@ -234,7 +234,7 @@
 #endif
 #ifdef __UCLIBC_HAS_LOCALE__
 #if defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
-       wchar_t decpt_wc = __LOCALE_PTR->decimal_point;
+       wchar_t decpt_wc = __LOCALE_PTR->decimal_point_wc;
 #else
        const char *decpt = __LOCALE_PTR->decimal_point;
        int decpt_len = __LOCALE_PTR->decimal_point_len;
Index: libc/stdlib/stdlib.c
===================================================================
--- libc/stdlib/stdlib.c        (revision 22698)
+++ libc/stdlib/stdlib.c        (working copy)
@@ -929,6 +929,31 @@
 libc_hidden_def(_stdlib_mb_cur_max)
 
 #endif
+
+#ifdef __UCLIBC_HAS_LOCALE__
+/* 
+ * The following function return 1 if the encoding is stateful, 0 if stateless.
+ * To note, until now all the supported encoding are stateless.
+ */
+ 
+static inline int
+is_stateful(unsigned char encoding)
+{
+       switch (encoding) 
+       {
+               case __ctype_encoding_7_bit:
+               case __ctype_encoding_utf8:
+               case __ctype_encoding_8_bit:
+                       return 0;
+               default:
+                       assert(0);
+                       return -1;
+       }
+}
+#else
+#define is_stateful(encoding) 0
+#endif
+
 /**********************************************************************/
 #ifdef L_mblen
 
@@ -941,13 +966,16 @@
 
        if (!s) {
                state.__mask = 0;
-#ifdef __CTYPE_HAS_UTF_8_LOCALES
-               return ENCODING == __ctype_encoding_utf8;
-#else
-               return 0;
-#endif
+/* In this case we have to return 0 because the only multibyte supported 
encoding
+   is utf-8, that is a stateless encoding. See mblen() documentation.*/
+   
+               return is_stateful(ENCODING);
        }
 
+       if (*s == '\0')
+    /* According to the ISO C 89 standard this is the expected behaviour.  */
+               return 0;
+       
        if ((r = mbrlen(s, n, &state)) == (size_t) -2) {
                /* TODO: Should we set an error state? */
                state.__wc = 0xffffU;   /* Make sure we're in an error state. */
@@ -969,13 +997,15 @@
 
        if (!s) {
                state.__mask = 0;
-#ifdef __CTYPE_HAS_UTF_8_LOCALES
-               return ENCODING == __ctype_encoding_utf8;
-#else
-               return 0;
-#endif
+/* In this case we have to return 0 because the only multibyte supported 
encoding
+   is utf-8, that is a stateless encoding. See mbtowc() documentation.*/
+               return is_stateful(ENCODING);
        }
 
+       if (*s == '\0')
+    /* According to the ISO C 89 standard this is the expected behaviour.  */
+               return 0;
+       
        if ((r = mbrtowc(pwc, s, n, &state)) == (size_t) -2) {
                /* TODO: Should we set an error state? */
                state.__wc = 0xffffU;   /* Make sure we're in an error state. */
@@ -996,11 +1026,9 @@
 {
        return (!s)
                ?
-#ifdef __CTYPE_HAS_UTF_8_LOCALES
-               (ENCODING == __ctype_encoding_utf8)
-#else
-               0                                               /* Encoding is 
stateless. */
-#endif
+/* In this case we have to return 0 because the only multibyte supported 
encoding
+   is utf-8, that is a stateless encoding. See wctomb() documentation.*/
+               is_stateful(ENCODING)
                : ((ssize_t) wcrtomb(s, swc, NULL));
 }
 
Index: libc/stdio/_scanf.c
===================================================================
--- libc/stdio/_scanf.c (revision 22698)
+++ libc/stdio/_scanf.c (working copy)
@@ -1068,9 +1068,6 @@
                wc = '.';
        } else
 #endif /* __UCLIBC_HAS_FLOATS__ */
-       if (!__isascii(wc)) {
-               wc = '?';
-       }
        sc->wc = sc->ungot_char = wc;
 
        return (int) wc;
Index: libc/string/strncmp.c
===================================================================
--- libc/string/strncmp.c       (revision 22698)
+++ libc/string/strncmp.c       (working copy)
@@ -25,7 +25,7 @@
                --n;
        }
 
-       return (n == 0) ? 0 : ((*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1);
+       return (n == 0) ? 0 : (*((Wuchar *)s1) - *((Wuchar *)s2));
 #else
        int r = 0;
 
Index: libc/misc/wchar/wchar.c
===================================================================
--- libc/misc/wchar/wchar.c     (revision 22698)
+++ libc/misc/wchar/wchar.c     (working copy)
@@ -293,10 +293,17 @@
                empty_string[0] = 0;    /* Init the empty string when 
necessary. */
                s = empty_string;
                n = 1;
+       } else if (*s == '\0') {
+    /* According to the ISO C 89 standard this is the expected behaviour.  */
+               return 0;
        } else if (!n) {
                /* TODO: change error code? */
+#if 0
                return (ps->__mask && (ps->__wc == 0xffffU))
                        ? ((size_t) -1) : ((size_t) -2);
+#else
+               return 0;
+#endif
        }
 
        p = s;
@@ -865,7 +872,6 @@
                                                                        + (wc & 
((1 << Cwc2c_TT_SHIFT)-1))];
                                }
 
-#define __WCHAR_REPLACEMENT_CHAR '?'
 #ifdef __WCHAR_REPLACEMENT_CHAR
                                *dst = (unsigned char) ( u ? u : 
__WCHAR_REPLACEMENT_CHAR );
 #else  /* __WCHAR_REPLACEMENT_CHAR */
@@ -1045,7 +1051,7 @@
                size_t i;
                
                for (i = 0 ; (i < n) && pwcs[i] ; i++) {
-                       if (pwcs[i] != ((unsigned char)(pwcs[i]))) {
+                       if (pwcs[i] != (pwcs[i] & 0x7f)) {
                                return -1;
                        }
                }

_______________________________________________
uClibc mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/uclibc

Reply via email to