This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH/RFA] Internationalize ctype functionality


On Apr  1 15:46, Hans-Peter Nilsson wrote:
> > Date: Wed, 1 Apr 2009 15:15:22 +0200
> > From: Corinna Vinschen <vinschen-mail-follow-up-to-set@redhat.com>
> 
> > On Apr  1 14:38, Hans-Peter Nilsson wrote:
> > > > From: Corinna Vinschen <XXXXXXXX@XXXXXX.XXX>
> > > 
> > > > The __set_ctype function is called for every target which has
> > > > _MB_CAPABLE set.
> > > 
> > > So presumably having __ctype_ptr__ const for other targets is
> > > ok, like in the patch I sent.
> > 
> > Yes, that should work, provided you do the same in libc/ctype/ctype_.c.
> 
> That part was already there, effectively... oh, you mean some
> deliberate means; testing _MB_CAPABLE.  Right.  Patch
> forthcoming.  After *cough* testing (though it'll just be
> cris-elf, a !_MB_CAPABLE target; not wanting to...raise the
> testing bar).

As I wrote in my previous mail, I have included that in my local version
of the patch adding the missing code for the !ALLOW_NEGATIVE_CTYPE_INDEX
case.  I've included the entire patch agin in this mail, for completeness.

I built ctype_.c with excessive warning level for all combinations of
ALLOW_NEGATIVE_CTYPE_INDEX and _MB_CAPABLE and gcc seems to be happy now.


Corinna


	* libc/ctype/ctype_c.c: Move inclusion of ctype_iso.h and
	ctype_cp.h out of ALLOW_NEGATIVE_CTYPE_INDEX case.
	(_ctype_b): Constify in !_MB_CAPABLE case.  Restrict !static
	to Cygwin.
	(__ctype_ptr__): Constify in !_MB_CAPABLE case.  Otherwise,
	de-constify in !ALLOW_NEGATIVE_CTYPE_INDEX case, too.  Add comment.
	(__set_ctype): Set __ctype_ptr__ pointer according to definition
	of ALLOW_NEGATIVE_CTYPE_INDEX.
	* libc/include/ctype.h (__ctype_ptr__): Constify in !_MB_CAPABLE case.


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 15:11:21 -0000
@@ -77,11 +77,25 @@ 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. */
+/* No static on Cygwin since it's referenced and potentially overwritten
+   for compatibility with older applications.
+   No _CONST on _MB_CAPABLE targets since the pointer is changed according
+   to the current locale. */
 #ifndef __CYGWIN__
-static _CONST
+static
+#endif
+#ifndef _MB_CAPABLE
+_CONST
 #endif
 char _ctype_b[128 + 256] = {
 	_CTYPE_DATA_128_256,
@@ -89,15 +103,9 @@ 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"
+#ifndef _MB_CAPABLE
+_CONST
 #endif
-#endif
-
 char __EXPORT *__ctype_ptr__ = _ctype_b + 127;
 
 #  ifdef __CYGWIN__
@@ -120,7 +128,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 +138,11 @@ _CONST char _ctype_[1 + 256] = {
 	_CTYPE_DATA_128_256
 };
 
-_CONST char *__ctype_ptr__ = _ctype_;
+#ifndef _MB_CAPABLE
+_CONST
+#endif
+char *__ctype_ptr__ = (char *) _ctype_;
+
 #endif
 
 #if defined(_MB_CAPABLE)
@@ -140,7 +152,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 +168,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 +180,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 */
Index: libc/include/ctype.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/ctype.h,v
retrieving revision 1.15
diff -u -p -r1.15 ctype.h
--- libc/include/ctype.h	31 Mar 2009 09:31:38 -0000	1.15
+++ libc/include/ctype.h	1 Apr 2009 15:11:21 -0000
@@ -39,6 +39,9 @@ int _EXFUN(toascii, (int __c));
 #define _X	0100
 #define	_B	0200
 
+#ifndef _MB_CAPABLE
+_CONST
+#endif
 extern	__IMPORT char	*__ctype_ptr__;
 
 #ifndef __cplusplus

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]