This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Refactor locale switching, creation, and destruction
AbandonedPublic

Authored by bcraig on May 24 2016, 1:26 PM.

Details

Summary

This patch cleans up libcxx's usage of newlocale, freelocale, uselocale, and locale_t.

First, libcxx no longer defines the posix newlocale, freelocale, uselocale, and locale_t names on non-posix compliant systems. Those names don't belong to libcxx, so _libcpp variants and forwarders have been created. The renaming is the bulk of the diff.

Second, improved locale management RAII objects have been created and used. _locale_raii was a typedef for a unique_ptr with a function pointer deleter. That requires a fatter object and an indirect call. Instead, a small, custom RAII object was added to manage the switching of locales with uselocale. This also allows for a terser syntax. An RAII object for the newlocale / freelocale pair was also created, as was a fancier RAII object to handle the case when we are handed a locale that (maybe) isn't supposed to be deleted.

The last significant change is that the nop_locale_mgmt's newlocale (used by newlib) will now attempt to support the "C" and "POSIX" locales, rather than return 0.

Tested on Linux x64, and on an embedded target that also happens to use all the trivial locale wrappers (like nop_locale_mgmt).

Diff Detail

Event Timeline

bcraig updated this revision to Diff 58300.May 24 2016, 1:26 PM
bcraig retitled this revision from to [libcxx] Refactor locale switching, creation, and destruction.
bcraig updated this object.
bcraig added reviewers: mclow.lists, EricWF, joerg, jroelofs.
bcraig added a subscriber: cfe-commits.
bcraig abandoned this revision.Jun 15 2017, 2:42 PM

This is very stale at this point, and isn't blocking anything. Closing.