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: Fun with magic numbers and the various system headers


Hey Benjamin (as the primary author/maintainer),

This issue was originally found on Darwin by Geoffrey back in
http://gcc.gnu.org/ml/libstdc++/2004-10/msg00455.html .
I found it independently but his report was triggered by memory.

This patch would kill another 2 FAILs on FreeBSD 5 [AFAIR, FreeBSD 4
never defined _GLIBCXX_USE_WCHAR_T].  mask (AKA wctype_t) is a 32-bit
entity on FreeBSD and that is an allowable choice by POSIX.  Thus, it
appears that the original code has a minor portability bug.  Is
changing this class, ctype<wchar_t>, an effective ABI change (Geoffrey
thought so)?  It is exposed in an installed header but I haven't yet
traced how it is actually used in the library and/or user code.  If
the use is completely inside the library, then I'd suppose it is not
really an ABI change.  However, are we that lucky?

Please consider and I will put this patch into a final form (e.g.  I
see I should have used "* CHAR_BIT" or "* __CHAR_BIT__" instead of "*
8" myself) or create one that mirrors Geoffrey's solution for Darwin
[if indeed an ABI change].  He claimed an efficiency gain (and I'd
agree at first glance).

OK, other than the 3 FAILs related to the unimplemented math function
issue (which appears to have a decent solution after all; thanks
Guys!) and pending this wchar_t fix, all I now see are another two
non-threaded wchar_t tests which only fail when tested against
-pthread (and I'm sure that will be a fun nightmare to debug).

Sorry I didn't spot this portability issue way back when it went in...

Regards,
Loren

Index: libstdc++-v3/include/bits/locale_facets.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.h,v
retrieving revision 1.98
diff -c -r1.98 locale_facets.h
*** libstdc++-v3/include/bits/locale_facets.h	23 Nov 2004 09:18:39 -0000	1.98
--- libstdc++-v3/include/bits/locale_facets.h	24 Jan 2005 20:45:33 -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 (mask) * 8];
!       __wmask_type              _M_wmask[sizeof (mask) * 8];
  
      public:
        // Data Members:
Index: libstdc++-v3/config/locale/generic/ctype_members.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/locale/generic/ctype_members.cc,v
retrieving revision 1.13
diff -c -r1.13 ctype_members.cc
*** libstdc++-v3/config/locale/generic/ctype_members.cc	12 Aug 2004 09:46:38 -0000	1.13
--- libstdc++-v3/config/locale/generic/ctype_members.cc	24 Jan 2005 20:45:33 -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,139 ****
    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,140 ----
    do_is(mask __m, char_type __c) const
    { 
      bool __ret = false;
!     // Generically, sizeof (mask) * 8 - 1 (instead of 10)
!     // since we don't know the numerical
      // encoding of the various categories in /usr/include/ctype.h.
!     const size_t __bitmasksize = sizeof (mask) * 8 - 1; 
      for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
        if (__m & _M_bit[__bitcur]
  	  && iswctype(__c, _M_wmask[__bitcur]))
***************
*** 150,158 ****
    {
      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]))
--- 151,157 ----
    {
      for (;__lo < __hi; ++__vec, ++__lo)
        {
! 	const size_t __bitmasksize = sizeof (mask) * 8 - 1; 
  	mask __m = 0;
  	for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
  	  if (iswctype(*__lo, _M_wmask[__bitcur]))
***************
*** 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]);
--- 256,262 ----
  	 __i < sizeof(_M_widen) / sizeof(wint_t); ++__i)
        _M_widen[__i] = btowc(__i);
  
!     for (size_t __i = 0; __i <= sizeof (mask) * 8 - 1; ++__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]