Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-34720: Fix test_importlib.test_bad_traverse for AIX #9391

Merged
merged 6 commits into from
Feb 17, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Modules/_testmultiphase.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,18 @@ bad_traverse(PyObject *self, visitproc visit, void *arg) {
testmultiphase_state *m_state;

m_state = PyModule_GetState(self);

#ifdef _AIX
/*
* AIX does not have a segmentation fault is a NULL pointer is accessed
* In order to mimic other systems that would crash if &(m_state->integer) == NULL
* force a non-zero exit status
*/
if (&(m_state->integer) == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could replace the Py_VISIT(m_state->integer); call on all platforms, thus avoiding the #ifdef?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling Py_VISIT(m_state->integer) is the purpose of this test.

But I wondering if it could be better to just skip the test on AIX in Python code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously, I cannot "decide" what is "cleaner" - letting the test run, but have a modification in the C code the test calls, or having an "SkipIf" in the test (and move the comment to the test, so it is clear why the skip is needed).

I will make the recommended change.

Copy link
Contributor

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:

  1. In debug mode, module creation automatically invokes the registered traverse function (for eager detection of problematic traversal function definitions)
  2. 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.

exit(255);
}
#endif

Py_VISIT(m_state->integer);
return 0;
}
Expand Down