[Python-checkins] bpo-34720: Fix test_importlib.test_bad_traverse for AIX (GH-14238)

Ned Deily webhook-mailer at python.org
Tue Sep 10 09:30:22 EDT 2019


https://github.com/python/cpython/commit/61f34f9f63aab7503420603627ad5bd8902d904b
commit: 61f34f9f63aab7503420603627ad5bd8902d904b
branch: 3.7
author: Michael Felt <aixtools at users.noreply.github.com>
committer: Ned Deily <nad at python.org>
date: 2019-09-10T14:30:18+01:00
summary:

bpo-34720: Fix test_importlib.test_bad_traverse for AIX  (GH-14238)

files:
A Misc/NEWS.d/next/Tests/2018-12-26-12-31-16.bpo-34720.T268vz.rst
M Modules/_testmultiphase.c

diff --git a/Misc/NEWS.d/next/Tests/2018-12-26-12-31-16.bpo-34720.T268vz.rst b/Misc/NEWS.d/next/Tests/2018-12-26-12-31-16.bpo-34720.T268vz.rst
new file mode 100644
index 000000000000..fc490285db3c
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2018-12-26-12-31-16.bpo-34720.T268vz.rst
@@ -0,0 +1,2 @@
+Assert m_state != NULL to mimic GC traversal functions that do not correctly
+handle module creation when the module state has not been created.
diff --git a/Modules/_testmultiphase.c b/Modules/_testmultiphase.c
index 5776df7d765d..c6dfc2f01dc0 100644
--- a/Modules/_testmultiphase.c
+++ b/Modules/_testmultiphase.c
@@ -624,6 +624,14 @@ bad_traverse(PyObject *self, visitproc visit, void *arg) {
     testmultiphase_state *m_state;
 
     m_state = PyModule_GetState(self);
+
+    /* The following assertion mimics any traversal function that doesn't correctly handle
+     * the case during module creation where the module state hasn't been created yet.
+     *
+     * The check that it is used to test only runs in debug mode, so it is OK that the
+     * assert() will get compiled out in fully optimised release builds.
+     */
+    assert(m_state != NULL);
     Py_VISIT(m_state->integer);
     return 0;
 }



More information about the Python-checkins mailing list