mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #17408: Avoid using an obsolete instance of the copyreg module when the interpreter is shutdown and then started again.
This commit is contained in:
commit
df6931dbbc
4 changed files with 22 additions and 8 deletions
|
@ -7,6 +7,10 @@
|
|||
#include <ctype.h>
|
||||
|
||||
|
||||
/* Cached lookup of the copyreg module, for faster __reduce__ calls */
|
||||
|
||||
static PyObject *cached_copyreg_module = NULL;
|
||||
|
||||
/* Support type attribute cache */
|
||||
|
||||
/* The cache can keep references to the names alive for longer than
|
||||
|
@ -68,6 +72,15 @@ PyType_ClearCache(void)
|
|||
return cur_version_tag;
|
||||
}
|
||||
|
||||
void
|
||||
_PyType_Fini(void)
|
||||
{
|
||||
PyType_ClearCache();
|
||||
/* Need to forget our obsolete instance of the copyreg module at
|
||||
* interpreter shutdown (issue #17408). */
|
||||
Py_CLEAR(cached_copyreg_module);
|
||||
}
|
||||
|
||||
void
|
||||
PyType_Modified(PyTypeObject *type)
|
||||
{
|
||||
|
@ -3339,19 +3352,18 @@ static PyObject *
|
|||
import_copyreg(void)
|
||||
{
|
||||
static PyObject *copyreg_str;
|
||||
static PyObject *mod_copyreg = NULL;
|
||||
|
||||
if (!copyreg_str) {
|
||||
copyreg_str = PyUnicode_InternFromString("copyreg");
|
||||
if (copyreg_str == NULL)
|
||||
return NULL;
|
||||
}
|
||||
if (!mod_copyreg) {
|
||||
mod_copyreg = PyImport_Import(copyreg_str);
|
||||
if (!cached_copyreg_module) {
|
||||
cached_copyreg_module = PyImport_Import(copyreg_str);
|
||||
}
|
||||
|
||||
Py_XINCREF(mod_copyreg);
|
||||
return mod_copyreg;
|
||||
Py_XINCREF(cached_copyreg_module);
|
||||
return cached_copyreg_module;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue