-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[libc++] Disable isw*_l functions on old MSVCRT (< 0x800) #144273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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).
@llvm/pr-subscribers-libcxx Author: Hervé Poussineau (hpoussin) ChangesThis 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). Full diff: https://github.com/llvm/llvm-project/pull/144273.diff 3 Files Affected:
diff --git a/libcxx/include/__cxx03/__config b/libcxx/include/__cxx03/__config
index ef47327d96355..0839d19ad5ab4 100644
--- a/libcxx/include/__cxx03/__config
+++ b/libcxx/include/__cxx03/__config
@@ -595,7 +595,9 @@ typedef __char32_t char32_t;
// clang-format on
# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
-# define _LIBCPP_LOCALE__L_EXTENSIONS 1
+# if !defined(__MSVCRT_VERSION__) || __MSVCRT_VERSION__ >= 0x800
+# define _LIBCPP_LOCALE__L_EXTENSIONS 1
+# endif
# endif
# ifdef __FreeBSD__
diff --git a/libcxx/include/__locale_dir/support/windows.h b/libcxx/include/__locale_dir/support/windows.h
index 0d3089c150081..6a2ffd897bb7a 100644
--- a/libcxx/include/__locale_dir/support/windows.h
+++ b/libcxx/include/__locale_dir/support/windows.h
@@ -221,6 +221,23 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, s
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
+# if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
+_LIBCPP_EXPORTED_FROM_ABI int __iswctype(wint_t c, wctype_t __type, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswspace(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswprint(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswcntrl(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswupper(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswlower(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswalpha(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswblank(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswdigit(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswpunct(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __iswxdigit(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI wint_t __towupper(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI wint_t __towlower(wint_t c, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI int __wcscoll(const wchar_t* ws1, const wchar_t* ws2, __locale_t loc);
+_LIBCPP_EXPORTED_FROM_ABI size_t __wcsxfrm(wchar_t* dest, const wchar_t* src, size_t n, __locale_t loc);
+# else
inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) {
return ::_iswctype_l(__c, __type, __loc);
}
@@ -245,7 +262,8 @@ inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t*
inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
return ::_wcsxfrm_l(__dest, __src, __n, __loc);
}
-# endif // _LIBCPP_HAS_WIDE_CHARACTERS
+# endif // defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
+# endif // _LIBCPP_HAS_WIDE_CHARACTERS
# if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
_LIBCPP_EXPORTED_FROM_ABI size_t __strftime(char*, size_t, const char*, const struct tm*, __locale_t);
diff --git a/libcxx/src/support/win32/locale_win32.cpp b/libcxx/src/support/win32/locale_win32.cpp
index 24402e818d95d..f8a963faa572f 100644
--- a/libcxx/src/support/win32/locale_win32.cpp
+++ b/libcxx/src/support/win32/locale_win32.cpp
@@ -57,6 +57,68 @@ size_t __strftime(char* ret, size_t n, const char* format, const struct tm* tm,
__locale_guard __current(loc);
return std::strftime(ret, n, format, tm);
}
+# if _LIBCPP_HAS_WIDE_CHARACTERS
+int __iswctype(wint_t c, wctype_t type, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswctype(c, type);
+}
+int __iswspace(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswspace(c);
+}
+int __iswprint(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswprint(c);
+}
+int __iswcntrl(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswcntrl(c);
+}
+int __iswupper(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswupper(c);
+}
+int __iswlower(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswlower(c);
+}
+int __iswalpha(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswalpha(c);
+}
+int __iswblank(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswblank(c);
+}
+int __iswdigit(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswdigit(c);
+}
+int __iswpunct(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswpunct(c);
+}
+int __iswxdigit(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::iswxdigit(c);
+}
+wint_t __towupper(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::towupper(c);
+}
+wint_t __towlower(wint_t c, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::towlower(c);
+}
+int __wcscoll(const wchar_t* ws1, const wchar_t* ws2, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::wcscoll(ws1, ws2);
+}
+size_t __wcsxfrm(wchar_t* dest, const wchar_t* src, size_t n, __locale_t loc) {
+ __locale_guard __current(loc);
+ return ::wcsxfrm(dest, src, n);
+}
+# endif
#endif
//
|
Ping |
I'm really not convinced we want to support such old systems. Windows 7 has been EoL since 2020. |
FWIW, current libc++ does work fine on Windows 7, with mingw-w64 headers/libs (I just rechecked with a fresh nightly build); although mingw-w64 may have a little bit of compatibility glue code around these locale functions for msvcrt.dll in there (see commits as mingw-w64/mingw-w64@797b4a6, mingw-w64/mingw-w64@87558c1, mingw-w64/mingw-w64@16ad1d4). For patches like this, it would be good to know which SDK setup it is about - I presume this is for use with ReactOS? As the mingw configuration still does work, I'm also a bit hesitant about accepting this change. |
I didn't see the mingw-w64 changes you mentioned, as I was testing with stable version 12.0.0. |
FWIW, I don't know what there is to rework - the current libc++ should work just fine on Windows 7 with mingw-w64. The msvcrt releases from e.g. https://github.com/mstorsjo/llvm-mingw/releases/tag/20250613 work just fine on Windows 7 (I just tested it), and yesterday I checked a libc++.dll from a nightly build of latest llvm git which also loaded fine. |
By using mingw-w64 v13.0.0, this patch on libcxx is not required anymore. Closing pull request. |
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).