[libstdc++v3]: Patch to ctype-noninline.h for mingw32

Danny Smith danny_r_smith_2001@yahoo.co.nz
Fri Jan 18 16:46:00 GMT 2002


 --- Benjamin Kosnik <bkoz@redhat.com> wrote: > 
> > _pctype points to ctype table for current locale, while _ctype[] is
> > the classic C-locale table and is the correct choice for default
> > initialisation.
> 
> Hmm. I didn't know that.

I didn't either. I couldn't find any MS documentation.   My statement is
inferred from experimentation. _ctype + 1 is constant (address in dll) as
change locales , _pctype is same as _ctype + 1 at programme startup, but
changes to new address with each call to setlocale.

 You might want to look at the gnu-linux bits to 
> see how this is handled.
> 
> > +  _M_table(__table == 0 ? _S_ctable : __table)  
>               __table ? __table : _S_ctable
> 
> -benjamin 

OK, revised patch:

ChangeLog

	2002-01-18  Danny Smith  <dannysmith@users.sourceforge.net>
 
	* config/os/mingw32/bits/ctype_noninline.h: Declare _ctype
	instead of _pctype. Use to define _S_ctable.
	Add definition for alternate ctor.
	Initialise _M_ctable to _S_ctable in ctors.
	(do_toupper, do_tolower): Use inline code appropriate for C-locale
	rather than ::toupper, ::tolower.


Index: bits/ctype_noninline.h
===================================================================
RCS file:
/cvs/gcc/gcc/libstdc++-v3/config/os/mingw32/bits/ctype_noninline.h,v
retrieving revision 1.2
diff -u -p -r1.2 ctype_noninline.h
--- ctype_noninline.h	2002/01/16 19:57:29	1.2
+++ ctype_noninline.h	2002/01/18 23:26:53
@@ -33,26 +33,41 @@
   
 // Information as gleaned from /mingw32/include/ctype.h.
 
-// This should be in mingw's ctype.h but isn't in older versions
+  // This should be in mingw's ctype.h but isn't in older versions
+  // Static classic C-locale table.  _ctype[0] is EOF
+  extern "C"  unsigned short  __declspec(dllimport) _ctype[];
+
+  // Data for classic_table().
+  const ctype_base::mask*  ctype<char>::_S_ctable = _ctype + 1; 
 
-  extern "C"  unsigned short*  __declspec(dllimport) _pctype;  
 
+  ctype<char>::ctype(__c_locale, const mask* __table = 0, bool __del =
false, 
+		     size_t __refs = 0) 
+  : __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del), 
+  _M_toupper(NULL), _M_tolower(NULL),
+  _M_table(__table ? __table : _S_ctable)  
+  { }
+
   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
-    : __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del), 
-      _M_toupper(NULL), _M_tolower(NULL),
-      _M_ctable(NULL), _M_table(__table == 0 ? (_pctype) : __table) 
-    { }
+  : __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del), 
+  _M_toupper(NULL), _M_tolower(NULL),
+  _M_table(__table ? __table : _S_ctable) 
+  { }
+
 
   char
   ctype<char>::do_toupper(char __c) const
-  { return ::toupper((int) __c); }
+  {
+    return (this->is(ctype_base::lower, __c) ?
+            (__c - 'a' + 'A') : __c);
+  }
 
   const char*
   ctype<char>::do_toupper(char* __low, const char* __high) const
   {
     while (__low < __high)
       {
-	*__low = ::toupper((int) *__low);
+	*__low = this->do_toupper(*__low);
 	++__low;
       }
     return __high;
@@ -60,14 +75,17 @@
 
   char
   ctype<char>::do_tolower(char __c) const
-  { return ::tolower((int) __c); }
+  { 
+    return (this->is(ctype_base::upper, __c) ?
+            (__c - 'A' + 'a') : __c);
+  }
 
   const char* 
   ctype<char>::do_tolower(char* __low, const char* __high) const
   {
     while (__low < __high)
       {
-	*__low = ::tolower((int) *__low);
+	*__low = this->do_tolower(*__low);
 	++__low;
       }
     return __high;


http://my.yahoo.com.au - My Yahoo!
- It's My Yahoo! Get your own!



More information about the Gcc-patches mailing list