diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-03-14 14:01:35 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 14:01:35 -0600 |
commit | cdb21ba74d933e262bc1696b6ce78b50cb5a4443 (patch) | |
tree | bfdf1ff0a564d9b7bc3f7288f115ccd3bc9c3d12 /Python/sysmodule.c | |
parent | 80abd62647b2a36947a11a6a8e395061be6f0c61 (diff) | |
download | cpython-git-cdb21ba74d933e262bc1696b6ce78b50cb5a4443.tar.gz |
gh-102660: Handle m_copy Specially for the sys and builtins Modules (gh-102661)
It doesn't make sense to use multi-phase init for these modules. Using a per-interpreter "m_copy" (instead of PyModuleDef.m_base.m_copy) makes this work okay. (This came up while working on gh-101660.)
Note that we might instead end up disallowing re-load for sys/builtins since they are so special.
https://github.com/python/cpython/issues/102660
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 764fb70bae..fc0550266b 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3425,12 +3425,20 @@ _PySys_Create(PyThreadState *tstate, PyObject **sysmod_p) return _PyStatus_ERR("failed to create a module object"); } + /* m_copy of Py_None means it is copied some other way. */ + sysmodule.m_base.m_copy = Py_NewRef(Py_None); + PyObject *sysdict = PyModule_GetDict(sysmod); if (sysdict == NULL) { goto error; } interp->sysdict = Py_NewRef(sysdict); + interp->sysdict_copy = PyDict_Copy(sysdict); + if (interp->sysdict_copy == NULL) { + goto error; + } + if (PyDict_SetItemString(sysdict, "modules", modules) < 0) { goto error; } |