Bug 11009 - Make LC_GLOBAL_LOCALE a real locale_t object.
Summary: Make LC_GLOBAL_LOCALE a real locale_t object.
Status: REOPENED
Alias: None
Product: glibc
Classification: Unclassified
Component: locale (show other bugs)
Version: 2.9
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-23 22:40 UTC by Ludovic Courtès
Modified: 2016-09-05 15:33 UTC (History)
3 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Last reconfirmed:
fweimer: security-


Attachments
Test case. (196 bytes, text/plain)
2009-11-23 22:41 UTC, Ludovic Courtès
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ludovic Courtès 2009-11-23 22:40:38 UTC
As a followup to #10968, the attached example crashes with glibc <= 2.11.
Comment 1 Ludovic Courtès 2009-11-23 22:41:54 UTC
Created attachment 4412 [details]
Test case.
Comment 2 Ulrich Drepper 2009-11-23 22:47:33 UTC
Not everything that is possible to do should be done.  Why on earth is this needed?
Comment 3 Jakub Jelinek 2009-11-23 23:01:06 UTC
Note that locale.h description says that LC_GLOBAL_LOCALE is a special value for
use by the uselocale function.  There is nothing that says it can be used in
other functions.  If you want to query the global locale, why don't you just use
nl_langinfo instead of nl_langinfo_l?
You'd be requesting that isdigit_l (x, LC_GLOBAL_LOCALE) works next time, all
those macros/inclines then would need to special case that value.
Comment 4 Ludovic Courtès 2009-11-23 23:44:35 UTC
It's sometimes useful to have code that treats `LC_GLOBAL_LOCALE' like any other
locale object.

The wording at
http://www.opengroup.org/onlinepubs/9699919799/basedefs/locale.h.html suggests
that it's a "locale object descriptor", which should be usable with any function
that takes a locale object descriptor, not just uselocale(3).
Comment 5 Ulrich Drepper 2009-11-23 23:48:30 UTC
(In reply to comment #4)
> It's sometimes useful to have code that treats `LC_GLOBAL_LOCALE' like any other
> locale object.

It's complete nonsense in this case and prohibitively expensive in some other
cases.  I won't change this.  And since the specification is written after the
glibc implementation it has to be adjusted.

Comment 6 Bruno Haible 2009-11-24 01:12:31 UTC
(In reply to comment #3)
> If you want to query the global locale, why don't you just use
> nl_langinfo instead of nl_langinfo_l?

Note that the proposed

  nl_langinfo_l (item, LC_GLOBAL_LOCALE)

is not equivalent to

  nl_langinfo (item)

but rather to

  ({ locale_t old_thread_locale = uselocale (LC_GLOBAL_LOCALE);
     const char *value = nl_langinfo (item);
     uselocale (old_thread_locale);
     value;
  })

or to

  ({ locale_t global_locale = duplocale (LC_GLOBAL_LOCALE);
     const char *value = nl_langinfo_l (item, global_locale);
     freelocale (global_locale);
     value;
  })

But I agree with your evaluation that it is not essential to support
LC_GLOBAL_LOCALE arguments here (unlike in duplocale, see bug10969).
Comment 7 Carlos O'Donell 2016-03-30 19:10:51 UTC
I'm reopening this because it bites users all the time. We do a terrible disservice by not returning real locale_t objects from uselocale under all conditions.

I don't see that it would be that hard to make LC_GLOBAL_LOCALE a real object instead of (locale_t) -1, and it would make the API easier to use.

There have been no technical arguments against this, and it would increase the QoI to be able to do this:

  myloc = uselocale ((locale_t) 0);

And then later use myloc for any API that needs a locale_t object.

Someone would have to present a strong performance argument to convince me that this was prohibitively expensive to make the API accessible to everyone.