[libcxx-commits] [libcxx] [libc++] Disable isw*_l functions on old MSVCRT (< 0x800) (PR #144273)
Hervé Poussineau via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jun 15 11:50:14 PDT 2025
https://github.com/hpoussin created https://github.com/llvm/llvm-project/pull/144273
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).
>From c831cfac68b6bb674c82041e05ef7e0d8617d23b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= <hpoussin at reactos.org>
Date: Sun, 15 Jun 2025 20:48:32 +0200
Subject: [PATCH] [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).
---
libcxx/include/__cxx03/__config | 4 +-
libcxx/include/__locale_dir/support/windows.h | 20 +++++-
libcxx/src/support/win32/locale_win32.cpp | 62 +++++++++++++++++++
3 files changed, 84 insertions(+), 2 deletions(-)
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
//
More information about the libcxx-commits
mailing list