bpo-34720: Fix test_importlib.test_bad_traverse for AIX by aixtools · Pull Request #9391 · python/cpython
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case originated from c2b0b12, and the new behaviour it's actually attempting to verify is:
- In debug mode, module creation automatically invokes the registered traverse function (for eager detection of problematic traversal function definitions)
- When the traversal function isn't checking correctly for a valid module state, the module creation fails
Actually implementing a valid traversal function here isn't overly important, as the module using it never actually gets created.
So I think @taleinat's right that this bad traversal function can be simplified to avoid the #ifdef, but I think it can be simplified all the way to being just:
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.
*/
assert(m_state != NULL);
Py_VISIT(m_state->integer);
return 0;
That way the case of interest will always fail on the assert() call, and never even attempt to dereference the pointer.