[libcxx-commits] [libcxx] [libcxx] Work around picolibc argv handling in tests. (PR #127662)
Simon Tatham via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 19 05:22:44 PST 2025
================
@@ -274,23 +274,38 @@ def hasAnyLocale(config, locales):
%{exec} -- this means that the command may be executed on a remote host
depending on the %{exec} substitution.
"""
- program = """
+
+ # Convert the locale names into C string literals, by escaping \
+ # and " and wrapping each one in double quotes.
+ name_string_literals = ", ".join(
+ '"' + locale.replace("\\", r"\\").replace('"', r"\"") + '"'
+ for locale in locales
+ )
+
+ program = (
+ """
#include <stddef.h>
#if defined(_LIBCPP_VERSION) && !_LIBCPP_HAS_LOCALIZATION
int main(int, char**) { return 1; }
#else
#include <locale.h>
- int main(int argc, char** argv) {
- for (int i = 1; i < argc; i++) {
- if (::setlocale(LC_ALL, argv[i]) != NULL) {
+ static const char *const test_locale_names[] = {
+ """
+ + name_string_literals
+ + """, nullptr,
+ };
+ int main() {
+ for (size_t i = 0; test_locale_names[i]; i++) {
+ if (::setlocale(LC_ALL, test_locale_names[i]) != NULL) {
return 0;
}
}
return 1;
}
#endif
- """
- return programSucceeds(config, program, args=[shlex.quote(l) for l in locales])
----------------
statham-arm wrote:
Oh yes, because that was the only use of it in the whole module. Good catch.
https://github.com/llvm/llvm-project/pull/127662
More information about the libcxx-commits
mailing list