Skip to content

Commit 0a92402

Browse files
committedDec 30, 2016
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 llvm-svn: 290748
1 parent 72bcc04 commit 0a92402

File tree

4 files changed

+1
-7
lines changed

4 files changed

+1
-7
lines changed
 

‎libcxx/include/__config

+1-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
917917
#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
918918
#endif
919919

920-
// Thread-unsafe functions such as strtok(), mbtowc() and localtime()
920+
// Thread-unsafe functions such as strtok() and localtime()
921921
// are not available.
922922
#ifdef __CloudABI__
923923
#define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS

‎libcxx/include/cstdlib

-2
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,9 @@ using ::ldiv;
144144
#ifndef _LIBCPP_HAS_NO_LONG_LONG
145145
using ::lldiv;
146146
#endif // _LIBCPP_HAS_NO_LONG_LONG
147-
#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
148147
using ::mblen;
149148
using ::mbtowc;
150149
using ::wctomb;
151-
#endif
152150
using ::mbstowcs;
153151
using ::wcstombs;
154152
#ifdef _LIBCPP_HAS_QUICK_EXIT

‎libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,9 @@ int main()
104104
wchar_t* pw = 0;
105105
const wchar_t* pwc = 0;
106106
char* pc = 0;
107-
#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
108107
static_assert((std::is_same<decltype(mblen("",0)), int>::value), "");
109108
static_assert((std::is_same<decltype(mbtowc(pw,"",0)), int>::value), "");
110109
static_assert((std::is_same<decltype(wctomb(pc,L' ')), int>::value), "");
111-
#endif
112110
static_assert((std::is_same<decltype(mbstowcs(pw,"",0)), size_t>::value), "");
113111
static_assert((std::is_same<decltype(wcstombs(pc,pwc,0)), size_t>::value), "");
114112
}

‎libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,9 @@ int main()
9696
wchar_t* pw = 0;
9797
const wchar_t* pwc = 0;
9898
char* pc = 0;
99-
#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
10099
static_assert((std::is_same<decltype(std::mblen("",0)), int>::value), "");
101100
static_assert((std::is_same<decltype(std::mbtowc(pw,"",0)), int>::value), "");
102101
static_assert((std::is_same<decltype(std::wctomb(pc,L' ')), int>::value), "");
103-
#endif
104102
static_assert((std::is_same<decltype(std::mbstowcs(pw,"",0)), std::size_t>::value), "");
105103
static_assert((std::is_same<decltype(std::wcstombs(pc,pwc,0)), std::size_t>::value), "");
106104
}

0 commit comments

Comments
 (0)
Please sign in to comment.