patches/gcc/4.2.2/150-uclibc-locale-update.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Jan 12 19:24:03 2010 +0100 (2010-01-12)
changeset 1761 88020b2c3246
parent 431 8bde4c6ea47a
permissions -rw-r--r--
scripts/functions: change handling of nochdir

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