projects/aports·blob master · refs

398 lines · 14.7 KiB

1From 75a39fb23bc62e44fc86fdc68cc6c6d39510d450 Mon Sep 17 00:00:00 2001
2From: Aelin <[email protected]>
3Date: Fri, 4 Sep 2026 18:50:51 +0200
4Subject: [PATCH] Revert "[libc++] Port The OpenBSD localization to the new
5 locale API (#194317)"
6
7This reverts commit 182ae96a82fc355eca89d12c179d6a0961c653d8.
8---
9 libcxx/include/CMakeLists.txt | 3 +-
10 libcxx/include/__locale_dir/locale_base_api.h | 8 +-
11 .../__locale_dir/locale_base_api/openbsd.h | 19 ++
12 libcxx/include/__locale_dir/support/openbsd.h | 229 ------------------
13 .../__support/xlocale/__strtonum_fallback.h | 37 +++
14 libcxx/include/module.modulemap.in | 2 +-
15 6 files changed, 64 insertions(+), 234 deletions(-)
16 create mode 100644 libcxx/include/__locale_dir/locale_base_api/openbsd.h
17 delete mode 100644 libcxx/include/__locale_dir/support/openbsd.h
18 create mode 100644 libcxx/include/__support/xlocale/__strtonum_fallback.h
19
20diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
21index b40f586161e6..71d1a78c3344 100644
22--- a/libcxx/include/CMakeLists.txt
23+++ b/libcxx/include/CMakeLists.txt
24@@ -535,6 +535,7 @@ set(files
25 __locale_dir/locale_base_api.h
26 __locale_dir/locale_base_api/bsd_locale_fallbacks.h
27 __locale_dir/locale_base_api/ibm.h
28+ __locale_dir/locale_base_api/openbsd.h
29 __locale_dir/messages.h
30 __locale_dir/money.h
31 __locale_dir/num.h
32@@ -553,7 +554,6 @@ set(files
33 __locale_dir/support/no_locale/conversions.h
34 __locale_dir/support/no_locale/formatting.h
35 __locale_dir/support/no_locale/strtonum.h
36- __locale_dir/support/openbsd.h
37 __locale_dir/support/windows.h
38 __locale_dir/time.h
39 __locale_dir/wbuffer_convert.h
40@@ -786,6 +786,7 @@ set(files
41 __support/ibm/locale_mgmt_zos.h
42 __support/ibm/nanosleep.h
43 __support/xlocale/__posix_l_fallback.h
44+ __support/xlocale/__strtonum_fallback.h
45 __system_error/errc.h
46 __system_error/error_category.h
47 __system_error/error_code.h
48diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
49index f973d95ef244..d0ee5417739c 100644
50--- a/libcxx/include/__locale_dir/locale_base_api.h
51+++ b/libcxx/include/__locale_dir/locale_base_api.h
52@@ -114,8 +114,6 @@
53 # include <__locale_dir/support/freebsd.h>
54 # elif defined(__NetBSD__)
55 # include <__locale_dir/support/netbsd.h>
56-# elif defined(__OpenBSD__)
57-# include <__locale_dir/support/openbsd.h>
58 # elif defined(_LIBCPP_MSVCRT_LIKE)
59 # include <__locale_dir/support/windows.h>
60 # elif defined(__Fuchsia__)
61@@ -134,7 +132,11 @@
62 // (by providing global non-reserved names) and the new API. As we move individual platforms
63 // towards the new way of defining the locale base API, this should disappear since each platform
64 // will define those directly.
65-# include <__locale_dir/locale_base_api/ibm.h>
66+# if defined(__MVS__)
67+# include <__locale_dir/locale_base_api/ibm.h>
68+# elif defined(__OpenBSD__)
69+# include <__locale_dir/locale_base_api/openbsd.h>
70+# endif
71
72 # include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h>
73
74diff --git a/libcxx/include/__locale_dir/locale_base_api/openbsd.h b/libcxx/include/__locale_dir/locale_base_api/openbsd.h
75new file mode 100644
76index 000000000000..d4fb224e0c80
77--- /dev/null
78+++ b/libcxx/include/__locale_dir/locale_base_api/openbsd.h
79@@ -0,0 +1,19 @@
80+// -*- C++ -*-
81+//===-----------------------------------------------------------------------===//
82+//
83+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
84+// See https://llvm.org/LICENSE.txt for license information.
85+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
86+//
87+//===----------------------------------------------------------------------===//
88+
89+#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H
90+#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H
91+
92+#include <__support/xlocale/__strtonum_fallback.h>
93+#include <clocale>
94+#include <cstdlib>
95+#include <ctype.h>
96+#include <cwctype>
97+
98+#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H
99diff --git a/libcxx/include/__locale_dir/support/openbsd.h b/libcxx/include/__locale_dir/support/openbsd.h
100deleted file mode 100644
101index 0ec5b12f2ebd..000000000000
102--- a/libcxx/include/__locale_dir/support/openbsd.h
103+++ /dev/null
104@@ -1,229 +0,0 @@
105-// -*- C++ -*-
106-//===-----------------------------------------------------------------------===//
107-//
108-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
109-// See https://llvm.org/LICENSE.txt for license information.
110-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
111-//
112-//===----------------------------------------------------------------------===//
113-
114-#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H
115-#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H
116-
117-#include <__config>
118-#include <__cstddef/size_t.h>
119-#include <__std_mbstate_t.h>
120-#include <__utility/forward.h>
121-#include <clocale> // std::lconv
122-#include <ctype.h>
123-#include <stdio.h>
124-#include <stdlib.h>
125-#include <string.h>
126-#include <time.h>
127-#if _LIBCPP_HAS_WIDE_CHARACTERS
128-# include <wchar.h>
129-# include <wctype.h>
130-#endif
131-
132-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
133-# pragma GCC system_header
134-#endif
135-
136-_LIBCPP_BEGIN_NAMESPACE_STD
137-namespace __locale {
138-
139-struct __locale_guard {
140- __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
141-
142- ~__locale_guard() {
143- if (__old_loc_)
144- ::uselocale(__old_loc_);
145- }
146-
147- locale_t __old_loc_;
148-
149- __locale_guard(__locale_guard const&) = delete;
150- __locale_guard& operator=(__locale_guard const&) = delete;
151-};
152-
153-//
154-// Locale management
155-//
156-#define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
157-#define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
158-#define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
159-#define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
160-#define _LIBCPP_TIME_MASK LC_TIME_MASK
161-#define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
162-#define _LIBCPP_ALL_MASK LC_ALL_MASK
163-#define _LIBCPP_LC_ALL LC_ALL
164-
165-using __locale_t _LIBCPP_NODEBUG = ::locale_t;
166-#if defined(_LIBCPP_BUILDING_LIBRARY)
167-using __lconv_t _LIBCPP_NODEBUG = std::lconv;
168-
169-inline __locale_t __newlocale(int __category_mask, const char* __locale, __locale_t __base) {
170- return ::newlocale(__category_mask, __locale, __base);
171-}
172-
173-inline void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
174-
175-inline char* __setlocale(int __category, char const* __locale) { return ::setlocale(__category, __locale); }
176-
177-inline __lconv_t* __localeconv(__locale_t& __loc) {
178- __locale_guard __current(__loc);
179- return ::localeconv();
180-}
181-#endif // _LIBCPP_BUILDING_LIBRARY
182-
183-//
184-// Strtonum functions
185-//
186-inline float __strtof(const char* __nptr, char** __endptr, __locale_t) { return ::strtof(__nptr, __endptr); }
187-
188-inline double __strtod(const char* __nptr, char** __endptr, __locale_t) { return ::strtod(__nptr, __endptr); }
189-
190-inline long double __strtold(const char* __nptr, char** __endptr, __locale_t) { return ::strtold(__nptr, __endptr); }
191-
192-//
193-// Character manipulation functions
194-//
195-#if defined(_LIBCPP_BUILDING_LIBRARY)
196-inline int __toupper(int __c, __locale_t __loc) { return ::toupper_l(__c, __loc); }
197-
198-inline int __tolower(int __c, __locale_t __loc) { return ::tolower_l(__c, __loc); }
199-
200-inline int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) { return ::strcoll_l(__s1, __s2, __loc); }
201-
202-inline size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) {
203- return ::strxfrm_l(__dest, __src, __n, __loc);
204-}
205-
206-# if _LIBCPP_HAS_WIDE_CHARACTERS
207-inline int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) { return ::iswctype_l(__c, __type, __loc); }
208-
209-inline int __iswspace(wint_t __c, __locale_t __loc) { return ::iswspace_l(__c, __loc); }
210-
211-inline int __iswprint(wint_t __c, __locale_t __loc) { return ::iswprint_l(__c, __loc); }
212-
213-inline int __iswcntrl(wint_t __c, __locale_t __loc) { return ::iswcntrl_l(__c, __loc); }
214-
215-inline int __iswupper(wint_t __c, __locale_t __loc) { return ::iswupper_l(__c, __loc); }
216-
217-inline int __iswlower(wint_t __c, __locale_t __loc) { return ::iswlower_l(__c, __loc); }
218-
219-inline int __iswalpha(wint_t __c, __locale_t __loc) { return ::iswalpha_l(__c, __loc); }
220-
221-inline int __iswblank(wint_t __c, __locale_t __loc) { return ::iswblank_l(__c, __loc); }
222-
223-inline int __iswdigit(wint_t __c, __locale_t __loc) { return ::iswdigit_l(__c, __loc); }
224-
225-inline int __iswpunct(wint_t __c, __locale_t __loc) { return ::iswpunct_l(__c, __loc); }
226-
227-inline int __iswxdigit(wint_t __c, __locale_t __loc) { return ::iswxdigit_l(__c, __loc); }
228-
229-inline wint_t __towupper(wint_t __c, __locale_t __loc) { return ::towupper_l(__c, __loc); }
230-
231-inline wint_t __towlower(wint_t __c, __locale_t __loc) { return ::towlower_l(__c, __loc); }
232-
233-inline int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t __loc) {
234- return ::wcscoll_l(__ws1, __ws2, __loc);
235-}
236-
237-inline size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
238- return ::wcsxfrm_l(__dest, __src, __n, __loc);
239-}
240-# endif // _LIBCPP_HAS_WIDE_CHARACTERS
241-
242-inline _LIBCPP_ATTRIBUTE_FORMAT(__strftime__, 3, 0) size_t
243- __strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) {
244- return ::strftime_l(__s, __max, __format, __tm, __loc);
245-}
246-
247-//
248-// Other functions
249-//
250-inline decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) {
251- __locale_guard __current(__loc);
252- return MB_CUR_MAX;
253-}
254-
255-# if _LIBCPP_HAS_WIDE_CHARACTERS
256-inline wint_t __btowc(int __c, __locale_t __loc) {
257- __locale_guard __current(__loc);
258- return btowc(__c);
259-}
260-
261-inline int __wctob(wint_t __c, __locale_t __loc) {
262- __locale_guard __current(__loc);
263- return wctob(__c);
264-}
265-
266-inline size_t
267-__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) {
268- __locale_guard __current(__loc);
269- return wcsnrtombs(__dest, __src, __nwc, __len, __ps); // wcsnrtombs is a POSIX extension
270-}
271-
272-inline size_t __wcrtomb(char* __s, wchar_t __wc, mbstate_t* __ps, __locale_t __loc) {
273- __locale_guard __current(__loc);
274- return wcrtomb(__s, __wc, __ps);
275-}
276-
277-inline size_t
278-__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) {
279- __locale_guard __current(__loc);
280- return mbsnrtowcs(__dest, __src, __nms, __len, __ps); // mbsnrtowcs is a POSIX extension
281-}
282-
283-inline size_t __mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
284- __locale_guard __current(__loc);
285- return mbrtowc(__pwc, __s, __n, __ps);
286-}
287-
288-inline int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
289- __locale_guard __current(__loc);
290- return mbtowc(__pwc, __pmb, __max);
291-}
292-
293-inline size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
294- __locale_guard __current(__loc);
295- return mbrlen(__s, __n, __ps);
296-}
297-
298-inline size_t __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
299- __locale_guard __current(__loc);
300- return mbsrtowcs(__dest, __src, __len, __ps);
301-}
302-# endif // _LIBCPP_HAS_WIDE_CHARACTERS
303-#endif // _LIBCPP_BUILDING_LIBRARY
304-
305-_LIBCPP_DIAGNOSTIC_PUSH
306-_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
307-_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
308-#ifdef _LIBCPP_COMPILER_CLANG_BASED
309-# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
310-#else
311-# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
312-#endif
313-
314-template <class... _Args>
315-_LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5)
316-int __snprintf(char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) {
317- __locale_guard __current(__loc);
318- return ::snprintf(__s, __n, __format, std::forward<_Args>(__args)...);
319-}
320-
321-template <class... _Args>
322-_LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4)
323-int __asprintf(char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
324- __locale_guard __current(__loc);
325- return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard
326-}
327-_LIBCPP_DIAGNOSTIC_POP
328-#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
329-
330-} // namespace __locale
331-_LIBCPP_END_NAMESPACE_STD
332-
333-#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H
334diff --git a/libcxx/include/__support/xlocale/__strtonum_fallback.h b/libcxx/include/__support/xlocale/__strtonum_fallback.h
335new file mode 100644
336index 000000000000..90bd59d36c24
337--- /dev/null
338+++ b/libcxx/include/__support/xlocale/__strtonum_fallback.h
339@@ -0,0 +1,37 @@
340+// -*- C++ -*-
341+//===-----------------------------------------------------------------------===//
342+//
343+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
344+// See https://llvm.org/LICENSE.txt for license information.
345+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
346+//
347+//===----------------------------------------------------------------------===//
348+// These are reimplementations of some extended locale functions ( *_l ) that
349+// aren't part of POSIX. They are widely available though (GLIBC, BSD, maybe
350+// others). The unifying aspect in this case is that all of these functions
351+// convert strings to some numeric type.
352+//===----------------------------------------------------------------------===//
353+
354+#ifndef _LIBCPP___SUPPORT_XLOCALE_STRTONUM_FALLBACK_H
355+#define _LIBCPP___SUPPORT_XLOCALE_STRTONUM_FALLBACK_H
356+
357+#include <__config>
358+#include <stdlib.h>
359+
360+#if _LIBCPP_HAS_WIDE_CHARACTERS
361+# include <wchar.h>
362+#endif
363+
364+inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t) {
365+ return ::strtof(__nptr, __endptr);
366+}
367+
368+inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t) {
369+ return ::strtod(__nptr, __endptr);
370+}
371+
372+inline _LIBCPP_HIDE_FROM_ABI long double strtold_l(const char* __nptr, char** __endptr, locale_t) {
373+ return ::strtold(__nptr, __endptr);
374+}
375+
376+#endif // _LIBCPP___SUPPORT_XLOCALE_STRTONUM_FALLBACK_H
377diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
378index 39b4e0bb986c..620428b71a3d 100644
379--- a/libcxx/include/module.modulemap.in
380+++ b/libcxx/include/module.modulemap.in
381@@ -1616,13 +1616,13 @@ module std {
382 textual header "__locale_dir/support/newlib.h"
383 textual header "__locale_dir/support/no_locale/characters.h"
384 textual header "__locale_dir/support/no_locale/strtonum.h"
385- textual header "__locale_dir/support/openbsd.h"
386 textual header "__locale_dir/support/windows.h"
387 }
388
389 module locale_base_api {
390 textual header "__locale_dir/locale_base_api/bsd_locale_fallbacks.h"
391 textual header "__locale_dir/locale_base_api/ibm.h"
392+ textual header "__locale_dir/locale_base_api/openbsd.h"
393 }
394 export *
395 }
396--
3972.55.0
398