|
9 | 9 | import os
|
10 | 10 | import pickle
|
11 | 11 | import platform
|
12 |
| -import shlex |
13 | 12 | import shutil
|
14 | 13 | import tempfile
|
15 | 14 |
|
@@ -274,23 +273,41 @@ def hasAnyLocale(config, locales):
|
274 | 273 | %{exec} -- this means that the command may be executed on a remote host
|
275 | 274 | depending on the %{exec} substitution.
|
276 | 275 | """
|
277 |
| - program = """ |
| 276 | + |
| 277 | + # Convert the locale names into C string literals. We expect all currently |
| 278 | + # known locale names to be printable ASCII and not contain awkward |
| 279 | + # characters like \ or ", so this should be trivial. |
| 280 | + assert all( |
| 281 | + 0x20 <= ord(ch) <= 0x7E and ch not in {'"', "\\"} |
| 282 | + for locale in locales |
| 283 | + for ch in locale |
| 284 | + ) |
| 285 | + name_string_literals = ", ".join('"' + locale + '"' for locale in locales) |
| 286 | + |
| 287 | + program = ( |
| 288 | + """ |
278 | 289 | #include <stddef.h>
|
279 | 290 | #if defined(_LIBCPP_VERSION) && !_LIBCPP_HAS_LOCALIZATION
|
280 | 291 | int main(int, char**) { return 1; }
|
281 | 292 | #else
|
282 | 293 | #include <locale.h>
|
283 |
| - int main(int argc, char** argv) { |
284 |
| - for (int i = 1; i < argc; i++) { |
285 |
| - if (::setlocale(LC_ALL, argv[i]) != NULL) { |
| 294 | + static const char *const test_locale_names[] = { |
| 295 | + """ |
| 296 | + + name_string_literals |
| 297 | + + """, nullptr, |
| 298 | + }; |
| 299 | + int main() { |
| 300 | + for (size_t i = 0; test_locale_names[i]; i++) { |
| 301 | + if (::setlocale(LC_ALL, test_locale_names[i]) != NULL) { |
286 | 302 | return 0;
|
287 | 303 | }
|
288 | 304 | }
|
289 | 305 | return 1;
|
290 | 306 | }
|
291 | 307 | #endif
|
292 |
| - """ |
293 |
| - return programSucceeds(config, program, args=[shlex.quote(l) for l in locales]) |
| 308 | + """ |
| 309 | + ) |
| 310 | + return programSucceeds(config, program) |
294 | 311 |
|
295 | 312 |
|
296 | 313 | @_memoizeExpensiveOperation(lambda c, flags="": (c.substitutions, c.environment, flags))
|
|
0 commit comments