[PATCH] D20596: [libcxx] Refactor locale switching, creation, and destruction

Ben Craig via cfe-commits cfe-commits at lists.llvm.org
Tue May 24 13:26:51 PDT 2016


bcraig created this revision.
bcraig added reviewers: mclow.lists, EricWF, joerg, jroelofs.
bcraig added a subscriber: cfe-commits.
Herald added a subscriber: jfb.

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).

http://reviews.llvm.org/D20596

Files:
  include/__bsd_locale_fallbacks.h
  include/__locale
  include/__locale_mgmt.h
  include/__posix_locale_mgmt_defaults.h
  include/locale
  include/support/ibm/locale_mgmt_aix.h
  include/support/ibm/xlocale.h
  include/support/musl/xlocale.h
  include/support/solaris/xlocale.h
  include/support/win32/locale_mgmt_win32.h
  include/support/win32/locale_win32.h
  include/support/xlocale/__nop_locale_mgmt.h
  include/support/xlocale/__posix_l_fallback.h
  include/support/xlocale/__strtonum_fallback.h
  src/locale.cpp
  src/support/solaris/mbsnrtowcs.inc
  src/support/solaris/wcsnrtombs.inc
  src/support/solaris/xlocale.c
  src/support/win32/locale_win32.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20596.58300.patch
Type: text/x-patch
Size: 82316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160524/0a327280/attachment-0001.bin>


More information about the cfe-commits mailing list