[Python-checkins] cpython: Improve verbose reporting of shutdown phase by using the "public" module name

antoine.pitrou python-checkins at python.org
Tue Aug 6 22:50:23 CEST 2013


http://hg.python.org/cpython/rev/41b1a2bbd3b6
changeset:   85056:41b1a2bbd3b6
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Tue Aug 06 22:50:15 2013 +0200
summary:
  Improve verbose reporting of shutdown phase by using the "public" module name

files:
  Python/import.c |  13 +++++++------
  1 files changed, 7 insertions(+), 6 deletions(-)


diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -345,17 +345,17 @@
        for diagnosis messages (in verbose mode), while the weakref helps
        detect those modules which have been held alive. */
     weaklist = PyList_New(0);
+    if (weaklist == NULL)
+        PyErr_Clear();
 
-#define STORE_MODULE_WEAKREF(mod) \
+#define STORE_MODULE_WEAKREF(name, mod) \
     if (weaklist != NULL) { \
-        PyObject *name = PyModule_GetNameObject(mod); \
         PyObject *wr = PyWeakref_NewRef(mod, NULL); \
         if (name && wr) { \
             PyObject *tup = PyTuple_Pack(2, name, wr); \
             PyList_Append(weaklist, tup); \
             Py_XDECREF(tup); \
         } \
-        Py_XDECREF(name); \
         Py_XDECREF(wr); \
         if (PyErr_Occurred()) \
             PyErr_Clear(); \
@@ -368,7 +368,7 @@
         if (PyModule_Check(value)) {
             if (Py_VerboseFlag && PyUnicode_Check(key))
                 PySys_FormatStderr("# cleanup[2] removing %U\n", key, value);
-            STORE_MODULE_WEAKREF(value);
+            STORE_MODULE_WEAKREF(key, value);
             PyDict_SetItem(modules, key, Py_None);
         }
     }
@@ -394,14 +394,15 @@
         n = PyList_GET_SIZE(weaklist);
         for (i = 0; i < n; i++) {
             PyObject *tup = PyList_GET_ITEM(weaklist, i);
+            PyObject *name = PyTuple_GET_ITEM(tup, 0);
             PyObject *mod = PyWeakref_GET_OBJECT(PyTuple_GET_ITEM(tup, 1));
             if (mod == Py_None)
                 continue;
             Py_INCREF(mod);
             assert(PyModule_Check(mod));
-            if (Py_VerboseFlag)
+            if (Py_VerboseFlag && PyUnicode_Check(name))
                 PySys_FormatStderr("# cleanup[3] wiping %U\n",
-                                   PyTuple_GET_ITEM(tup, 0), mod);
+                                   name, mod);
             _PyModule_Clear(mod);
             Py_DECREF(mod);
         }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list