summaryrefslogtreecommitdiffstats
path: root/libcxx/include/__locale
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2017-05-08 22:02:43 +0000
committerEric Fiselier <eric@efcs.ca>2017-05-08 22:02:43 +0000
commitb4ddab26bce7a30b05d4e21b648927dd1571ca7e (patch)
tree3f02bda16e3c781e1979223f1d70ec332d1aea93 /libcxx/include/__locale
parent362ea7329fc8bd5a7080a78d606066024ac40b11 (diff)
downloadbcm5719-llvm-b4ddab26bce7a30b05d4e21b648927dd1571ca7e.tar.gz
bcm5719-llvm-b4ddab26bce7a30b05d4e21b648927dd1571ca7e.zip
Refactor <locale> RAII guards to aid upcoming Windows locale changes.
Previously <locale> used std::unique_ptr<remove_ptr<locale_t>, locale-mgmt-function> as a scope guard for (A) creating new locales, and (B) setting the thread specific locale in RAII safe manner. However using unique_ptr has some problems, first it requires that locale_t is a pointer type, which may not be the case (Windows will need a non-pointer locale_t type that emulates _locale_t). The second problem is that users of the guards had to supply the locale management function to the custom deleter at every call site. However these locale management functions don't exist natively Windows, making a good Windows implementation of locale more difficult. This patch creates distinct and simply RAII guards that replace unique_ptr. These guards handle calling the correct locale management function so that callers don't have too. This simplification will aid in upcoming Windows fixes. llvm-svn: 302474
Diffstat (limited to 'libcxx/include/__locale')
-rw-r--r--libcxx/include/__locale19
1 files changed, 19 insertions, 0 deletions
diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index 4184e7e0348..cf3ba23b909 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -49,6 +49,25 @@
_LIBCPP_BEGIN_NAMESPACE_STD
+#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) || defined(_LIBCPP_MSVCRT)
+struct __libcpp_locale_guard {
+ _LIBCPP_INLINE_VISIBILITY
+ __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
+
+ _LIBCPP_INLINE_VISIBILITY
+ ~__libcpp_locale_guard() {
+ if (__old_loc_)
+ uselocale(__old_loc_);
+ }
+
+ locale_t __old_loc_;
+private:
+ __libcpp_locale_guard(__libcpp_locale_guard const&);
+ __libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
+};
+#endif
+
+
class _LIBCPP_TYPE_VIS locale;
template <class _Facet>
OpenPOWER on IntegriCloud