public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* locale bug?
@ 2021-05-17 14:11 Jason Pyeron
  2021-05-17 17:07 ` Achim Gratz
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Pyeron @ 2021-05-17 14:11 UTC (permalink / raw)
  To: cygwin

While working an updated build of pdfgrep, I ran in to a crash when the environment local was something other than LC_ALL=C.

 

Looking at http://www.cplusplus.com/reference/locale/locale/locale/ the empty string passed to the constructor should use the environment's default locale and if the “argument” does not represent a valid C-locale in the implementation, runtime_error is thrown.

 

 

$ g++ -o bug50 bug50.cc ; echo en_US.UTF-8; LC_ALL="en_US.UTF-8" ./bug50; echo C; LC_ALL=C ./bug50

en_US.UTF-8

Line:8:start

Line:17:exception thrown

Line:19:succeeded using Minimal C locale (the same as locale::classic)

Line:21:about to set global locale

Line:23:done

C

Line:8:start

Line:13:succeeded using The environment's default locale

Line:21:about to set global locale

Line:23:done

 

$ cat -n bug50.cc

     1  #include <iostream>

     2  #include <locale>

     3

     4  using namespace std;

     5

     6  int main(int argc, char** argv)

     7  {

     8          cout << "Line:" << __LINE__ << ":start" << endl;

     9          locale l;

    10          try

    11          {

    12                  l=locale("");

    13                  cout << "Line:" << __LINE__ << ":succeeded using The environment's default locale" << endl;

    14          }

    15          catch (exception& e)

    16          {

    17                  cout << "Line:" << __LINE__ << ":exception thrown" << endl;

    18                  l=locale("C");

    19                  cout << "Line:" << __LINE__ << ":succeeded using Minimal C locale (the same as locale::classic)" << endl;

    20          }

    21          cout << "Line:" << __LINE__ << ":about to set global locale" << endl;

    22          locale::global(l);

    23          cout << "Line:" << __LINE__ << ":done" << endl;

    24

    25  }

 

Thoughts? This is out of my knowledge area – never worked with locales in C++ before.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: locale bug?
  2021-05-17 14:11 locale bug? Jason Pyeron
@ 2021-05-17 17:07 ` Achim Gratz
  0 siblings, 0 replies; 2+ messages in thread
From: Achim Gratz @ 2021-05-17 17:07 UTC (permalink / raw)
  To: cygwin

Jason Pyeron writes:
> While working an updated build of pdfgrep, I ran in to a crash when
> the environment local was something other than LC_ALL=C.
>
> Looking at http://www.cplusplus.com/reference/locale/locale/locale/
> the empty string passed to the constructor should use the
> environment's default locale and if the “argument” does not represent
> a valid C-locale in the implementation, runtime_error is thrown.

It looks like the C++ standard library goes through all the right
motions, but then fails to construct an actual locale object as it's
supposed to do and thus errors out.  Cygwin is not glibc based, so this
seems to be essentially the same bug as described here:

https://stackoverflow.com/questions/58245286/why-does-stdlocale-name-give-different-results-on-clang-and-gcc

and elsewhere.  This bug is at least 17 years old by now, so if anybody
comes up with a patch that would be helpful.  It's entirely possible
that the configury failed to detect (if it even tried) that Cygwin has
(or should have) thread-safe locale API by now, but it might have a
different API than glibc.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Wavetables for the Terratec KOMPLEXER:
http://Synth.Stromeko.net/Downloads.html#KomplexerWaves

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-17 17:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 14:11 locale bug? Jason Pyeron
2021-05-17 17:07 ` Achim Gratz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).