[Python-checkins] no-issue: Add assertion to PyModule_GetName for understanding (GH-32236)

corona10 webhook-mailer at python.org
Fri Apr 1 20:56:35 EDT 2022


https://github.com/python/cpython/commit/b183f486493e7e4c332566392ef18c6b346a6561
commit: b183f486493e7e4c332566392ef18c6b346a6561
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2022-04-02T09:56:30+09:00
summary:

no-issue: Add assertion to PyModule_GetName for understanding (GH-32236)

files:
M Objects/moduleobject.c

diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 738b262288bcd..dba20a0b36463 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -510,8 +510,10 @@ const char *
 PyModule_GetName(PyObject *m)
 {
     PyObject *name = PyModule_GetNameObject(m);
-    if (name == NULL)
+    if (name == NULL) {
         return NULL;
+    }
+    assert(Py_REFCNT(name) >= 2);
     Py_DECREF(name);   /* module dict has still a reference */
     return PyUnicode_AsUTF8(name);
 }



More information about the Python-checkins mailing list