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]

Re: [RFC] libstdc++/7811 vs libstdc++/7222


> I'm currently investigating this regression from 3.1.1. This is the 
> testcase:
> 
> #include <locale>
> #include <iostream>
> 
> int main(){
>   using namespace std;
>   locale loc("");
>   cout << loc.name() << endl;
> }

I saw this come in. 

:(

> What happens with 3.2 and current mainline is that the environment is 
> not taken into account and loc is *always* "C".
> The regression was introduced with the checkin for libstdc++/7222 (by 
> the way, to date I still cannot reproduce it the problem reported therein):

Yep. I figured this was the issue.

This was checked in as part of the PR:

// libstdc++/7222
void test02()
{
  bool test = true;
  std::locale loc_c1("C");
  std::locale loc_c2 ("C");
  
  std::locale loc_1("");
  std::locale loc_2("");

  VERIFY( loc_c1 == loc_c2 );
  VERIFY( loc_1 == loc_2 );
}

I'd been able to reproduce the fail with this testcase. Is that not the
case for you?

>  	if (strcmp(__s, "C") == 0 || strcmp(__s, "POSIX") == 0)
>  	  (_M_impl = _S_classic)->_M_add_reference();
>  	else if (strcmp(__s, "") == 0)
> -	  _M_impl = new _Impl(setlocale(LC_ALL, __s), 1);
> +	  _M_impl = new _Impl(setlocale(LC_ALL, NULL), 1);
>  	else
>  	  _M_impl = new _Impl(__s, 1);
>        }

What to do with this....

> I believe that a possible not-MT-aware solution would be the usual pattern
> 
>       {
>         char* __old = strdup(setlocale(LC_ALL, NULL));
>         _M_impl = new _Impl(setlocale(LC_ALL, __s), 1);
>         setlocale(LC_ALL, __old);
>         free(__old);
>       }
> 
> Useful to extract the name of the locale set in the environment without 
> actually changing it for the running program.

Note that for the part of locale.cc you are patching, it is known that
__s == "". 
 
> However, I'm not sure about the corresponding MT-aware glibc2.3 solution 
> using __uselocale.

Maybe the following, where __s == "". Basically, this is just a question
of how to get read-only info from the current locale using __uselocale.

      __c_locale __env;
      _S_create_c_locale(__env, __s);
      __c_locale __old = __uselocale(__env);

     // do stuff

      __uselocale(__old);
      _S_destroy_c_locale(__env);


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