summaryrefslogtreecommitdiffstats
path: root/libcxx/src/support
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2019-10-28 10:39:44 +0200
committerHans Wennborg <hans@chromium.org>2020-02-04 11:41:50 +0100
commitca6b341bd5d7159d9e398eef1a787b649c5bc888 (patch)
tree18af90b33b476738e31292464697d80df32b74c3 /libcxx/src/support
parent5f6fec2404c5135247ae9e4e515e8d9d3242f790 (diff)
downloadbcm5719-llvm-ca6b341bd5d7159d9e398eef1a787b649c5bc888.tar.gz
bcm5719-llvm-ca6b341bd5d7159d9e398eef1a787b649c5bc888.zip
[libcxx] [Windows] Store the lconv struct returned from localeconv in locale_t
This fixes using non-default locales, which currently can crash when e.g. formatting numbers. Within the localeconv_l function, the per-thread locale is temporarily changed with __libcpp_locale_guard, then localeconv() is called, returning an lconv * struct pointer. When localeconv_l returns, the __libcpp_locale_guard dtor restores the per-thread locale back to the original. This invalidates the contents of the earlier returned lconv struct, and all C strings that are pointed to within it are also invalidated. Thus, to have an actually working localeconv_l function, the function needs to allocate some sort of storage for the returned contents, that stays valid for as long as the caller needs to use the returned struct. Extend the libcxx/win32 specific locale_t class with storage for a deep copy of a lconv struct, and change localeconv_l to take a reference to the locale_t, to allow it to store the returned lconv struct there. This works fine for libcxx itself, but wouldn't necessarily be right for a caller that uses libcxx's localeconv_l function. This fixes around 11 of libcxx's currently failing tests on windows. Differential Revision: https://reviews.llvm.org/D69505 (cherry picked from commit 7db4f2c6945a24a7d81dad3362700353e2ec369e)
Diffstat (limited to 'libcxx/src/support')
-rw-r--r--libcxx/src/support/win32/locale_win32.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/libcxx/src/support/win32/locale_win32.cpp b/libcxx/src/support/win32/locale_win32.cpp
index a64788685c2..b7062db352a 100644
--- a/libcxx/src/support/win32/locale_win32.cpp
+++ b/libcxx/src/support/win32/locale_win32.cpp
@@ -32,11 +32,13 @@ decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
#endif
}
-
-lconv *localeconv_l( locale_t loc )
+lconv *localeconv_l( locale_t &loc )
{
__libcpp_locale_guard __current(loc);
- return localeconv();
+ lconv *lc = localeconv();
+ if (!lc)
+ return lc;
+ return loc.__store_lconv(lc);
}
size_t mbrlen_l( const char *__restrict s, size_t n,
mbstate_t *__restrict ps, locale_t loc )
OpenPOWER on IntegriCloud