[libcxx] r290748 - Remove mblen(), mbtowc() and wctomb() from the thread-unsafe functions.
Ed Schouten via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 30 02:44:00 PST 2016
Author: ed
Date: Fri Dec 30 04:44:00 2016
New Revision: 290748
URL: http://llvm.org/viewvc/llvm-project?rev=290748&view=rev
Log:
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
Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/cstdlib
libcxx/trunk/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
libcxx/trunk/test/std/language.support/support.runtime/cstdlib.pass.cpp
Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=290748&r1=290747&r2=290748&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri Dec 30 04:44:00 2016
@@ -917,7 +917,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
#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
Modified: libcxx/trunk/include/cstdlib
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cstdlib?rev=290748&r1=290747&r2=290748&view=diff
==============================================================================
--- libcxx/trunk/include/cstdlib (original)
+++ libcxx/trunk/include/cstdlib Fri Dec 30 04:44:00 2016
@@ -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
Modified: libcxx/trunk/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/stdlib_h.pass.cpp?rev=290748&r1=290747&r2=290748&view=diff
==============================================================================
--- libcxx/trunk/test/std/depr/depr.c.headers/stdlib_h.pass.cpp (original)
+++ libcxx/trunk/test/std/depr/depr.c.headers/stdlib_h.pass.cpp Fri Dec 30 04:44:00 2016
@@ -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<decltype(mblen("",0)), int>::value), "");
static_assert((std::is_same<decltype(mbtowc(pw,"",0)), int>::value), "");
static_assert((std::is_same<decltype(wctomb(pc,L' ')), int>::value), "");
-#endif
static_assert((std::is_same<decltype(mbstowcs(pw,"",0)), size_t>::value), "");
static_assert((std::is_same<decltype(wcstombs(pc,pwc,0)), size_t>::value), "");
}
Modified: libcxx/trunk/test/std/language.support/support.runtime/cstdlib.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/language.support/support.runtime/cstdlib.pass.cpp?rev=290748&r1=290747&r2=290748&view=diff
==============================================================================
--- libcxx/trunk/test/std/language.support/support.runtime/cstdlib.pass.cpp (original)
+++ libcxx/trunk/test/std/language.support/support.runtime/cstdlib.pass.cpp Fri Dec 30 04:44:00 2016
@@ -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<decltype(std::mblen("",0)), int>::value), "");
static_assert((std::is_same<decltype(std::mbtowc(pw,"",0)), int>::value), "");
static_assert((std::is_same<decltype(std::wctomb(pc,L' ')), int>::value), "");
-#endif
static_assert((std::is_same<decltype(std::mbstowcs(pw,"",0)), std::size_t>::value), "");
static_assert((std::is_same<decltype(std::wcstombs(pc,pwc,0)), std::size_t>::value), "");
}
More information about the cfe-commits
mailing list