This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

PATCH (libstdc++-v3 libstdcxx_so_7-branch): Minor portability issue


In article <200501250151.j0P1pvfF008592@latour.waar.labs.mot.com>,
Loren James Rittle <rittle@latour.waar.labs.mot.com> writes:

> I will play with so_7-branch and install a clean version (aka the
> ABI-breaking version) of the wctype fix.

As installed, after required protocol (on i386-unknown-freebsd5.3).

Notes to other libstdc++ maintainers: I applied a tiny idiomatic
change along with the portable size computation.  I made an explicit
choice not to touch ./config/locale/gnu/ctype_members.cc since the
implementor may assume knowledge of the bit assignments in that case.
However, removing the magic there might be wise as well IMHO.
Finally, although this fixes the portability issue in the most direct
manner, I think that the current use of _M_bit and _M_wmask could be
redone to remove one of them without any losses in the generic case.
As Geoffrey observed, BSD-based systems actually need neither of them
and I suspect that gnu could be reworked as well.  If we really care
about memory space or other performance in this area, then I could
spend more time here.

Regards,
Loren

(Placed in ChangeLog.libstdcxx_so_7-branch:)
        * include/bits/locale_facets.h (ctype<wchar_t>::_M_bit):
        Base size on bits in __wmask_type.
	(ctype<wchar_t>::_M_wmask): Likewise. 
        * config/locale/generic/ctype_members.cc: Remove magic numbers.

Index: include/bits/locale_facets.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.h,v
retrieving revision 1.93.4.4
diff -c -r1.93.4.4 locale_facets.h
*** include/bits/locale_facets.h	6 Dec 2004 11:12:34 -0000	1.93.4.4
--- include/bits/locale_facets.h	25 Jan 2005 20:27:40 -0000
***************
*** 1,6 ****
  // Locale support -*- C++ -*-
  
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
  // Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
--- 1,6 ----
  // Locale support -*- C++ -*-
  
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
  // Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
***************
*** 1231,1238 ****
        wint_t                    _M_widen[1 + static_cast<unsigned char>(-1)];
  
        // Pre-computed elements for do_is.
!       mask                      _M_bit[16];
!       __wmask_type              _M_wmask[16];
  
      public:
        // Data Members:
--- 1231,1238 ----
        wint_t                    _M_widen[1 + static_cast<unsigned char>(-1)];
  
        // Pre-computed elements for do_is.
!       mask                      _M_bit[sizeof (__wmask_type) * __CHAR_BIT__];
!       __wmask_type              _M_wmask[sizeof (__wmask_type) * __CHAR_BIT__];
  
      public:
        // Data Members:
Index: config/locale/generic/ctype_members.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/locale/generic/ctype_members.cc,v
retrieving revision 1.12.4.1
diff -c -r1.12.4.1 ctype_members.cc
*** config/locale/generic/ctype_members.cc	17 Aug 2004 14:48:42 -0000	1.12.4.1
--- config/locale/generic/ctype_members.cc	25 Jan 2005 20:27:40 -0000
***************
*** 1,6 ****
  // std::ctype implementation details, generic version -*- C++ -*-
  
! // Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
--- 1,6 ----
  // std::ctype implementation details, generic version -*- C++ -*-
  
! // Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
***************
*** 131,140 ****
    do_is(mask __m, char_type __c) const
    { 
      bool __ret = false;
!     // Generically, 15 (instead of 10) since we don't know the numerical
!     // encoding of the various categories in /usr/include/ctype.h.
!     const size_t __bitmasksize = 15; 
!     for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
        if (__m & _M_bit[__bitcur]
  	  && iswctype(__c, _M_wmask[__bitcur]))
  	{
--- 131,138 ----
    do_is(mask __m, char_type __c) const
    { 
      bool __ret = false;
!     const size_t __bitmasksize = sizeof _M_bit / sizeof _M_bit[0]; 
!     for (size_t __bitcur = 0; __bitcur < __bitmasksize; ++__bitcur)
        if (__m & _M_bit[__bitcur]
  	  && iswctype(__c, _M_wmask[__bitcur]))
  	{
***************
*** 150,160 ****
    {
      for (;__lo < __hi; ++__vec, ++__lo)
        {
! 	// Generically, 15 (instead of 10) since we don't know the numerical
! 	// encoding of the various categories in /usr/include/ctype.h.
! 	const size_t __bitmasksize = 15; 
  	mask __m = 0;
! 	for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
  	  if (iswctype(*__lo, _M_wmask[__bitcur]))
  	    __m |= _M_bit[__bitcur];
  	*__vec = __m;
--- 148,156 ----
    {
      for (;__lo < __hi; ++__vec, ++__lo)
        {
! 	const size_t __bitmasksize = sizeof _M_bit / sizeof _M_bit[0]; 
  	mask __m = 0;
! 	for (size_t __bitcur = 0; __bitcur < __bitmasksize; ++__bitcur)
  	  if (iswctype(*__lo, _M_wmask[__bitcur]))
  	    __m |= _M_bit[__bitcur];
  	*__vec = __m;
***************
*** 257,263 ****
  	 __i < sizeof(_M_widen) / sizeof(wint_t); ++__i)
        _M_widen[__i] = btowc(__i);
  
!     for (size_t __i = 0; __i <= 15; ++__i)
        { 
  	_M_bit[__i] = static_cast<mask>(1 << __i);
  	_M_wmask[__i] = _M_convert_to_wmask(_M_bit[__i]);
--- 253,259 ----
  	 __i < sizeof(_M_widen) / sizeof(wint_t); ++__i)
        _M_widen[__i] = btowc(__i);
  
!     for (size_t __i = 0; __i < sizeof _M_bit / sizeof _M_bit[0]; ++__i)
        { 
  	_M_bit[__i] = static_cast<mask>(1 << __i);
  	_M_wmask[__i] = _M_convert_to_wmask(_M_bit[__i]);


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