cpython: 96d1207d33d0 (original) (raw)
Mercurial > cpython
changeset 87652:96d1207d33d0 3.3
Issue #19088: Fix incorrect caching of the copyreg module. This fix does not cause any degradation in performance. [#19088]
Alexandre Vassalotti alexandre@peadrop.com | |
---|---|
date | Sat, 30 Nov 2013 00:53:09 -0800 |
parents | 63f3e8670fa6 |
children | 1ceb6f84b617 b92f9eaedb76 |
files | Misc/NEWS Objects/typeobject.c |
diffstat | 2 files changed, 26 insertions(+), 20 deletions(-)[+] [-] Misc/NEWS 3 Objects/typeobject.c 43 |
line wrap: on
line diff
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -18,6 +18,9 @@ Core and Builtins Library ------- +- Issue #19088: Fixed incorrect caching of the copyreg module in
- Issue #11508: Fixed uuid.getnode() and uuid.uuid1() on environment with virtual interface. Original patch by Kent Frazier.
--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -7,10 +7,6 @@ #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 @@ -73,9 +69,6 @@ void _PyType_Fini(void) { PyType_ClearCache();
- /* Need to forget our obsolete instance of the copyreg module at
* interpreter shutdown (issue #17408). */[](#l2.19)
- Py_CLEAR(cached_copyreg_module);
} void @@ -3348,19 +3341,29 @@ static PyGetSetDef object_getsets[] = { static PyObject * import_copyreg(void) {
- if (!copyreg_str) {
copyreg_str = PyUnicode_InternFromString("copyreg");[](#l2.31)
if (copyreg_str == NULL)[](#l2.32)
return NULL;[](#l2.33)
- }
- if (!cached_copyreg_module) {
cached_copyreg_module = PyImport_Import(copyreg_str);[](#l2.36)
- }
- PyObject *copyreg_str;
- PyObject *copyreg_module;
- PyInterpreterState *interp = PyThreadState_GET()->interp;
- _Py_IDENTIFIER(copyreg);
- copyreg_str = _PyUnicode_FromId(&PyId_copyreg);
- if (copyreg_str == NULL) {
return NULL;[](#l2.48)
- }
- /* Try to fetch cached copy of copyreg from sys.modules first in an
attempt to avoid the import overhead. Previously this was implemented[](#l2.51)
by storing a reference to the cached module in a static variable, but[](#l2.52)
this broke when multiple embeded interpreters were in use (see issue[](#l2.53)
#17408 and #19088). */[](#l2.54)
- copyreg_module = PyDict_GetItemWithError(interp->modules, copyreg_str);
- if (copyreg_module != NULL) {
Py_INCREF(copyreg_module);[](#l2.57)
return copyreg_module;[](#l2.58)
- }
- if (PyErr_Occurred()) {
return NULL;[](#l2.61)
- }
- return PyImport_Import(copyreg_str);