summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-05-04 18:46:19 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-05-04 18:46:19 (GMT)
commitdf6931dbbcf3d0a33f5469e63c9944577a7c7382 (patch)
tree20dc1c75735e64dabfe13c3f9eedb22da1a921eb /Objects
parent609a56f788293585039e78a108f8c3aff8ac245d (diff)
parent957a23b0883c1d92f4d5c5de2459319615a8ed34 (diff)
downloadcpython-df6931dbbcf3d0a33f5469e63c9944577a7c7382.zip
cpython-df6931dbbcf3d0a33f5469e63c9944577a7c7382.tar.gz
cpython-df6931dbbcf3d0a33f5469e63c9944577a7c7382.tar.bz2
Issue #17408: Avoid using an obsolete instance of the copyreg module when the interpreter is shutdown and then started again.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 5093452..aa67af8 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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
@@ -69,6 +73,15 @@ PyType_ClearCache(void)
}
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)
{
/* Invalidate any cached data for the specified type and all
@@ -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 *