blob: 392324ff201a338ef1dcda9cfc4afaf98dea2674 [file] [log] [blame]
Victor Stinner91b9ecf2019-03-01 17:52:56 +01001#include "Python.h"
2#include "pycore_coreconfig.h"
Victor Stinner6dcb5422019-03-05 02:44:12 +01003#include "pycore_getopt.h"
Victor Stinner5a02e0d2019-03-05 12:32:09 +01004#include "pycore_pystate.h" /* _PyRuntime_Initialize() */
5#include <locale.h> /* setlocale() */
Victor Stinner91b9ecf2019-03-01 17:52:56 +01006
7
8#define DECODE_LOCALE_ERR(NAME, LEN) \
9 (((LEN) == -2) \
Victor Stinnerdb719752019-05-01 05:35:33 +020010 ? _Py_INIT_ERR("cannot decode " NAME) \
Victor Stinner91b9ecf2019-03-01 17:52:56 +010011 : _Py_INIT_NO_MEMORY())
12
13
14/* --- File system encoding/errors -------------------------------- */
15
16/* The filesystem encoding is chosen by config_init_fs_encoding(),
Victor Stinner709d23d2019-05-02 14:56:30 -040017 see also initfsencoding().
18
19 Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors
20 are encoded to UTF-8. */
Victor Stinner91b9ecf2019-03-01 17:52:56 +010021const char *Py_FileSystemDefaultEncoding = NULL;
22int Py_HasFileSystemDefaultEncoding = 0;
23const char *Py_FileSystemDefaultEncodeErrors = NULL;
24int _Py_HasFileSystemDefaultEncodeErrors = 0;
25
26void
27_Py_ClearFileSystemEncoding(void)
28{
29 if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) {
30 PyMem_RawFree((char*)Py_FileSystemDefaultEncoding);
31 Py_FileSystemDefaultEncoding = NULL;
32 }
33 if (!_Py_HasFileSystemDefaultEncodeErrors && Py_FileSystemDefaultEncodeErrors) {
34 PyMem_RawFree((char*)Py_FileSystemDefaultEncodeErrors);
35 Py_FileSystemDefaultEncodeErrors = NULL;
36 }
37}
38
39
40/* Set Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors
41 global configuration variables. */
42int
43_Py_SetFileSystemEncoding(const char *encoding, const char *errors)
44{
45 char *encoding2 = _PyMem_RawStrdup(encoding);
46 if (encoding2 == NULL) {
47 return -1;
48 }
49
50 char *errors2 = _PyMem_RawStrdup(errors);
51 if (errors2 == NULL) {
52 PyMem_RawFree(encoding2);
53 return -1;
54 }
55
56 _Py_ClearFileSystemEncoding();
57
58 Py_FileSystemDefaultEncoding = encoding2;
59 Py_HasFileSystemDefaultEncoding = 0;
60
61 Py_FileSystemDefaultEncodeErrors = errors2;
62 _Py_HasFileSystemDefaultEncodeErrors = 0;
63 return 0;
64}
65
66
67/* --- _PyArgv ---------------------------------------------------- */
68
Victor Stinnerf8ba6f52019-03-26 16:58:50 +010069/* Decode bytes_argv using Py_DecodeLocale() */
Victor Stinner91b9ecf2019-03-01 17:52:56 +010070_PyInitError
Victor Stinner74f65682019-03-15 15:08:05 +010071_PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list)
Victor Stinner91b9ecf2019-03-01 17:52:56 +010072{
Victor Stinner74f65682019-03-15 15:08:05 +010073 _PyWstrList wargv = _PyWstrList_INIT;
Victor Stinner91b9ecf2019-03-01 17:52:56 +010074 if (args->use_bytes_argv) {
Victor Stinner74f65682019-03-15 15:08:05 +010075 size_t size = sizeof(wchar_t*) * args->argc;
76 wargv.items = (wchar_t **)PyMem_RawMalloc(size);
77 if (wargv.items == NULL) {
Victor Stinner91b9ecf2019-03-01 17:52:56 +010078 return _Py_INIT_NO_MEMORY();
79 }
80
Victor Stinner74f65682019-03-15 15:08:05 +010081 for (Py_ssize_t i = 0; i < args->argc; i++) {
Victor Stinner91b9ecf2019-03-01 17:52:56 +010082 size_t len;
83 wchar_t *arg = Py_DecodeLocale(args->bytes_argv[i], &len);
84 if (arg == NULL) {
Victor Stinner74f65682019-03-15 15:08:05 +010085 _PyWstrList_Clear(&wargv);
Victor Stinner91b9ecf2019-03-01 17:52:56 +010086 return DECODE_LOCALE_ERR("command line arguments",
87 (Py_ssize_t)len);
88 }
Victor Stinner74f65682019-03-15 15:08:05 +010089 wargv.items[i] = arg;
90 wargv.length++;
Victor Stinner91b9ecf2019-03-01 17:52:56 +010091 }
Victor Stinner74f65682019-03-15 15:08:05 +010092
93 _PyWstrList_Clear(list);
94 *list = wargv;
Victor Stinner91b9ecf2019-03-01 17:52:56 +010095 }
96 else {
Victor Stinner74f65682019-03-15 15:08:05 +010097 wargv.length = args->argc;
Victor Stinner6d1c4672019-05-20 11:02:00 +020098 wargv.items = (wchar_t **)args->wchar_argv;
Victor Stinner74f65682019-03-15 15:08:05 +010099 if (_PyWstrList_Copy(list, &wargv) < 0) {
100 return _Py_INIT_NO_MEMORY();
101 }
Victor Stinner91b9ecf2019-03-01 17:52:56 +0100102 }
Victor Stinner91b9ecf2019-03-01 17:52:56 +0100103 return _Py_INIT_OK();
104}
Victor Stinnercad1f742019-03-05 02:01:27 +0100105
106
Victor Stinner6dcb5422019-03-05 02:44:12 +0100107/* --- _PyPreCmdline ------------------------------------------------- */
108
Victor Stinnerfa153762019-03-20 04:25:38 +0100109void
110_PyPreCmdline_Clear(_PyPreCmdline *cmdline)
Victor Stinner6dcb5422019-03-05 02:44:12 +0100111{
Victor Stinner74f65682019-03-15 15:08:05 +0100112 _PyWstrList_Clear(&cmdline->argv);
113 _PyWstrList_Clear(&cmdline->xoptions);
Victor Stinner6dcb5422019-03-05 02:44:12 +0100114}
115
116
Victor Stinnerfa153762019-03-20 04:25:38 +0100117_PyInitError
Victor Stinnerf72346c2019-03-25 17:54:58 +0100118_PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args)
Victor Stinnerfa153762019-03-20 04:25:38 +0100119{
120 return _PyArgv_AsWstrList(args, &cmdline->argv);
121}
122
123
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100124static void
Victor Stinnerf72346c2019-03-25 17:54:58 +0100125_PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config)
126{
127#define COPY_ATTR(ATTR) \
128 if (config->ATTR != -1) { \
129 cmdline->ATTR = config->ATTR; \
130 }
131
Victor Stinnerf72346c2019-03-25 17:54:58 +0100132 COPY_ATTR(isolated);
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100133 COPY_ATTR(use_environment);
Victor Stinner20004952019-03-26 02:31:11 +0100134 COPY_ATTR(dev_mode);
135
136#undef COPY_ATTR
137}
138
139
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100140static void
Victor Stinner20004952019-03-26 02:31:11 +0100141_PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config)
142{
143#define COPY_ATTR(ATTR) \
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100144 config->ATTR = cmdline->ATTR
Victor Stinner20004952019-03-26 02:31:11 +0100145
Victor Stinner20004952019-03-26 02:31:11 +0100146 COPY_ATTR(isolated);
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100147 COPY_ATTR(use_environment);
Victor Stinner20004952019-03-26 02:31:11 +0100148 COPY_ATTR(dev_mode);
Victor Stinnerf72346c2019-03-25 17:54:58 +0100149
150#undef COPY_ATTR
151}
152
153
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100154int
Victor Stinnera6fbc4e2019-03-25 18:37:10 +0100155_PyPreCmdline_SetCoreConfig(const _PyPreCmdline *cmdline, _PyCoreConfig *config)
156{
157#define COPY_ATTR(ATTR) \
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100158 config->ATTR = cmdline->ATTR
159
160 if (_PyWstrList_Extend(&config->xoptions, &cmdline->xoptions) < 0) {
161 return -1;
Victor Stinnera6fbc4e2019-03-25 18:37:10 +0100162 }
163
Victor Stinnera6fbc4e2019-03-25 18:37:10 +0100164 COPY_ATTR(isolated);
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100165 COPY_ATTR(use_environment);
Victor Stinner20004952019-03-26 02:31:11 +0100166 COPY_ATTR(dev_mode);
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100167 return 0;
Victor Stinnera6fbc4e2019-03-25 18:37:10 +0100168
169#undef COPY_ATTR
170}
171
172
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100173/* Parse the command line arguments */
174static _PyInitError
175precmdline_parse_cmdline(_PyPreCmdline *cmdline)
176{
Victor Stinner870b0352019-05-17 03:15:12 +0200177 const _PyWstrList *argv = &cmdline->argv;
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100178
179 _PyOS_ResetGetOpt();
180 /* Don't log parsing errors into stderr here: _PyCoreConfig_Read()
181 is responsible for that */
182 _PyOS_opterr = 0;
183 do {
184 int longindex = -1;
185 int c = _PyOS_GetOpt(argv->length, argv->items, &longindex);
186
187 if (c == EOF || c == 'c' || c == 'm') {
188 break;
189 }
190
191 switch (c) {
192 case 'E':
193 cmdline->use_environment = 0;
194 break;
195
196 case 'I':
197 cmdline->isolated = 1;
198 break;
199
200 case 'X':
201 {
202 if (_PyWstrList_Append(&cmdline->xoptions, _PyOS_optarg) < 0) {
203 return _Py_INIT_NO_MEMORY();
204 }
205 break;
206 }
207
208 default:
209 /* ignore other argument:
210 handled by _PyCoreConfig_Read() */
211 break;
212 }
213 } while (1);
214
215 return _Py_INIT_OK();
216}
217
218
219_PyInitError
Victor Stinner6d1c4672019-05-20 11:02:00 +0200220_PyPreCmdline_Read(_PyPreCmdline *cmdline, const _PyPreConfig *preconfig)
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100221{
Victor Stinner6d1c4672019-05-20 11:02:00 +0200222 _PyPreCmdline_GetPreConfig(cmdline, preconfig);
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100223
Victor Stinner6d1c4672019-05-20 11:02:00 +0200224 if (preconfig->parse_argv) {
225 _PyInitError err = precmdline_parse_cmdline(cmdline);
226 if (_Py_INIT_FAILED(err)) {
227 return err;
228 }
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100229 }
230
231 /* isolated, use_environment */
232 if (cmdline->isolated < 0) {
233 cmdline->isolated = 0;
234 }
235 if (cmdline->isolated > 0) {
236 cmdline->use_environment = 0;
237 }
238 if (cmdline->use_environment < 0) {
239 cmdline->use_environment = 0;
240 }
241
242 /* dev_mode */
Victor Stinnerbab0db62019-05-18 03:21:27 +0200243 if ((cmdline->dev_mode < 0)
244 && (_Py_get_xoption(&cmdline->xoptions, L"dev")
245 || _Py_GetEnv(cmdline->use_environment, "PYTHONDEVMODE")))
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100246 {
247 cmdline->dev_mode = 1;
248 }
249 if (cmdline->dev_mode < 0) {
250 cmdline->dev_mode = 0;
251 }
252
253 assert(cmdline->use_environment >= 0);
254 assert(cmdline->isolated >= 0);
255 assert(cmdline->dev_mode >= 0);
256
257 return _Py_INIT_OK();
258}
259
260
Victor Stinnercad1f742019-03-05 02:01:27 +0100261/* --- _PyPreConfig ----------------------------------------------- */
262
Victor Stinnerbab0db62019-05-18 03:21:27 +0200263
Victor Stinnercab5d072019-05-17 19:01:14 +0200264void
Victor Stinner022be022019-05-22 23:58:50 +0200265_PyPreConfig_InitCompatConfig(_PyPreConfig *config)
Victor Stinnercab5d072019-05-17 19:01:14 +0200266{
Victor Stinnerbab0db62019-05-18 03:21:27 +0200267 memset(config, 0, sizeof(*config));
268
269 config->_config_version = _Py_CONFIG_VERSION;
Victor Stinner022be022019-05-22 23:58:50 +0200270 config->_config_init = (int)_PyConfig_INIT_COMPAT;
Victor Stinner6d1c4672019-05-20 11:02:00 +0200271 config->parse_argv = 0;
Victor Stinnerbab0db62019-05-18 03:21:27 +0200272 config->isolated = -1;
273 config->use_environment = -1;
274 config->configure_locale = 1;
Victor Stinner022be022019-05-22 23:58:50 +0200275 config->utf8_mode = -1;
Victor Stinnerbab0db62019-05-18 03:21:27 +0200276 config->dev_mode = -1;
277 config->allocator = PYMEM_ALLOCATOR_NOT_SET;
278#ifdef MS_WINDOWS
279 config->legacy_windows_fs_encoding = -1;
280#endif
Victor Stinnercab5d072019-05-17 19:01:14 +0200281}
282
283
284void
285_PyPreConfig_InitPythonConfig(_PyPreConfig *config)
286{
Victor Stinner022be022019-05-22 23:58:50 +0200287 _PyPreConfig_InitCompatConfig(config);
Victor Stinnercab5d072019-05-17 19:01:14 +0200288
Victor Stinner022be022019-05-22 23:58:50 +0200289 config->_config_init = (int)_PyConfig_INIT_PYTHON;
290 config->isolated = 0;
Victor Stinner6d1c4672019-05-20 11:02:00 +0200291 config->parse_argv = 1;
Victor Stinner022be022019-05-22 23:58:50 +0200292 config->use_environment = 1;
Victor Stinnercab5d072019-05-17 19:01:14 +0200293 /* Set to -1 to enable C locale coercion (PEP 538) and UTF-8 Mode (PEP 540)
294 depending on the LC_CTYPE locale, PYTHONUTF8 and PYTHONCOERCECLOCALE
295 environment variables. */
296 config->coerce_c_locale = -1;
297 config->coerce_c_locale_warn = -1;
298 config->utf8_mode = -1;
Victor Stinner022be022019-05-22 23:58:50 +0200299#ifdef MS_WINDOWS
300 config->legacy_windows_fs_encoding = 0;
301#endif
Victor Stinnercab5d072019-05-17 19:01:14 +0200302}
303
304
305void
306_PyPreConfig_InitIsolatedConfig(_PyPreConfig *config)
307{
Victor Stinner022be022019-05-22 23:58:50 +0200308 _PyPreConfig_InitCompatConfig(config);
Victor Stinnercab5d072019-05-17 19:01:14 +0200309
Victor Stinner022be022019-05-22 23:58:50 +0200310 config->_config_init = (int)_PyConfig_INIT_ISOLATED;
Victor Stinnerbcfbbd72019-05-17 22:44:16 +0200311 config->configure_locale = 0;
Victor Stinnercab5d072019-05-17 19:01:14 +0200312 config->isolated = 1;
313 config->use_environment = 0;
Victor Stinnerbab0db62019-05-18 03:21:27 +0200314 config->utf8_mode = 0;
315 config->dev_mode = 0;
Victor Stinnercab5d072019-05-17 19:01:14 +0200316#ifdef MS_WINDOWS
317 config->legacy_windows_fs_encoding = 0;
318#endif
Victor Stinnercab5d072019-05-17 19:01:14 +0200319}
320
321
Victor Stinnerb5947842019-05-18 00:38:16 +0200322void
Victor Stinner6d1c4672019-05-20 11:02:00 +0200323_PyPreConfig_InitFromPreConfig(_PyPreConfig *config,
324 const _PyPreConfig *config2)
325{
Victor Stinner022be022019-05-22 23:58:50 +0200326 _PyPreConfig_InitCompatConfig(config);
Victor Stinner6d1c4672019-05-20 11:02:00 +0200327 _PyPreConfig_Copy(config, config2);
328}
329
330
331void
332_PyPreConfig_InitFromCoreConfig(_PyPreConfig *config,
333 const _PyCoreConfig *coreconfig)
334{
Victor Stinner022be022019-05-22 23:58:50 +0200335 _PyConfigInitEnum config_init = (_PyConfigInitEnum)coreconfig->_config_init;
Victor Stinner6d1c4672019-05-20 11:02:00 +0200336 switch (config_init) {
Victor Stinner022be022019-05-22 23:58:50 +0200337 case _PyConfig_INIT_PYTHON:
Victor Stinner6d1c4672019-05-20 11:02:00 +0200338 _PyPreConfig_InitPythonConfig(config);
339 break;
Victor Stinner022be022019-05-22 23:58:50 +0200340 case _PyConfig_INIT_ISOLATED:
Victor Stinner6d1c4672019-05-20 11:02:00 +0200341 _PyPreConfig_InitIsolatedConfig(config);
342 break;
Victor Stinner022be022019-05-22 23:58:50 +0200343 case _PyConfig_INIT_COMPAT:
Victor Stinner6d1c4672019-05-20 11:02:00 +0200344 default:
Victor Stinner022be022019-05-22 23:58:50 +0200345 _PyPreConfig_InitCompatConfig(config);
Victor Stinner6d1c4672019-05-20 11:02:00 +0200346 }
347 _PyPreConfig_GetCoreConfig(config, coreconfig);
348}
349
350
351void
Victor Stinnercad1f742019-03-05 02:01:27 +0100352_PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2)
353{
Victor Stinnercad1f742019-03-05 02:01:27 +0100354#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
355
Victor Stinner6d1c4672019-05-20 11:02:00 +0200356 COPY_ATTR(parse_argv);
Victor Stinnercad1f742019-03-05 02:01:27 +0100357 COPY_ATTR(isolated);
358 COPY_ATTR(use_environment);
Victor Stinnerbcfbbd72019-05-17 22:44:16 +0200359 COPY_ATTR(configure_locale);
Victor Stinner20004952019-03-26 02:31:11 +0100360 COPY_ATTR(dev_mode);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100361 COPY_ATTR(coerce_c_locale);
362 COPY_ATTR(coerce_c_locale_warn);
Victor Stinnerb5947842019-05-18 00:38:16 +0200363 COPY_ATTR(utf8_mode);
364 COPY_ATTR(allocator);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100365#ifdef MS_WINDOWS
366 COPY_ATTR(legacy_windows_fs_encoding);
367#endif
Victor Stinnercad1f742019-03-05 02:01:27 +0100368
369#undef COPY_ATTR
Victor Stinnercad1f742019-03-05 02:01:27 +0100370}
371
372
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100373PyObject*
374_PyPreConfig_AsDict(const _PyPreConfig *config)
375{
376 PyObject *dict;
377
378 dict = PyDict_New();
379 if (dict == NULL) {
380 return NULL;
381 }
382
Victor Stinner6d1c4672019-05-20 11:02:00 +0200383#define SET_ITEM_INT(ATTR) \
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100384 do { \
Victor Stinner6d1c4672019-05-20 11:02:00 +0200385 PyObject *obj = PyLong_FromLong(config->ATTR); \
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100386 if (obj == NULL) { \
387 goto fail; \
388 } \
Victor Stinner6d1c4672019-05-20 11:02:00 +0200389 int res = PyDict_SetItemString(dict, #ATTR, obj); \
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100390 Py_DECREF(obj); \
391 if (res < 0) { \
392 goto fail; \
393 } \
394 } while (0)
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100395
Victor Stinner6d1c4672019-05-20 11:02:00 +0200396 SET_ITEM_INT(parse_argv);
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100397 SET_ITEM_INT(isolated);
398 SET_ITEM_INT(use_environment);
Victor Stinnerbcfbbd72019-05-17 22:44:16 +0200399 SET_ITEM_INT(configure_locale);
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100400 SET_ITEM_INT(coerce_c_locale);
401 SET_ITEM_INT(coerce_c_locale_warn);
402 SET_ITEM_INT(utf8_mode);
403#ifdef MS_WINDOWS
404 SET_ITEM_INT(legacy_windows_fs_encoding);
405#endif
406 SET_ITEM_INT(dev_mode);
Victor Stinnerb16b4e42019-05-17 15:20:52 +0200407 SET_ITEM_INT(allocator);
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100408 return dict;
409
410fail:
411 Py_DECREF(dict);
412 return NULL;
413
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100414#undef SET_ITEM_INT
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100415}
416
417
Victor Stinner5ac27a52019-03-27 13:40:14 +0100418void
Victor Stinnercab5d072019-05-17 19:01:14 +0200419_PyPreConfig_GetCoreConfig(_PyPreConfig *config,
Victor Stinner5ac27a52019-03-27 13:40:14 +0100420 const _PyCoreConfig *core_config)
421{
422#define COPY_ATTR(ATTR) \
423 if (core_config->ATTR != -1) { \
424 config->ATTR = core_config->ATTR; \
425 }
426
Victor Stinner6d1c4672019-05-20 11:02:00 +0200427 COPY_ATTR(parse_argv);
Victor Stinner5ac27a52019-03-27 13:40:14 +0100428 COPY_ATTR(isolated);
429 COPY_ATTR(use_environment);
430 COPY_ATTR(dev_mode);
431
432#undef COPY_ATTR
433}
434
435
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100436static void
Victor Stinnercad1f742019-03-05 02:01:27 +0100437_PyPreConfig_GetGlobalConfig(_PyPreConfig *config)
438{
Victor Stinner022be022019-05-22 23:58:50 +0200439 if (config->_config_init != _PyConfig_INIT_COMPAT) {
440 /* Python and Isolated configuration ignore global variables */
441 return;
442 }
443
Victor Stinnercad1f742019-03-05 02:01:27 +0100444#define COPY_FLAG(ATTR, VALUE) \
Victor Stinnercab5d072019-05-17 19:01:14 +0200445 if (config->ATTR < 0) { \
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100446 config->ATTR = VALUE; \
447 }
Victor Stinnercad1f742019-03-05 02:01:27 +0100448#define COPY_NOT_FLAG(ATTR, VALUE) \
Victor Stinnercab5d072019-05-17 19:01:14 +0200449 if (config->ATTR < 0) { \
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100450 config->ATTR = !(VALUE); \
451 }
Victor Stinnercad1f742019-03-05 02:01:27 +0100452
453 COPY_FLAG(isolated, Py_IsolatedFlag);
454 COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag);
Victor Stinner022be022019-05-22 23:58:50 +0200455 COPY_FLAG(utf8_mode, Py_UTF8Mode);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100456#ifdef MS_WINDOWS
457 COPY_FLAG(legacy_windows_fs_encoding, Py_LegacyWindowsFSEncodingFlag);
458#endif
Victor Stinnercad1f742019-03-05 02:01:27 +0100459
460#undef COPY_FLAG
461#undef COPY_NOT_FLAG
462}
463
464
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100465static void
Victor Stinnercad1f742019-03-05 02:01:27 +0100466_PyPreConfig_SetGlobalConfig(const _PyPreConfig *config)
467{
468#define COPY_FLAG(ATTR, VAR) \
Victor Stinnercab5d072019-05-17 19:01:14 +0200469 if (config->ATTR >= 0) { \
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100470 VAR = config->ATTR; \
471 }
Victor Stinnercad1f742019-03-05 02:01:27 +0100472#define COPY_NOT_FLAG(ATTR, VAR) \
Victor Stinnercab5d072019-05-17 19:01:14 +0200473 if (config->ATTR >= 0) { \
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100474 VAR = !config->ATTR; \
475 }
Victor Stinnercad1f742019-03-05 02:01:27 +0100476
477 COPY_FLAG(isolated, Py_IsolatedFlag);
478 COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100479#ifdef MS_WINDOWS
480 COPY_FLAG(legacy_windows_fs_encoding, Py_LegacyWindowsFSEncodingFlag);
481#endif
482 COPY_FLAG(utf8_mode, Py_UTF8Mode);
Victor Stinnercad1f742019-03-05 02:01:27 +0100483
484#undef COPY_FLAG
485#undef COPY_NOT_FLAG
486}
487
488
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100489const char*
Victor Stinnerf78a5e92019-03-26 00:03:15 +0100490_Py_GetEnv(int use_environment, const char *name)
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100491{
Victor Stinnerf78a5e92019-03-26 00:03:15 +0100492 assert(use_environment >= 0);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100493
Victor Stinnerf78a5e92019-03-26 00:03:15 +0100494 if (!use_environment) {
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100495 return NULL;
496 }
497
498 const char *var = getenv(name);
499 if (var && var[0] != '\0') {
500 return var;
501 }
502 else {
503 return NULL;
504 }
505}
506
507
508int
509_Py_str_to_int(const char *str, int *result)
510{
511 const char *endptr = str;
512 errno = 0;
513 long value = strtol(str, (char **)&endptr, 10);
514 if (*endptr != '\0' || errno == ERANGE) {
515 return -1;
516 }
517 if (value < INT_MIN || value > INT_MAX) {
518 return -1;
519 }
520
521 *result = (int)value;
522 return 0;
523}
524
525
526void
Victor Stinnerf78a5e92019-03-26 00:03:15 +0100527_Py_get_env_flag(int use_environment, int *flag, const char *name)
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100528{
Victor Stinnerf78a5e92019-03-26 00:03:15 +0100529 const char *var = _Py_GetEnv(use_environment, name);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100530 if (!var) {
531 return;
532 }
533 int value;
534 if (_Py_str_to_int(var, &value) < 0 || value < 0) {
535 /* PYTHONDEBUG=text and PYTHONDEBUG=-2 behave as PYTHONDEBUG=1 */
536 value = 1;
537 }
538 if (*flag < value) {
539 *flag = value;
540 }
541}
542
543
544const wchar_t*
Victor Stinner74f65682019-03-15 15:08:05 +0100545_Py_get_xoption(const _PyWstrList *xoptions, const wchar_t *name)
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100546{
Victor Stinner74f65682019-03-15 15:08:05 +0100547 for (Py_ssize_t i=0; i < xoptions->length; i++) {
548 const wchar_t *option = xoptions->items[i];
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100549 size_t len;
550 wchar_t *sep = wcschr(option, L'=');
551 if (sep != NULL) {
552 len = (sep - option);
553 }
554 else {
555 len = wcslen(option);
556 }
557 if (wcsncmp(option, name, len) == 0 && name[len] == L'\0') {
558 return option;
559 }
560 }
561 return NULL;
562}
563
564
565static _PyInitError
566preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
567{
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100568#ifdef MS_WINDOWS
569 if (config->legacy_windows_fs_encoding) {
570 config->utf8_mode = 0;
571 }
572#endif
573
574 if (config->utf8_mode >= 0) {
575 return _Py_INIT_OK();
576 }
577
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100578 const wchar_t *xopt;
Victor Stinner022be022019-05-22 23:58:50 +0200579 xopt = _Py_get_xoption(&cmdline->xoptions, L"utf8");
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100580 if (xopt) {
581 wchar_t *sep = wcschr(xopt, L'=');
582 if (sep) {
583 xopt = sep + 1;
584 if (wcscmp(xopt, L"1") == 0) {
585 config->utf8_mode = 1;
586 }
587 else if (wcscmp(xopt, L"0") == 0) {
588 config->utf8_mode = 0;
589 }
590 else {
Victor Stinnerdb719752019-05-01 05:35:33 +0200591 return _Py_INIT_ERR("invalid -X utf8 option value");
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100592 }
593 }
594 else {
595 config->utf8_mode = 1;
596 }
597 return _Py_INIT_OK();
598 }
599
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100600 const char *opt = _Py_GetEnv(config->use_environment, "PYTHONUTF8");
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100601 if (opt) {
602 if (strcmp(opt, "1") == 0) {
603 config->utf8_mode = 1;
604 }
605 else if (strcmp(opt, "0") == 0) {
606 config->utf8_mode = 0;
607 }
608 else {
Victor Stinnerdb719752019-05-01 05:35:33 +0200609 return _Py_INIT_ERR("invalid PYTHONUTF8 environment "
610 "variable value");
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100611 }
612 return _Py_INIT_OK();
613 }
614
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100615
616#ifndef MS_WINDOWS
617 if (config->utf8_mode < 0) {
618 /* The C locale and the POSIX locale enable the UTF-8 Mode (PEP 540) */
619 const char *ctype_loc = setlocale(LC_CTYPE, NULL);
620 if (ctype_loc != NULL
621 && (strcmp(ctype_loc, "C") == 0
622 || strcmp(ctype_loc, "POSIX") == 0))
623 {
624 config->utf8_mode = 1;
625 }
626 }
627#endif
628
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100629 if (config->utf8_mode < 0) {
630 config->utf8_mode = 0;
631 }
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100632 return _Py_INIT_OK();
633}
634
635
636static void
637preconfig_init_coerce_c_locale(_PyPreConfig *config)
638{
Victor Stinnerbcfbbd72019-05-17 22:44:16 +0200639 if (!config->configure_locale) {
640 config->coerce_c_locale = 0;
641 config->coerce_c_locale_warn = 0;
642 return;
643 }
644
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100645 const char *env = _Py_GetEnv(config->use_environment, "PYTHONCOERCECLOCALE");
646 if (env) {
647 if (strcmp(env, "0") == 0) {
648 if (config->coerce_c_locale < 0) {
649 config->coerce_c_locale = 0;
650 }
651 }
652 else if (strcmp(env, "warn") == 0) {
Victor Stinnercab5d072019-05-17 19:01:14 +0200653 if (config->coerce_c_locale_warn < 0) {
654 config->coerce_c_locale_warn = 1;
655 }
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100656 }
657 else {
658 if (config->coerce_c_locale < 0) {
659 config->coerce_c_locale = 1;
660 }
661 }
662 }
663
664 /* Test if coerce_c_locale equals to -1 or equals to 1:
665 PYTHONCOERCECLOCALE=1 doesn't imply that the C locale is always coerced.
666 It is only coerced if if the LC_CTYPE locale is "C". */
Victor Stinnercab5d072019-05-17 19:01:14 +0200667 if (config->coerce_c_locale < 0 || config->coerce_c_locale == 1) {
668 /* The C locale enables the C locale coercion (PEP 538) */
Victor Stinner0f721472019-05-20 17:16:38 +0200669 if (_Py_LegacyLocaleDetected(0)) {
Victor Stinnercab5d072019-05-17 19:01:14 +0200670 config->coerce_c_locale = 2;
671 }
672 else {
673 config->coerce_c_locale = 0;
674 }
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100675 }
676
Victor Stinnercab5d072019-05-17 19:01:14 +0200677 if (config->coerce_c_locale_warn < 0) {
678 config->coerce_c_locale_warn = 0;
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100679 }
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100680}
Victor Stinnerb35be4b2019-03-05 17:37:44 +0100681
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100682
683static _PyInitError
684preconfig_init_allocator(_PyPreConfig *config)
685{
Victor Stinnerb16b4e42019-05-17 15:20:52 +0200686 if (config->allocator == PYMEM_ALLOCATOR_NOT_SET) {
Victor Stinner25d13f32019-03-06 12:51:53 +0100687 /* bpo-34247. The PYTHONMALLOC environment variable has the priority
688 over PYTHONDEV env var and "-X dev" command line option.
689 For example, PYTHONMALLOC=malloc PYTHONDEVMODE=1 sets the memory
690 allocators to "malloc" (and not to "debug"). */
Victor Stinnerb16b4e42019-05-17 15:20:52 +0200691 const char *envvar = _Py_GetEnv(config->use_environment, "PYTHONMALLOC");
692 if (envvar) {
Victor Stinner6d1c4672019-05-20 11:02:00 +0200693 PyMemAllocatorName name;
694 if (_PyMem_GetAllocatorName(envvar, &name) < 0) {
Victor Stinnerb16b4e42019-05-17 15:20:52 +0200695 return _Py_INIT_ERR("PYTHONMALLOC: unknown allocator");
Victor Stinnerb35be4b2019-03-05 17:37:44 +0100696 }
Victor Stinner6d1c4672019-05-20 11:02:00 +0200697 config->allocator = (int)name;
Victor Stinnerb35be4b2019-03-05 17:37:44 +0100698 }
699 }
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100700
Victor Stinnerb16b4e42019-05-17 15:20:52 +0200701 if (config->dev_mode && config->allocator == PYMEM_ALLOCATOR_NOT_SET) {
702 config->allocator = PYMEM_ALLOCATOR_DEBUG;
Victor Stinner25d13f32019-03-06 12:51:53 +0100703 }
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100704 return _Py_INIT_OK();
705}
706
707
708static _PyInitError
Victor Stinner5ac27a52019-03-27 13:40:14 +0100709preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100710{
711 _PyInitError err;
712
Victor Stinner5ac27a52019-03-27 13:40:14 +0100713 err = _PyPreCmdline_Read(cmdline, config);
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100714 if (_Py_INIT_FAILED(err)) {
715 return err;
716 }
717
718 _PyPreCmdline_SetPreConfig(cmdline, config);
719
720 /* legacy_windows_fs_encoding, coerce_c_locale, utf8_mode */
721#ifdef MS_WINDOWS
722 _Py_get_env_flag(config->use_environment,
723 &config->legacy_windows_fs_encoding,
724 "PYTHONLEGACYWINDOWSFSENCODING");
725#endif
726
727 preconfig_init_coerce_c_locale(config);
728
729 err = preconfig_init_utf8_mode(config, cmdline);
730 if (_Py_INIT_FAILED(err)) {
731 return err;
732 }
733
734 /* allocator */
735 err = preconfig_init_allocator(config);
736 if (_Py_INIT_FAILED(err)) {
737 return err;
738 }
Victor Stinner25d13f32019-03-06 12:51:53 +0100739
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100740 assert(config->coerce_c_locale >= 0);
Victor Stinnercab5d072019-05-17 19:01:14 +0200741 assert(config->coerce_c_locale_warn >= 0);
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100742#ifdef MS_WINDOWS
743 assert(config->legacy_windows_fs_encoding >= 0);
744#endif
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100745 assert(config->utf8_mode >= 0);
Victor Stinner6dcb5422019-03-05 02:44:12 +0100746 assert(config->isolated >= 0);
Victor Stinnercad1f742019-03-05 02:01:27 +0100747 assert(config->use_environment >= 0);
Victor Stinnerb35be4b2019-03-05 17:37:44 +0100748 assert(config->dev_mode >= 0);
Victor Stinnercad1f742019-03-05 02:01:27 +0100749
750 return _Py_INIT_OK();
751}
752
753
Victor Stinner4fffd382019-03-06 01:44:31 +0100754/* Read the configuration from:
755
756 - command line arguments
757 - environment variables
758 - Py_xxx global configuration variables
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100759 - the LC_CTYPE locale */
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100760_PyInitError
Victor Stinner5ac27a52019-03-27 13:40:14 +0100761_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100762{
763 _PyInitError err;
764
765 err = _PyRuntime_Initialize();
766 if (_Py_INIT_FAILED(err)) {
767 return err;
768 }
769
Victor Stinnerf29084d2019-03-20 02:20:13 +0100770 _PyPreConfig_GetGlobalConfig(config);
771
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100772 /* Copy LC_CTYPE locale, since it's modified later */
773 const char *loc = setlocale(LC_CTYPE, NULL);
774 if (loc == NULL) {
775 return _Py_INIT_ERR("failed to LC_CTYPE locale");
776 }
777 char *init_ctype_locale = _PyMem_RawStrdup(loc);
778 if (init_ctype_locale == NULL) {
779 return _Py_INIT_NO_MEMORY();
780 }
781
782 /* Save the config to be able to restore it if encodings change */
Victor Stinnercab5d072019-05-17 19:01:14 +0200783 _PyPreConfig save_config;
Victor Stinner6d1c4672019-05-20 11:02:00 +0200784 _PyPreConfig_InitFromPreConfig(&save_config, config);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100785
786 /* Set LC_CTYPE to the user preferred locale */
Victor Stinnerbcfbbd72019-05-17 22:44:16 +0200787 if (config->configure_locale) {
788 _Py_SetLocaleFromEnv(LC_CTYPE);
789 }
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100790
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100791 _PyPreCmdline cmdline = _PyPreCmdline_INIT;
Victor Stinner6a8c3132019-04-05 11:44:04 +0200792 int init_utf8_mode = Py_UTF8Mode;
793#ifdef MS_WINDOWS
794 int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag;
795#endif
796
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100797 if (args) {
798 err = _PyPreCmdline_SetArgv(&cmdline, args);
799 if (_Py_INIT_FAILED(err)) {
800 goto done;
801 }
802 }
803
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100804 int locale_coerced = 0;
805 int loops = 0;
806
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100807 while (1) {
808 int utf8_mode = config->utf8_mode;
809
810 /* Watchdog to prevent an infinite loop */
811 loops++;
812 if (loops == 3) {
813 err = _Py_INIT_ERR("Encoding changed twice while "
814 "reading the configuration");
815 goto done;
816 }
817
818 /* bpo-34207: Py_DecodeLocale() and Py_EncodeLocale() depend
819 on Py_UTF8Mode and Py_LegacyWindowsFSEncodingFlag. */
820 Py_UTF8Mode = config->utf8_mode;
821#ifdef MS_WINDOWS
822 Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding;
823#endif
824
Victor Stinner5ac27a52019-03-27 13:40:14 +0100825 err = preconfig_read(config, &cmdline);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100826 if (_Py_INIT_FAILED(err)) {
827 goto done;
828 }
829
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100830 /* The legacy C locale assumes ASCII as the default text encoding, which
831 * causes problems not only for the CPython runtime, but also other
832 * components like GNU readline.
833 *
834 * Accordingly, when the CLI detects it, it attempts to coerce it to a
835 * more capable UTF-8 based alternative.
836 *
837 * See the documentation of the PYTHONCOERCECLOCALE setting for more
838 * details.
839 */
840 int encoding_changed = 0;
841 if (config->coerce_c_locale && !locale_coerced) {
842 locale_coerced = 1;
843 _Py_CoerceLegacyLocale(0);
844 encoding_changed = 1;
845 }
846
847 if (utf8_mode == -1) {
848 if (config->utf8_mode == 1) {
849 /* UTF-8 Mode enabled */
850 encoding_changed = 1;
851 }
852 }
853 else {
854 if (config->utf8_mode != utf8_mode) {
855 encoding_changed = 1;
856 }
857 }
858
859 if (!encoding_changed) {
860 break;
861 }
862
863 /* Reset the configuration before reading again the configuration,
864 just keep UTF-8 Mode value. */
865 int new_utf8_mode = config->utf8_mode;
866 int new_coerce_c_locale = config->coerce_c_locale;
Victor Stinnerb5947842019-05-18 00:38:16 +0200867 _PyPreConfig_Copy(config, &save_config);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100868 config->utf8_mode = new_utf8_mode;
869 config->coerce_c_locale = new_coerce_c_locale;
870
871 /* The encoding changed: read again the configuration
872 with the new encoding */
873 }
874 err = _Py_INIT_OK();
875
876done:
877 if (init_ctype_locale != NULL) {
878 setlocale(LC_CTYPE, init_ctype_locale);
Victor Stinnerc1834442019-03-18 22:24:28 +0100879 PyMem_RawFree(init_ctype_locale);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100880 }
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100881 Py_UTF8Mode = init_utf8_mode ;
882#ifdef MS_WINDOWS
883 Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding;
884#endif
Victor Stinnerf8ba6f52019-03-26 16:58:50 +0100885 _PyPreCmdline_Clear(&cmdline);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100886 return err;
887}
888
889
Victor Stinner4fffd382019-03-06 01:44:31 +0100890/* Write the pre-configuration:
891
892 - set the memory allocators
893 - set Py_xxx global configuration variables
894 - set the LC_CTYPE locale (coerce C locale, PEP 538) and set the UTF-8 mode
895 (PEP 540)
Victor Stinnerc656e252019-03-06 01:13:43 +0100896
Victor Stinner0f721472019-05-20 17:16:38 +0200897 The applied configuration is written into _PyRuntime.preconfig.
898 If the C locale cannot be coerced, set coerce_c_locale to 0.
Victor Stinner4fffd382019-03-06 01:44:31 +0100899
900 Do nothing if called after Py_Initialize(): ignore the new
901 pre-configuration. */
Victor Stinner7d2ef3e2019-03-06 00:36:56 +0100902_PyInitError
Victor Stinner0f721472019-05-20 17:16:38 +0200903_PyPreConfig_Write(const _PyPreConfig *src_config)
Victor Stinner6dcb5422019-03-05 02:44:12 +0100904{
Victor Stinner0f721472019-05-20 17:16:38 +0200905 _PyPreConfig config;
906 _PyPreConfig_InitFromPreConfig(&config, src_config);
907
Victor Stinner7d2ef3e2019-03-06 00:36:56 +0100908 if (_PyRuntime.core_initialized) {
Victor Stinner4fffd382019-03-06 01:44:31 +0100909 /* bpo-34008: Calling this functions after Py_Initialize() ignores
Victor Stinner7d2ef3e2019-03-06 00:36:56 +0100910 the new configuration. */
Victor Stinnerc656e252019-03-06 01:13:43 +0100911 return _Py_INIT_OK();
Victor Stinner7d2ef3e2019-03-06 00:36:56 +0100912 }
913
Victor Stinner0f721472019-05-20 17:16:38 +0200914 PyMemAllocatorName name = (PyMemAllocatorName)config.allocator;
Victor Stinner6d1c4672019-05-20 11:02:00 +0200915 if (name != PYMEM_ALLOCATOR_NOT_SET) {
916 if (_PyMem_SetupAllocators(name) < 0) {
Victor Stinnerb16b4e42019-05-17 15:20:52 +0200917 return _Py_INIT_ERR("Unknown PYTHONMALLOC allocator");
Victor Stinner7d2ef3e2019-03-06 00:36:56 +0100918 }
919 }
920
Victor Stinner0f721472019-05-20 17:16:38 +0200921 _PyPreConfig_SetGlobalConfig(&config);
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100922
Victor Stinner0f721472019-05-20 17:16:38 +0200923 if (config.configure_locale) {
924 if (config.coerce_c_locale) {
925 if (!_Py_CoerceLegacyLocale(config.coerce_c_locale_warn)) {
926 /* C locale not coerced */
927 config.coerce_c_locale = 0;
928 }
Victor Stinnerbcfbbd72019-05-17 22:44:16 +0200929 }
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100930
Victor Stinnerbcfbbd72019-05-17 22:44:16 +0200931 /* Set LC_CTYPE to the user preferred locale */
932 _Py_SetLocaleFromEnv(LC_CTYPE);
933 }
Victor Stinner7d2ef3e2019-03-06 00:36:56 +0100934
Victor Stinner6d5ee972019-03-23 12:05:43 +0100935 /* Write the new pre-configuration into _PyRuntime */
Victor Stinner0f721472019-05-20 17:16:38 +0200936 _PyPreConfig_Copy(&_PyRuntime.preconfig, &config);
Victor Stinner6d5ee972019-03-23 12:05:43 +0100937
Victor Stinner7d2ef3e2019-03-06 00:36:56 +0100938 return _Py_INIT_OK();
Victor Stinner6dcb5422019-03-05 02:44:12 +0100939}