svn commit: trunk/uClibc/libc: misc/wchar stdio stdlib string

carmelo at uclibc.org carmelo at uclibc.org
Tue Sep 9 13:01:58 UTC 2008


Author: carmelo
Date: 2008-09-09 06:01:58 -0700 (Tue, 09 Sep 2008)
New Revision: 23369

Log:
Fix some locale multibyte tests failures ad below:

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 <filippo.arcidiacono at st.com>
Signed-off-by: Carmelo Amoroso <carmelo.amoroso at st.com>


Modified:
   trunk/uClibc/libc/misc/wchar/wchar.c
   trunk/uClibc/libc/stdio/_scanf.c
   trunk/uClibc/libc/stdlib/_strtod.c
   trunk/uClibc/libc/stdlib/stdlib.c
   trunk/uClibc/libc/string/strncmp.c


Changeset:
Modified: trunk/uClibc/libc/misc/wchar/wchar.c
===================================================================
--- trunk/uClibc/libc/misc/wchar/wchar.c	2008-09-09 12:58:57 UTC (rev 23368)
+++ trunk/uClibc/libc/misc/wchar/wchar.c	2008-09-09 13:01:58 UTC (rev 23369)
@@ -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;
 			}
 		}

Modified: trunk/uClibc/libc/stdio/_scanf.c
===================================================================
--- trunk/uClibc/libc/stdio/_scanf.c	2008-09-09 12:58:57 UTC (rev 23368)
+++ trunk/uClibc/libc/stdio/_scanf.c	2008-09-09 13:01:58 UTC (rev 23369)
@@ -1068,9 +1068,6 @@
 		wc = '.';
 	} else
 #endif /* __UCLIBC_HAS_FLOATS__ */
-	if (!__isascii(wc)) {
-		wc = '?';
-	}
 	sc->wc = sc->ungot_char = wc;
 
 	return (int) wc;

Modified: trunk/uClibc/libc/stdlib/_strtod.c
===================================================================
--- trunk/uClibc/libc/stdlib/_strtod.c	2008-09-09 12:58:57 UTC (rev 23368)
+++ trunk/uClibc/libc/stdlib/_strtod.c	2008-09-09 13:01:58 UTC (rev 23369)
@@ -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;

Modified: trunk/uClibc/libc/stdlib/stdlib.c
===================================================================
--- trunk/uClibc/libc/stdlib/stdlib.c	2008-09-09 12:58:57 UTC (rev 23368)
+++ trunk/uClibc/libc/stdlib/stdlib.c	2008-09-09 13:01:58 UTC (rev 23369)
@@ -929,6 +929,30 @@
 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 +965,17 @@
 
 	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,18 @@
 
 	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 +1029,12 @@
 {
 	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));
 }
 

Modified: trunk/uClibc/libc/string/strncmp.c
===================================================================
--- trunk/uClibc/libc/string/strncmp.c	2008-09-09 12:58:57 UTC (rev 23368)
+++ trunk/uClibc/libc/string/strncmp.c	2008-09-09 13:01:58 UTC (rev 23369)
@@ -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;
 




More information about the uClibc-cvs mailing list