patches/gcc/4.3.0/350-uclibc-locale-update.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jul 28 21:32:33 2008 +0000 (2008-07-28)
changeset 747 d3e603e7c17c
parent 746 patches/gcc/4.3.0/725-uclibc-locale-update.patch@b150d6f590fc
permissions -rw-r--r--
Fourth step at renaming patches: renumber all patches with a 10-step.
     1 Original patch from gentoo: gentoo/src/patchsets/gcc/4.3.0/uclibc/90_all_205-uclibc-locale-update.patch
     2 diff -durN gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/c_locale.cc gcc-4.3.0/libstdc++-v3/config/locale/uclibc/c_locale.cc
     3 --- gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/c_locale.cc	2008-06-10 14:45:43.000000000 +0200
     4 +++ gcc-4.3.0/libstdc++-v3/config/locale/uclibc/c_locale.cc	2008-06-10 14:45:46.000000000 +0200
     5 @@ -46,16 +46,13 @@
     6      __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err, 
     7  		   const __c_locale& __cloc)
     8      {
     9 -      if (!(__err & ios_base::failbit))
    10 -	{
    11 -	  char* __sanity;
    12 -	  errno = 0;
    13 -	  float __f = __strtof_l(__s, &__sanity, __cloc);
    14 -          if (__sanity != __s && errno != ERANGE)
    15 -	    __v = __f;
    16 -	  else
    17 -	    __err |= ios_base::failbit;
    18 -	}
    19 +      char* __sanity;
    20 +      errno = 0;
    21 +      float __f = __strtof_l(__s, &__sanity, __cloc);
    22 +      if (__sanity != __s && errno != ERANGE)
    23 +	__v = __f;
    24 +      else
    25 +	__err |= ios_base::failbit;
    26      }
    27  
    28    template<>
    29 @@ -63,16 +60,13 @@
    30      __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err, 
    31  		   const __c_locale& __cloc)
    32      {
    33 -      if (!(__err & ios_base::failbit))
    34 -	{
    35 -	  char* __sanity;
    36 -	  errno = 0;
    37 -	  double __d = __strtod_l(__s, &__sanity, __cloc);
    38 -          if (__sanity != __s && errno != ERANGE)
    39 -	    __v = __d;
    40 -	  else
    41 -	    __err |= ios_base::failbit;
    42 -	}
    43 +      char* __sanity;
    44 +      errno = 0;
    45 +      double __d = __strtod_l(__s, &__sanity, __cloc);
    46 +      if (__sanity != __s && errno != ERANGE)
    47 +	__v = __d;
    48 +      else
    49 +	__err |= ios_base::failbit;
    50      }
    51  
    52    template<>
    53 @@ -80,16 +74,13 @@
    54      __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
    55  		   const __c_locale& __cloc)
    56      {
    57 -      if (!(__err & ios_base::failbit))
    58 -	{
    59 -	  char* __sanity;
    60 -	  errno = 0;
    61 -	  long double __ld = __strtold_l(__s, &__sanity, __cloc);
    62 -          if (__sanity != __s && errno != ERANGE)
    63 -	    __v = __ld;
    64 -	  else
    65 -	    __err |= ios_base::failbit;
    66 -	}
    67 +      char* __sanity;
    68 +      errno = 0;
    69 +      long double __ld = __strtold_l(__s, &__sanity, __cloc);
    70 +      if (__sanity != __s && errno != ERANGE)
    71 +	__v = __ld;
    72 +      else
    73 +	__err |= ios_base::failbit;
    74      }
    75  
    76    void
    77 @@ -110,7 +101,7 @@
    78    void
    79    locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
    80    {
    81 -    if (_S_get_c_locale() != __cloc)
    82 +    if (__cloc && _S_get_c_locale() != __cloc)
    83        __freelocale(__cloc); 
    84    }
    85  
    86 diff -durN gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/c_locale.h gcc-4.3.0/libstdc++-v3/config/locale/uclibc/c_locale.h
    87 --- gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/c_locale.h	2008-06-10 14:45:43.000000000 +0200
    88 +++ gcc-4.3.0/libstdc++-v3/config/locale/uclibc/c_locale.h	2008-06-10 14:45:46.000000000 +0200
    89 @@ -39,21 +39,23 @@
    90  #pragma GCC system_header
    91  
    92  #include <cstring>              // get std::strlen
    93 -#include <cstdio>               // get std::snprintf or std::sprintf
    94 +#include <cstdio>               // get std::vsnprintf or std::vsprintf
    95  #include <clocale>
    96  #include <langinfo.h>		// For codecvt
    97  #ifdef __UCLIBC_MJN3_ONLY__
    98  #warning fix this
    99  #endif
   100 -#ifdef __UCLIBC_HAS_LOCALE__
   101 +#ifdef _GLIBCXX_USE_ICONV
   102  #include <iconv.h>		// For codecvt using iconv, iconv_t
   103  #endif
   104 -#ifdef __UCLIBC_HAS_GETTEXT_AWARENESS__
   105 -#include <libintl.h> 		// For messages
   106 +#ifdef HAVE_LIBINTL_H
   107 +#include <libintl.h>		// For messages
   108  #endif
   109 +#include <cstdarg>
   110  
   111  #ifdef __UCLIBC_MJN3_ONLY__
   112  #warning what is _GLIBCXX_C_LOCALE_GNU for
   113 +// psm: used in os/gnu-linux/ctype_noninline.h
   114  #endif
   115  #define _GLIBCXX_C_LOCALE_GNU 1
   116  
   117 @@ -62,7 +64,7 @@
   118  #endif
   119  // #define _GLIBCXX_NUM_CATEGORIES 6
   120  #define _GLIBCXX_NUM_CATEGORIES 0
   121 - 
   122 +
   123  #ifdef __UCLIBC_HAS_XLOCALE__
   124  namespace __gnu_cxx
   125  {
   126 @@ -79,22 +81,24 @@
   127    typedef int*			__c_locale;
   128  #endif
   129  
   130 -  // Convert numeric value of type _Tv to string and return length of
   131 -  // string.  If snprintf is available use it, otherwise fall back to
   132 -  // the unsafe sprintf which, in general, can be dangerous and should
   133 +  // Convert numeric value of type double to string and return length of
   134 +  // string.  If vsnprintf is available use it, otherwise fall back to
   135 +  // the unsafe vsprintf which, in general, can be dangerous and should
   136    // be avoided.
   137 -  template<typename _Tv>
   138 -    int
   139 -    __convert_from_v(char* __out, 
   140 -		     const int __size __attribute__ ((__unused__)),
   141 -		     const char* __fmt,
   142 -#ifdef __UCLIBC_HAS_XCLOCALE__
   143 -		     _Tv __v, const __c_locale& __cloc, int __prec)
   144 +    inline int
   145 +    __convert_from_v(const __c_locale&
   146 +#ifndef __UCLIBC_HAS_XCLOCALE__
   147 +					__cloc __attribute__ ((__unused__))
   148 +#endif
   149 +		     ,
   150 +		     char* __out,
   151 +		     const int __size,
   152 +		     const char* __fmt, ...)
   153      {
   154 +      va_list __args;
   155 +#ifdef __UCLIBC_HAS_XCLOCALE__
   156        __c_locale __old = __gnu_cxx::__uselocale(__cloc);
   157  #else
   158 -		     _Tv __v, const __c_locale&, int __prec)
   159 -    {
   160  # ifdef __UCLIBC_HAS_LOCALE__
   161        char* __old = std::setlocale(LC_ALL, NULL);
   162        char* __sav = new char[std::strlen(__old) + 1];
   163 @@ -103,7 +107,9 @@
   164  # endif
   165  #endif
   166  
   167 -      const int __ret = std::snprintf(__out, __size, __fmt, __prec, __v);
   168 +      va_start(__args, __fmt);
   169 +      const int __ret = std::vsnprintf(__out, __size, __fmt, __args);
   170 +      va_end(__args);
   171  
   172  #ifdef __UCLIBC_HAS_XCLOCALE__
   173        __gnu_cxx::__uselocale(__old);
   174 diff -durN gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/ctype_members.cc gcc-4.3.0/libstdc++-v3/config/locale/uclibc/ctype_members.cc
   175 --- gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/ctype_members.cc	2008-06-10 14:45:43.000000000 +0200
   176 +++ gcc-4.3.0/libstdc++-v3/config/locale/uclibc/ctype_members.cc	2008-06-10 14:45:46.000000000 +0200
   177 @@ -33,9 +33,14 @@
   178  
   179  // Written by Benjamin Kosnik <bkoz@redhat.com>
   180  
   181 +#include <features.h>
   182 +#ifdef __UCLIBC_HAS_LOCALE__
   183  #define _LIBC
   184  #include <locale>
   185  #undef _LIBC
   186 +#else
   187 +#include <locale>
   188 +#endif
   189  #include <bits/c++locale_internal.h>
   190  
   191  namespace std
   192 @@ -138,20 +143,34 @@
   193    ctype<wchar_t>::
   194    do_is(mask __m, wchar_t __c) const
   195    { 
   196 -    // Highest bitmask in ctype_base == 10, but extra in "C"
   197 -    // library for blank.
   198 +    // The case of __m == ctype_base::space is particularly important,
   199 +    // due to its use in many istream functions.  Therefore we deal with
   200 +    // it first, exploiting the knowledge that on GNU systems _M_bit[5]
   201 +    // is the mask corresponding to ctype_base::space.  NB: an encoding
   202 +    // change would not affect correctness!
   203      bool __ret = false;
   204 -    const size_t __bitmasksize = 11; 
   205 -    for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
   206 -      if (__m & _M_bit[__bitcur]
   207 -	  && __iswctype_l(__c, _M_wmask[__bitcur], _M_c_locale_ctype))
   208 -	{
   209 -	  __ret = true;
   210 -	  break;
   211 -	}
   212 +    if (__m == _M_bit[5])
   213 +      __ret = __iswctype_l(__c, _M_wmask[5], _M_c_locale_ctype);
   214 +    else
   215 +      {
   216 +	// Highest bitmask in ctype_base == 10, but extra in "C"
   217 +	// library for blank.
   218 +	const size_t __bitmasksize = 11;
   219 +	for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
   220 +	  if (__m & _M_bit[__bitcur])
   221 +	    {
   222 +	      if (__iswctype_l(__c, _M_wmask[__bitcur], _M_c_locale_ctype))
   223 +		{
   224 +		  __ret = true;
   225 +		  break;
   226 +		}
   227 +	      else if (__m == _M_bit[__bitcur])
   228 +		break;
   229 +	    }
   230 +      }
   231      return __ret;    
   232    }
   233 -  
   234 +
   235    const wchar_t* 
   236    ctype<wchar_t>::
   237    do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __vec) const
   238 diff -durN gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/messages_members.h gcc-4.3.0/libstdc++-v3/config/locale/uclibc/messages_members.h
   239 --- gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/messages_members.h	2008-06-10 14:45:43.000000000 +0200
   240 +++ gcc-4.3.0/libstdc++-v3/config/locale/uclibc/messages_members.h	2008-06-10 14:45:46.000000000 +0200
   241 @@ -47,18 +47,21 @@
   242    template<typename _CharT>
   243       messages<_CharT>::messages(size_t __refs)
   244       : facet(__refs), _M_c_locale_messages(_S_get_c_locale()), 
   245 -     _M_name_messages(_S_get_c_name())
   246 +       _M_name_messages(_S_get_c_name())
   247       { }
   248  
   249    template<typename _CharT>
   250       messages<_CharT>::messages(__c_locale __cloc, const char* __s, 
   251  				size_t __refs) 
   252 -     : facet(__refs), _M_c_locale_messages(_S_clone_c_locale(__cloc)),
   253 -     _M_name_messages(__s)
   254 +     : facet(__refs), _M_c_locale_messages(NULL), _M_name_messages(NULL)
   255       {
   256 -       char* __tmp = new char[std::strlen(__s) + 1];
   257 -       std::strcpy(__tmp, __s);
   258 +       const size_t __len = std::strlen(__s) + 1;
   259 +       char* __tmp = new char[__len];
   260 +       std::memcpy(__tmp, __s, __len);
   261         _M_name_messages = __tmp;
   262 +
   263 +       // Last to avoid leaking memory if new throws.
   264 +       _M_c_locale_messages = _S_clone_c_locale(__cloc);
   265       }
   266  
   267    template<typename _CharT>
   268 diff -durN gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/monetary_members.cc gcc-4.3.0/libstdc++-v3/config/locale/uclibc/monetary_members.cc
   269 --- gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/monetary_members.cc	2008-06-10 14:45:46.000000000 +0200
   270 +++ gcc-4.3.0/libstdc++-v3/config/locale/uclibc/monetary_members.cc	2008-06-10 14:45:46.000000000 +0200
   271 @@ -33,9 +33,14 @@
   272  
   273  // Written by Benjamin Kosnik <bkoz@redhat.com>
   274  
   275 +#include <features.h>
   276 +#ifdef __UCLIBC_HAS_LOCALE__
   277  #define _LIBC
   278  #include <locale>
   279  #undef _LIBC
   280 +#else
   281 +#include <locale>
   282 +#endif
   283  #include <bits/c++locale_internal.h>
   284  
   285  #ifdef __UCLIBC_MJN3_ONLY__
   286 @@ -206,7 +211,7 @@
   287  	  }
   288  	break;
   289        default:
   290 -	;
   291 +	__ret = pattern();
   292        }
   293      return __ret;
   294    }
   295 diff -durN gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/numeric_members.cc gcc-4.3.0/libstdc++-v3/config/locale/uclibc/numeric_members.cc
   296 --- gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/numeric_members.cc	2008-06-10 14:45:46.000000000 +0200
   297 +++ gcc-4.3.0/libstdc++-v3/config/locale/uclibc/numeric_members.cc	2008-06-10 14:45:46.000000000 +0200
   298 @@ -33,9 +33,14 @@
   299  
   300  // Written by Benjamin Kosnik <bkoz@redhat.com>
   301  
   302 +#include <features.h>
   303 +#ifdef __UCLIBC_HAS_LOCALE__
   304  #define _LIBC
   305  #include <locale>
   306  #undef _LIBC
   307 +#else
   308 +#include <locale>
   309 +#endif
   310  #include <bits/c++locale_internal.h>
   311  
   312  #ifdef __UCLIBC_MJN3_ONLY__
   313 diff -durN gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/time_members.h gcc-4.3.0/libstdc++-v3/config/locale/uclibc/time_members.h
   314 --- gcc-4.3.0.orig/libstdc++-v3/config/locale/uclibc/time_members.h	2008-06-10 14:45:39.000000000 +0200
   315 +++ gcc-4.3.0/libstdc++-v3/config/locale/uclibc/time_members.h	2008-06-10 14:45:46.000000000 +0200
   316 @@ -37,25 +37,33 @@
   317    template<typename _CharT>
   318      __timepunct<_CharT>::__timepunct(size_t __refs) 
   319      : facet(__refs), _M_data(NULL), _M_c_locale_timepunct(NULL), 
   320 -    _M_name_timepunct(_S_get_c_name())
   321 +      _M_name_timepunct(_S_get_c_name())
   322      { _M_initialize_timepunct(); }
   323  
   324    template<typename _CharT>
   325      __timepunct<_CharT>::__timepunct(__cache_type* __cache, size_t __refs) 
   326      : facet(__refs), _M_data(__cache), _M_c_locale_timepunct(NULL), 
   327 -    _M_name_timepunct(_S_get_c_name())
   328 +      _M_name_timepunct(_S_get_c_name())
   329      { _M_initialize_timepunct(); }
   330  
   331    template<typename _CharT>
   332      __timepunct<_CharT>::__timepunct(__c_locale __cloc, const char* __s,
   333  				     size_t __refs) 
   334      : facet(__refs), _M_data(NULL), _M_c_locale_timepunct(NULL), 
   335 -    _M_name_timepunct(__s)
   336 +      _M_name_timepunct(NULL)
   337      { 
   338 -      char* __tmp = new char[std::strlen(__s) + 1];
   339 -      std::strcpy(__tmp, __s);
   340 +      const size_t __len = std::strlen(__s) + 1;
   341 +      char* __tmp = new char[__len];
   342 +      std::memcpy(__tmp, __s, __len);
   343        _M_name_timepunct = __tmp;
   344 -      _M_initialize_timepunct(__cloc); 
   345 +
   346 +      try
   347 +	{ _M_initialize_timepunct(__cloc); }
   348 +      catch(...)
   349 +	{
   350 +	  delete [] _M_name_timepunct;
   351 +	  __throw_exception_again;
   352 +	}
   353      }
   354  
   355    template<typename _CharT>