[libcxx-commits] [libcxx] [libc++] Add more missing bits to the locale base API (PR #122531)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 21 13:00:32 PST 2025


https://github.com/philnik777 approved this pull request.

> > Why do we need this if we already have the standard `std::lconv`? Same for setlocale.
> 
> The issue is that platforms who don't provide localization support generally don't provide `lconv` and `setlocale`. I am moving towards emulating the C locale on such platforms in the `_LIBCPP_HAS_LOCALIZATION == 0` case, and without introducing these internal names, I'd have to introduce these names when the underlying platform doesn't provide them.
> 
> > For the mask ones, are these equivalent to the standard versions without the `_MASK` prefix, or do the mask versions represent something distinct?
> 
> I think it depends on the platform. Some platforms provide those macros (e.g. https://man7.org/linux/man-pages/man3/newlocale.3.html) but other platforms don't. In the case of platforms that do provide these macros, I don't know if they are equivalent to our definition in libc++, but I'd assume they might not be. Was that your question?

I was mostly wondering what exactly the difference between the two is, since it's not at all clear to me.

> Basically, this patch makes it such that the whole localization support of libc++ is implemented on top of the API documented in `locale_base_api.h`, which gives us more flexibility to implement a locale emulation layer in the no-localization config, makes it easier to port to new platforms, etc. I do imagine that the API can then be simplified further, but this was the shortest path I could find to lifting all this API surface into something libc++ specific.

With the additional information that this is for support of platforms which don't support locales at all this patch makes a lot of sense. I think I was really confused by the commit message saying this is about non-BSD-like platforms. Could you update the commit message to just not mention BSD-like platforms at all? I think that would make it a lot clearer. Otherwise LGTM.


https://github.com/llvm/llvm-project/pull/122531


More information about the libcxx-commits mailing list