diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/atomic_support.h | 2 | ||||
-rw-r--r-- | src/locale.cpp | 46 | ||||
-rw-r--r-- | src/string.cpp | 5 | ||||
-rw-r--r-- | src/support/runtime/exception_pointer_msvc.ipp | 1 | ||||
-rw-r--r-- | src/support/win32/locale_win32.cpp | 26 | ||||
-rw-r--r-- | src/thread.cpp | 2 |
6 files changed, 49 insertions, 33 deletions
diff --git a/src/include/atomic_support.h b/src/include/atomic_support.h index 378541b23256..08847e630705 100644 --- a/src/include/atomic_support.h +++ b/src/include/atomic_support.h @@ -29,7 +29,7 @@ #endif #if !defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS) -# if defined(_LIBCPP_MSVC) +# if defined(_LIBCPP_WARNING) _LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported") # else # warning Building libc++ without __atomic builtins is unsupported diff --git a/src/locale.cpp b/src/locale.cpp index 1ed9b41fd4ad..4163c2c0af65 100644 --- a/src/locale.cpp +++ b/src/locale.cpp @@ -45,6 +45,24 @@ _LIBCPP_BEGIN_NAMESPACE_STD +struct __libcpp_unique_locale { + __libcpp_unique_locale(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) {} + + ~__libcpp_unique_locale() { + if (__loc_) + freelocale(__loc_); + } + + explicit operator bool() const { return __loc_; } + + locale_t& get() { return __loc_; } + + locale_t __loc_; +private: + __libcpp_unique_locale(__libcpp_unique_locale const&); + __libcpp_unique_locale& operator=(__libcpp_unique_locale const&); +}; + #ifdef __cloc_defined locale_t __cloc() { // In theory this could create a race condition. In practice @@ -4185,7 +4203,7 @@ __widen_from_utf8<32>::~__widen_from_utf8() static bool checked_string_to_wchar_convert(wchar_t& dest, const char* ptr, - __locale_struct* loc) { + locale_t loc) { if (*ptr == '\0') return false; mbstate_t mb = {}; @@ -4200,7 +4218,7 @@ static bool checked_string_to_wchar_convert(wchar_t& dest, static bool checked_string_to_char_convert(char& dest, const char* ptr, - __locale_struct* __loc) { + locale_t __loc) { if (*ptr == '\0') return false; if (!ptr[1]) { @@ -4295,8 +4313,8 @@ numpunct_byname<char>::__init(const char* nm) { if (strcmp(nm, "C") != 0) { - __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); - if (loc == nullptr) + __libcpp_unique_locale loc(nm); + if (!loc) __throw_runtime_error("numpunct_byname<char>::numpunct_byname" " failed to construct for " + string(nm)); @@ -4333,8 +4351,8 @@ numpunct_byname<wchar_t>::__init(const char* nm) { if (strcmp(nm, "C") != 0) { - __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); - if (loc == nullptr) + __libcpp_unique_locale loc(nm); + if (!loc) __throw_runtime_error("numpunct_byname<wchar_t>::numpunct_byname" " failed to construct for " + string(nm)); @@ -5820,8 +5838,8 @@ void moneypunct_byname<char, false>::init(const char* nm) { typedef moneypunct<char, false> base; - __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); - if (loc == nullptr) + __libcpp_unique_locale loc(nm); + if (!loc) __throw_runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); @@ -5864,8 +5882,8 @@ void moneypunct_byname<char, true>::init(const char* nm) { typedef moneypunct<char, true> base; - __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); - if (loc == nullptr) + __libcpp_unique_locale loc(nm); + if (!loc) __throw_runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); @@ -5924,8 +5942,8 @@ void moneypunct_byname<wchar_t, false>::init(const char* nm) { typedef moneypunct<wchar_t, false> base; - __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); - if (loc == nullptr) + __libcpp_unique_locale loc(nm); + if (!loc) __throw_runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); lconv* lc = __libcpp_localeconv_l(loc.get()); @@ -5989,8 +6007,8 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) { typedef moneypunct<wchar_t, true> base; - __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); - if (loc == nullptr) + __libcpp_unique_locale loc(nm); + if (!loc) __throw_runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); diff --git a/src/string.cpp b/src/string.cpp index cd644330b3a7..d7ebdd3e5c9a 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -13,9 +13,6 @@ #include "cerrno" #include "limits" #include "stdexcept" -#ifdef _LIBCPP_MSVCRT -#include "support/win32/support.h" -#endif // _LIBCPP_MSVCRT #include <stdio.h> _LIBCPP_BEGIN_NAMESPACE_STD @@ -430,7 +427,7 @@ get_swprintf() #ifndef _LIBCPP_MSVCRT return swprintf; #else - return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(swprintf); + return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(_snwprintf); #endif } diff --git a/src/support/runtime/exception_pointer_msvc.ipp b/src/support/runtime/exception_pointer_msvc.ipp index a8cd0e8d304d..eab5d30a9487 100644 --- a/src/support/runtime/exception_pointer_msvc.ipp +++ b/src/support/runtime/exception_pointer_msvc.ipp @@ -10,6 +10,7 @@ #include <stdio.h> #include <stdlib.h> +#include <yvals.h> // for _CRTIMP2_PURE _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(_Out_ void*); _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(_Inout_ void*); diff --git a/src/support/win32/locale_win32.cpp b/src/support/win32/locale_win32.cpp index acbf79ac197c..28cb4491781f 100644 --- a/src/support/win32/locale_win32.cpp +++ b/src/support/win32/locale_win32.cpp @@ -13,14 +13,14 @@ #include <memory> #include <type_traits> -typedef _VSTD::remove_pointer<locale_t>::type __locale_struct; -typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii; +using std::__libcpp_locale_guard; // FIXME: base currently unused. Needs manual work to construct the new locale locale_t newlocale( int mask, const char * locale, locale_t /*base*/ ) { return _create_locale( mask, locale ); } + locale_t uselocale( locale_t newloc ) { locale_t old_locale = _get_current_locale(); @@ -36,59 +36,59 @@ locale_t uselocale( locale_t newloc ) } lconv *localeconv_l( locale_t loc ) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); return localeconv(); } size_t mbrlen_l( const char *__restrict s, size_t n, mbstate_t *__restrict ps, locale_t loc ) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); return mbrlen( s, n, ps ); } size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src, size_t len, mbstate_t *__restrict ps, locale_t loc ) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); return mbsrtowcs( dst, src, len, ps ); } size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps, locale_t loc ) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); return wcrtomb( s, wc, ps ); } size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s, size_t n, mbstate_t *__restrict ps, locale_t loc ) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); return mbrtowc( pwc, s, n, ps ); } size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src, size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc ) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); return mbsnrtowcs( dst, src, nms, len, ps ); } size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src, size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc ) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); return wcsnrtombs( dst, src, nwc, len, ps ); } wint_t btowc_l( int c, locale_t loc ) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); return btowc( c ); } int wctob_l( wint_t c, locale_t loc ) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); return wctob( c ); } int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); va_list ap; va_start( ap, format ); int result = vsnprintf( ret, n, format, ap ); @@ -106,6 +106,6 @@ int asprintf_l( char **ret, locale_t loc, const char *format, ... ) } int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap ) { - __locale_raii __current( uselocale(loc), uselocale ); + __libcpp_locale_guard __current(loc); return vasprintf( ret, format, ap ); } diff --git a/src/thread.cpp b/src/thread.cpp index 3f283c385b76..412a8fa0a620 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -99,7 +99,7 @@ thread::hardware_concurrency() _NOEXCEPT #else // defined(CTL_HW) && defined(HW_NCPU) // TODO: grovel through /proc or check cpuid on x86 and similar // instructions on other architectures. -# if defined(_LIBCPP_MSVC) +# if defined(_LIBCPP_WARNING) _LIBCPP_WARNING("hardware_concurrency not yet implemented") # else # warning hardware_concurrency not yet implemented |