bpo-36142: _PyPreConfig_Read() sets LC_CTYPE (GH-12188) · python/cpython@4fffd38

@@ -387,7 +387,7 @@ _Py_ClearArgcArgv(void)

387387

}

388388389389390-

int

390+

static int

391391

_Py_SetArgcArgv(int argc, wchar_t * const *argv)

392392

{

393393

int res;

@@ -473,6 +473,9 @@ _PyCoreConfig_Clear(_PyCoreConfig *config)

473473

CLEAR(config->filesystem_errors);

474474

CLEAR(config->stdio_encoding);

475475

CLEAR(config->stdio_errors);

476+

CLEAR(config->run_command);

477+

CLEAR(config->run_module);

478+

CLEAR(config->run_filename);

476479

#undef CLEAR

477480

#undef CLEAR_WSTRLIST

478481

}

@@ -677,8 +680,6 @@ _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config)

677680

void

678681

_PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)

679682

{

680-

_PyPreConfig_SetGlobalConfig(&config->preconfig);

681-682683

#define COPY_FLAG(ATTR, VAR) \

683684

if (config->ATTR != -1) { \

684685

VAR = config->ATTR; \

@@ -812,6 +813,7 @@ config_init_executable(_PyCoreConfig *config)

812813

return _Py_INIT_OK();

813814

}

814815816+815817

static const wchar_t*

816818

config_get_xoption(const _PyCoreConfig *config, wchar_t *name)

817819

{

@@ -897,35 +899,34 @@ config_wstr_to_int(const wchar_t *wstr, int *result)

897899

static _PyInitError

898900

config_read_env_vars(_PyCoreConfig *config)

899901

{

900-

#define get_env_flag(CONFIG, ATTR, NAME) \

901-

_Py_get_env_flag(&(CONFIG)->preconfig, (ATTR), (NAME))

902+

_PyPreConfig *preconfig = &config->preconfig;

902903903904

/* Get environment variables */

904-

get_env_flag(config, &config->parser_debug, "PYTHONDEBUG");

905-

get_env_flag(config, &config->verbose, "PYTHONVERBOSE");

906-

get_env_flag(config, &config->optimization_level, "PYTHONOPTIMIZE");

907-

get_env_flag(config, &config->inspect, "PYTHONINSPECT");

905+

_Py_get_env_flag(preconfig, &config->parser_debug, "PYTHONDEBUG");

906+

_Py_get_env_flag(preconfig, &config->verbose, "PYTHONVERBOSE");

907+

_Py_get_env_flag(preconfig, &config->optimization_level, "PYTHONOPTIMIZE");

908+

_Py_get_env_flag(preconfig, &config->inspect, "PYTHONINSPECT");

908909909910

int dont_write_bytecode = 0;

910-

get_env_flag(config, &dont_write_bytecode, "PYTHONDONTWRITEBYTECODE");

911+

_Py_get_env_flag(preconfig, &dont_write_bytecode, "PYTHONDONTWRITEBYTECODE");

911912

if (dont_write_bytecode) {

912913

config->write_bytecode = 0;

913914

}

914915915916

int no_user_site_directory = 0;

916-

get_env_flag(config, &no_user_site_directory, "PYTHONNOUSERSITE");

917+

_Py_get_env_flag(preconfig, &no_user_site_directory, "PYTHONNOUSERSITE");

917918

if (no_user_site_directory) {

918919

config->user_site_directory = 0;

919920

}

920921921922

int unbuffered_stdio = 0;

922-

get_env_flag(config, &unbuffered_stdio, "PYTHONUNBUFFERED");

923+

_Py_get_env_flag(preconfig, &unbuffered_stdio, "PYTHONUNBUFFERED");

923924

if (unbuffered_stdio) {

924925

config->buffered_stdio = 0;

925926

}

926927927928

#ifdef MS_WINDOWS

928-

get_env_flag(config, &config->legacy_windows_stdio,

929+

_Py_get_env_flag(preconfig, &config->legacy_windows_stdio,

929930

"PYTHONLEGACYWINDOWSSTDIO");

930931

#endif

931932

@@ -952,8 +953,6 @@ config_read_env_vars(_PyCoreConfig *config)

952953

}

953954954955

return _Py_INIT_OK();

955-956-

#undef get_env_flag

957956

}

958957959958

@@ -1333,10 +1332,7 @@ _PyCoreConfig_ReadPreConfig(_PyCoreConfig *config)

13331332

}

13341333133513341336-

/* Read the configuration into _PyCoreConfig and initialize the LC_CTYPE

1337-

locale: enable UTF-8 mode (PEP 540) and/or coerce the C locale (PEP 538).

1338-1339-

Read the configuration from:

1335+

/* Read the configuration into _PyCoreConfig from:

1340133613411337

* Environment variables

13421338

* Py_xxx global configuration variables

@@ -1497,8 +1493,6 @@ config_init_stdio(const _PyCoreConfig *config)

1497149314981494

/* Write the configuration:

149914951500-

- coerce the LC_CTYPE locale (PEP 538)

1501-

- UTF-8 mode (PEP 540)

15021496

- set Py_xxx global configuration variables

15031497

- initialize C standard streams (stdin, stdout, stderr) */

15041498

void

@@ -2110,10 +2104,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,

21102104

}

21112105211221062113-

/* Read the configuration into _PyCoreConfig and initialize the LC_CTYPE

2114-

locale: enable UTF-8 mode (PEP 540) and/or coerce the C locale (PEP 538).

2115-2116-

Read the configuration from:

2107+

/* Read the configuration into _PyCoreConfig from:

2117210821182109

* Command line arguments

21192110

* Environment variables