[PATCH/RFA] Internationalize ctype functionality
Corinna Vinschen
vinschen@redhat.com
Wed Apr 1 12:38:00 GMT 2009
On Apr 1 03:24, Hans-Peter Nilsson wrote:
> > Date: Tue, 31 Mar 2009 11:31:50 +0200
> > From: Corinna Vinschen <vinschen AT redhat DOT com>
>
> > Thanks, applied.
>
> I get, for cris-elf:
> [...]
> --- pre/newlib/libc/ctype/ctype_.c Thu Mar 26 11:02:16 2009
> +++ aft/newlib/libc/ctype/ctype_.c Tue Mar 31 11:47:32 2009
> ...
> -# if defined(__CYGWIN__)
> -_CONST char __declspec(dllexport) *__ctype_ptr = _ctype_b + 128;
> -_CONST char __declspec(dllexport) *__ctype_ptr__ = _ctype_b + 127;
> -# else
> -_CONST char *__ctype_ptr = _ctype_b + 128;
> -_CONST char *__ctype_ptr__ = _ctype_b + 127;
> -# endif
> ... (at line 101):
> +char __EXPORT *__ctype_ptr__ = _ctype_b + 127;
>
> Still unpatched at line 133:
> _CONST char *__ctype_ptr__ = _ctype_;
>
> --- pre/newlib/libc/include/ctype.h Thu Mar 26 11:02:16 2009
> +++ aft/newlib/libc/include/ctype.h Tue Mar 31 11:47:32 2009
> ...
> @@ -39,7 +39,7 @@ int _EXFUN(_toupper, (int __c));
> #define _X 0100
> #define _B 0200
>
> -extern __IMPORT _CONST char *__ctype_ptr__;
> +extern __IMPORT char *__ctype_ptr__;
>
> Besides, IMHO you could have made that last +-line in ctype.h:
>
> +#ifndef _MB_CAPABLE
> +_CONST
> +#endif
> +extern __IMPORT char *__ctype_ptr__;
>
> (or something) to avoid deconstify __ctype_ptr__ for all other
> targets that didn't change semantics, IIUC. I'll let you guys
> sort out what the fix should be, but will fix it as above if
> preapproved.
Actually, what I really had in mind was the patch below. The new
functionality was supposed to be available for all targets, not only for
the targets defining ALLOW_NEGATIVE_CTYPE_INDEX.
The __set_ctype function is called for every target which has
_MB_CAPABLE set. If you constify __ctype_ptr__, you would disallow the
__set_ctype functionality for every !ALLOW_NEGATIVE_CTYPE_INDEX target.
Please note that the actual character class arrays are still const.
Only the pointer used in the ctype functions isn't.
Corinna
* libc/ctype/ctype_c.c: Move inclusion of ctype_iso.h and
ctype_cp.h out of ALLOW_NEGATIVE_CTYPE_INDEX case.
(__ctype_ptr__): De-constify in !ALLOW_NEGATIVE_CTYPE_INDEX case.
(__set_ctype): Set __ctype_ptr__ pointer according to definition
of ALLOW_NEGATIVE_CTYPE_INDEX.
Index: libc/ctype/ctype_.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/ctype_.c,v
retrieving revision 1.7
diff -u -p -r1.7 ctype_.c
--- libc/ctype/ctype_.c 31 Mar 2009 09:31:38 -0000 1.7
+++ libc/ctype/ctype_.c 1 Apr 2009 08:16:58 -0000
@@ -77,6 +77,15 @@ static char sccsid[] = "@(#)ctype_.c 5.6
#define ALLOW_NEGATIVE_CTYPE_INDEX
#endif
+#if defined(_MB_CAPABLE)
+#if defined(_MB_EXTENDED_CHARSETS_ISO)
+#include "ctype_iso.h"
+#endif
+#if defined(_MB_EXTENDED_CHARSETS_WINDOWS)
+#include "ctype_cp.h"
+#endif
+#endif
+
#if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
/* No static const on Cygwin since it's referenced and potentially overwritten
for compatibility with older applications. */
@@ -89,15 +98,6 @@ char _ctype_b[128 + 256] = {
_CTYPE_DATA_128_256
};
-#if defined(_MB_CAPABLE)
-#if defined(_MB_EXTENDED_CHARSETS_ISO)
-#include "ctype_iso.h"
-#endif
-#if defined(_MB_EXTENDED_CHARSETS_WINDOWS)
-#include "ctype_cp.h"
-#endif
-#endif
-
char __EXPORT *__ctype_ptr__ = _ctype_b + 127;
# ifdef __CYGWIN__
@@ -120,7 +120,7 @@ _CONST char _ctype_[1 + 256] = {
_CTYPE_DATA_0_127,
_CTYPE_DATA_128_256
};
-# endif /* !_HAVE_ARRAY_ALIASING */
+# endif /* !_HAVE_ARRAY_ALIASING */
#else /* !defined(ALLOW_NEGATIVE_CTYPE_INDEX) */
@@ -130,7 +130,8 @@ _CONST char _ctype_[1 + 256] = {
_CTYPE_DATA_128_256
};
-_CONST char *__ctype_ptr__ = _ctype_;
+char *__ctype_ptr__ = (char *) _ctype_;
+
#endif
#if defined(_MB_CAPABLE)
@@ -140,7 +141,9 @@ _CONST char *__ctype_ptr__ = _ctype_;
void
__set_ctype (const char *charset)
{
+#if defined(_MB_EXTENDED_CHARSETS_ISO) || defined(_MB_EXTENDED_CHARSETS_WINDOWS)
int idx;
+#endif
switch (*charset)
{
@@ -154,7 +157,11 @@ __set_ctype (const char *charset)
idx = 0;
else
++idx;
+# if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
__ctype_ptr__ = (char *) (__ctype_iso[idx] + 127);
+# else
+ __ctype_ptr__ = (char *) __ctype_iso[idx];
+# endif
return;
#endif
#if defined(_MB_EXTENDED_CHARSETS_WINDOWS)
@@ -162,13 +169,21 @@ __set_ctype (const char *charset)
idx = __cp_index (charset + 2);
if (idx < 0)
break;
+# if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
__ctype_ptr__ = (char *) (__ctype_cp[idx] + 127);
+# else
+ __ctype_ptr__ = (char *) __ctype_cp[idx];
+# endif
return;
#endif
default:
break;
}
+# if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
__ctype_ptr__ = (char *) _ctype_b + 127;
+# else
+ __ctype_ptr__ = (char *) _ctype_;
+# endif
}
#endif /* !__CYGWIN__ */
#endif /* _MB_CAPABLE */
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat
More information about the Newlib
mailing list