Skip to content

Commit c831cfa

Browse files
committed
[libc++] Disable isw*_l functions on old MSVCRT (< 0x800)
This fixes linking on platforms older than Windows 10, which don't have these functions. In that case, implement char functions with specific locale by calling the same function without locale (which will use the ambiant one).
1 parent 5676478 commit c831cfa

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

libcxx/include/__cxx03/__config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,9 @@ typedef __char32_t char32_t;
595595
// clang-format on
596596

597597
# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
598-
# define _LIBCPP_LOCALE__L_EXTENSIONS 1
598+
# if !defined(__MSVCRT_VERSION__) || __MSVCRT_VERSION__ >= 0x800
599+
# define _LIBCPP_LOCALE__L_EXTENSIONS 1
600+
# endif
599601
# endif
600602

601603
# ifdef __FreeBSD__

libcxx/include/__locale_dir/support/windows.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,23 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, s
221221
}
222222

223223
# if _LIBCPP_HAS_WIDE_CHARACTERS
224+
# if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
225+
_LIBCPP_EXPORTED_FROM_ABI int __iswctype(wint_t c, wctype_t __type, __locale_t loc);
226+
_LIBCPP_EXPORTED_FROM_ABI int __iswspace(wint_t c, __locale_t loc);
227+
_LIBCPP_EXPORTED_FROM_ABI int __iswprint(wint_t c, __locale_t loc);
228+
_LIBCPP_EXPORTED_FROM_ABI int __iswcntrl(wint_t c, __locale_t loc);
229+
_LIBCPP_EXPORTED_FROM_ABI int __iswupper(wint_t c, __locale_t loc);
230+
_LIBCPP_EXPORTED_FROM_ABI int __iswlower(wint_t c, __locale_t loc);
231+
_LIBCPP_EXPORTED_FROM_ABI int __iswalpha(wint_t c, __locale_t loc);
232+
_LIBCPP_EXPORTED_FROM_ABI int __iswblank(wint_t c, __locale_t loc);
233+
_LIBCPP_EXPORTED_FROM_ABI int __iswdigit(wint_t c, __locale_t loc);
234+
_LIBCPP_EXPORTED_FROM_ABI int __iswpunct(wint_t c, __locale_t loc);
235+
_LIBCPP_EXPORTED_FROM_ABI int __iswxdigit(wint_t c, __locale_t loc);
236+
_LIBCPP_EXPORTED_FROM_ABI wint_t __towupper(wint_t c, __locale_t loc);
237+
_LIBCPP_EXPORTED_FROM_ABI wint_t __towlower(wint_t c, __locale_t loc);
238+
_LIBCPP_EXPORTED_FROM_ABI int __wcscoll(const wchar_t* ws1, const wchar_t* ws2, __locale_t loc);
239+
_LIBCPP_EXPORTED_FROM_ABI size_t __wcsxfrm(wchar_t* dest, const wchar_t* src, size_t n, __locale_t loc);
240+
# else
224241
inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) {
225242
return ::_iswctype_l(__c, __type, __loc);
226243
}
@@ -245,7 +262,8 @@ inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t*
245262
inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
246263
return ::_wcsxfrm_l(__dest, __src, __n, __loc);
247264
}
248-
# endif // _LIBCPP_HAS_WIDE_CHARACTERS
265+
# endif // defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
266+
# endif // _LIBCPP_HAS_WIDE_CHARACTERS
249267

250268
# if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
251269
_LIBCPP_EXPORTED_FROM_ABI size_t __strftime(char*, size_t, const char*, const struct tm*, __locale_t);

libcxx/src/support/win32/locale_win32.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,68 @@ size_t __strftime(char* ret, size_t n, const char* format, const struct tm* tm,
5757
__locale_guard __current(loc);
5858
return std::strftime(ret, n, format, tm);
5959
}
60+
# if _LIBCPP_HAS_WIDE_CHARACTERS
61+
int __iswctype(wint_t c, wctype_t type, __locale_t loc) {
62+
__locale_guard __current(loc);
63+
return ::iswctype(c, type);
64+
}
65+
int __iswspace(wint_t c, __locale_t loc) {
66+
__locale_guard __current(loc);
67+
return ::iswspace(c);
68+
}
69+
int __iswprint(wint_t c, __locale_t loc) {
70+
__locale_guard __current(loc);
71+
return ::iswprint(c);
72+
}
73+
int __iswcntrl(wint_t c, __locale_t loc) {
74+
__locale_guard __current(loc);
75+
return ::iswcntrl(c);
76+
}
77+
int __iswupper(wint_t c, __locale_t loc) {
78+
__locale_guard __current(loc);
79+
return ::iswupper(c);
80+
}
81+
int __iswlower(wint_t c, __locale_t loc) {
82+
__locale_guard __current(loc);
83+
return ::iswlower(c);
84+
}
85+
int __iswalpha(wint_t c, __locale_t loc) {
86+
__locale_guard __current(loc);
87+
return ::iswalpha(c);
88+
}
89+
int __iswblank(wint_t c, __locale_t loc) {
90+
__locale_guard __current(loc);
91+
return ::iswblank(c);
92+
}
93+
int __iswdigit(wint_t c, __locale_t loc) {
94+
__locale_guard __current(loc);
95+
return ::iswdigit(c);
96+
}
97+
int __iswpunct(wint_t c, __locale_t loc) {
98+
__locale_guard __current(loc);
99+
return ::iswpunct(c);
100+
}
101+
int __iswxdigit(wint_t c, __locale_t loc) {
102+
__locale_guard __current(loc);
103+
return ::iswxdigit(c);
104+
}
105+
wint_t __towupper(wint_t c, __locale_t loc) {
106+
__locale_guard __current(loc);
107+
return ::towupper(c);
108+
}
109+
wint_t __towlower(wint_t c, __locale_t loc) {
110+
__locale_guard __current(loc);
111+
return ::towlower(c);
112+
}
113+
int __wcscoll(const wchar_t* ws1, const wchar_t* ws2, __locale_t loc) {
114+
__locale_guard __current(loc);
115+
return ::wcscoll(ws1, ws2);
116+
}
117+
size_t __wcsxfrm(wchar_t* dest, const wchar_t* src, size_t n, __locale_t loc) {
118+
__locale_guard __current(loc);
119+
return ::wcsxfrm(dest, src, n);
120+
}
121+
# endif
60122
#endif
61123

62124
//

0 commit comments

Comments
 (0)