8000 Revert "bpo-35239: _PySys_EndInit() copies module_search_path (GH-105… · python/cpython@a519411 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 script crossorigin="anonymous" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_remote-form_dist_index_js-node_modules_delegated-events_dist_inde-94fd67-99b04cc350b5.js" defer="defer">

Commit a519411

Browse files
authored
Revert "bpo-35239: _PySys_EndInit() copies module_search_path (GH-10532)" (GH-10660)
This reverts commit d2be9a5.
1 parent 18f3327 commit a519411

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

Lib/test/test_embed.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
301301
}
302302

303303
# main config
304+
UNTESTED_MAIN_CONFIG = (
305+
# FIXME: untested main configuration variables
306+
'module_search_path',
307+
)
304308
COPY_MAIN_CONFIG = (
305309
# Copy core config to main config for expected values
306310
'argv',
@@ -311,8 +315,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
311315
'install_signal_handlers',
312316
'prefix',
313317
'warnoptions',
314-
# xoptions is created from core_config in check_main_config().
315-
# 'module_search_paths' is copied to 'module_search_path'.
318+
# xoptions is created from core_config in check_main_config()
316319
)
317320

318321
# global config
@@ -386,10 +389,12 @@ def check_main_config(self, config):
386389
main_config = config['main_config']
387390

388391
# main config
392+
for key in self.UNTESTED_MAIN_CONFIG:
393+
del main_config[key]
394+
389395
expected_main = {}
390396
for key in self.COPY_MAIN_CONFIG:
391397
expected_main[key] = core_config[key]
392-
expected_main['module_search_path'] = core_config['module_search_paths']
393398
expected_main['xoptions'] = self.main_xoptions(core_config['xoptions'])
394399
self.assertEqual(main_config, expected_main)
395400

Python/pylifecycle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,8 @@ _Py_InitializeMainInterpreter(PyInterpreterState *interp,
967967
}
968968

969969
/* Initialize warnings. */
970-
PyObject *warnoptions = PySys_GetObject("warnoptions");
971-
if (warnoptions != NULL && PyList_Size(warnoptions) > 0)
970+
if (interp->config.warnoptions != NULL &&
971+
PyList_Size(interp->config.warnoptions) > 0)
972972
{
973973
PyObject *warnings_module = PyImport_ImportModule("warnings");
974974
if (warnings_module == NULL) {

Python/sysmodule.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,20 +2464,7 @@ _PySys_EndInit(PyObject *sysdict, _PyMainInterpreterConfig *config)
24642464
assert(config->exec_prefix != NULL);
24652465
assert(config->base_exec_prefix != NULL);
24662466

2467-
#define COPY_LIST(KEY, ATTR) \
2468-
do { \
2469-
assert(PyList_Check(config->ATTR)); \
2470-
PyObject *list = PyList_GetSlice(config->ATTR, \
2471-
0, PyList_GET_SIZE(config->ATTR)); \
2472-
if (list == NULL) { \
2473-
return -1; \
2474-
} \
2475-
SET_SYS_FROM_STRING_BORROW(KEY, list); \
2476-
Py_DECREF(list); \
2477-
} while (0)
2478-
2479-
COPY_LIST("path", module_search_path);
2480-
2467+
SET_SYS_FROM_STRING_BORROW("path", config->module_search_path);
24812468
SET_SYS_FROM_STRING_BORROW("executable", config->executable);
24822469
SET_SYS_FROM_STRING_BORROW("prefix", config->prefix);
24832470
SET_SYS_FROM_STRING_BORROW("base_prefix", config->base_prefix);
@@ -2488,19 +2475,12 @@ _PySys_EndInit(PyObject *sysdict, _PyMainInterpreterConfig *config)
24882475
SET_SYS_FROM_STRING_BORROW("argv", config->argv);
24892476
}
24902477
if (config->warnoptions != NULL) {
2491-
COPY_LIST("warnoptions", warnoptions);
2478+
SET_SYS_FROM_STRING_BORROW("warnoptions", config->warnoptions);
24922479
}
24932480
if (config->xoptions != NULL) {
2494-
PyObject *dict = PyDict_Copy(config->xoptions);
2495-
if (dict == NULL) {
2496-
return -1;
2497-
}
2498-
SET_SYS_FROM_STRING_BORROW("_xoptions", dict);
2499-
Py_DECREF(dict);
2481+
SET_SYS_FROM_STRING_BORROW("_xoptions", config->xoptions);
25002482
}
25012483

2502-
#undef COPY_LIST
2503-
25042484
/* Set flags to their final values */
25052485
SET_SYS_FROM_STRING_INT_RESULT("flags", make_flags());
25062486
/* prevent user from creating new instances */

0 commit comments

Comments
 (0)
0