summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-04-24 21:48:05 (GMT)
committerGitHub <noreply@github.com>2023-04-24 21:48:05 (GMT)
commit19e4f757de8c7cf2b4b9b4cbb32e376d0e50d2d4 (patch)
treec845e14c1ed7118c57c5093a11205f88624ea63d /Python/import.c
parentae25855045e8f19f4715c9b2c02cbcd81e7f6f95 (diff)
downloadcpython-19e4f757de8c7cf2b4b9b4cbb32e376d0e50d2d4.zip
cpython-19e4f757de8c7cf2b4b9b4cbb32e376d0e50d2d4.tar.gz
cpython-19e4f757de8c7cf2b4b9b4cbb32e376d0e50d2d4.tar.bz2
gh-100227: Only Use deepfreeze for the Main Interpreter (gh-103794)
Deep-frozen code objects are cannot be shared (currently) by interpreters, due to how adaptive specialization can modify the bytecodes. We work around this by only using the deep-frozen objects in the main interpreter. This does incur a performance penalty for subinterpreters, which we may be able to resolve later.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Python/import.c b/Python/import.c
index 1db5b93..df57780 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2021,9 +2021,9 @@ find_frozen(PyObject *nameobj, struct frozen_info *info)
}
static PyObject *
-unmarshal_frozen_code(struct frozen_info *info)
+unmarshal_frozen_code(PyInterpreterState *interp, struct frozen_info *info)
{
- if (info->get_code) {
+ if (info->get_code && _Py_IsMainInterpreter(interp)) {
PyObject *code = info->get_code();
assert(code != NULL);
return code;
@@ -2070,7 +2070,7 @@ PyImport_ImportFrozenModuleObject(PyObject *name)
set_frozen_error(status, name);
return -1;
}
- co = unmarshal_frozen_code(&info);
+ co = unmarshal_frozen_code(tstate->interp, &info);
if (co == NULL) {
return -1;
}
@@ -3528,7 +3528,8 @@ _imp_get_frozen_object_impl(PyObject *module, PyObject *name,
return NULL;
}
- PyObject *codeobj = unmarshal_frozen_code(&info);
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyObject *codeobj = unmarshal_frozen_code(interp, &info);
if (dataobj != Py_None) {
PyBuffer_Release(&buf);
}