From 9454060e84a669dde63824d9e2fcaf295e34f687 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 16 Dec 2017 04:54:22 +0100 Subject: bpo-29240, bpo-32030: Py_Main() re-reads config if encoding changes (#4899) bpo-29240, bpo-32030: If the encoding change (C locale coerced or UTF-8 Mode changed), Py_Main() now reads again the configuration with the new encoding. Changes: * Add _Py_UnixMain() called by main(). * Rename pymain_free_pymain() to pymain_clear_pymain(), it can now be called multipled times. * Rename pymain_parse_cmdline_envvars() to pymain_read_conf(). * Py_Main() now clears orig_argc and orig_argv at exit. * Remove argv_copy2, Py_Main() doesn't modify argv anymore. There is no need anymore to get two copies of the wchar_t** argv. * _PyCoreConfig: add coerce_c_locale and coerce_c_locale_warn. * Py_UTF8Mode is now initialized to -1. * Locale coercion (PEP 538) now respects -I and -E options. --- Python/bltinmodule.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 604493dc5e..e702f7c6e9 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -29,9 +29,10 @@ const char *Py_FileSystemDefaultEncoding = NULL; /* set by initfsencoding() */ int Py_HasFileSystemDefaultEncoding = 0; #endif const char *Py_FileSystemDefaultEncodeErrors = "surrogateescape"; -/* UTF-8 mode (PEP 540): if non-zero, use the UTF-8 encoding, and change stdin - and stdout error handler to "surrogateescape". */ -int Py_UTF8Mode = 0; +/* UTF-8 mode (PEP 540): if equals to 1, use the UTF-8 encoding, and change + stdin and stdout error handler to "surrogateescape". It is equal to + -1 by default: unknown, will be set by Py_Main() */ +int Py_UTF8Mode = -1; _Py_IDENTIFIER(__builtins__); _Py_IDENTIFIER(__dict__); -- cgit v1.2.1