From 1e17bc1faf03109ff64ca278f8e603c31fe089f4 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Fri, 30 Dec 2016 10:44:00 +0000 Subject: [PATCH] Remove mblen(), mbtowc() and wctomb() from the thread-unsafe functions. Back in r240527 I added a knob to prevent thread-unsafe functions from being exposed. mblen(), mbtowc() and wctomb() were also added to this list, as the latest issue of POSIX doesn't require these functions to be thread-safe. It turns out that the only circumstance in which these functions are not thread-safe is in case they are used in combination with state-dependent character sets (e.g., Shift-JIS). According to Austin Group Bug 708, these character sets "[...] are mostly a relic of the past and which were never supported on most POSIX systems". Though in many cases the use of these functions can be prevented by using the reentrant counterparts, they are the only functions that allow you to query whether the locale's character set is state-dependent. This means that omitting these functions removes actual functionality. Let's be a bit less pedantic and drop the guards around these functions. Links: http://austingroupbugs.net/view.php?id=708 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2037.htm Reviewed by: ericwf Differential Revision: https://reviews.llvm.org/D21436 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@290748 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__config | 2 +- include/cstdlib | 2 -- test/std/depr/depr.c.headers/stdlib_h.pass.cpp | 2 -- test/std/language.support/support.runtime/cstdlib.pass.cpp | 2 -- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/include/__config b/include/__config index 1c629f0e9..467ab00a1 100644 --- a/include/__config +++ b/include/__config @@ -917,7 +917,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE #endif -// Thread-unsafe functions such as strtok(), mbtowc() and localtime() +// Thread-unsafe functions such as strtok() and localtime() // are not available. #ifdef __CloudABI__ #define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS diff --git a/include/cstdlib b/include/cstdlib index 9a775b844..2ca25ed56 100644 --- a/include/cstdlib +++ b/include/cstdlib @@ -144,11 +144,9 @@ using ::ldiv; #ifndef _LIBCPP_HAS_NO_LONG_LONG using ::lldiv; #endif // _LIBCPP_HAS_NO_LONG_LONG -#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS using ::mblen; using ::mbtowc; using ::wctomb; -#endif using ::mbstowcs; using ::wcstombs; #ifdef _LIBCPP_HAS_QUICK_EXIT diff --git a/test/std/depr/depr.c.headers/stdlib_h.pass.cpp b/test/std/depr/depr.c.headers/stdlib_h.pass.cpp index 96d1143d4..1680f4349 100644 --- a/test/std/depr/depr.c.headers/stdlib_h.pass.cpp +++ b/test/std/depr/depr.c.headers/stdlib_h.pass.cpp @@ -104,11 +104,9 @@ int main() wchar_t* pw = 0; const wchar_t* pwc = 0; char* pc = 0; -#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); -#endif static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); } diff --git a/test/std/language.support/support.runtime/cstdlib.pass.cpp b/test/std/language.support/support.runtime/cstdlib.pass.cpp index d8f88cf58..60f7d954d 100644 --- a/test/std/language.support/support.runtime/cstdlib.pass.cpp +++ b/test/std/language.support/support.runtime/cstdlib.pass.cpp @@ -96,11 +96,9 @@ int main() wchar_t* pw = 0; const wchar_t* pwc = 0; char* pc = 0; -#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); -#endif static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); }