diff Objects/moduleobject.c @ 56542:20d09549b82c legacy-trunk

only clear a module's __dict__ if the module is the only one with a reference to it #7140
author Benjamin Peterson <benjamin@python.org>
date Thu, 15 Oct 2009 15:44:46 +0000
parents 52294af4b663
children fd25030223b0
line wrap: on
line diff
--- a/Objects/moduleobject.c	Thu Oct 15 15:39:15 2009 +0000
+++ b/Objects/moduleobject.c	Thu Oct 15 15:44:46 2009 +0000
@@ -175,7 +175,10 @@
 {
 	PyObject_GC_UnTrack(m);
 	if (m->md_dict != NULL) {
-		_PyModule_Clear((PyObject *)m);
+		/* If we are the only ones holding a reference, we can clear
+		   the dictionary. */
+		if (Py_REFCNT(m->md_dict) == 1)
+			_PyModule_Clear((PyObject *)m);
 		Py_DECREF(m->md_dict);
 	}
 	Py_TYPE(m)->tp_free((PyObject *)m);