-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
close, and reopen, to rerun the tests (still showing one red X atm). |
@@ -0,0 +1 @@ | |||
Fix `test_importlib.test_bad_traverse` for AIX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test-only changes usually don't require a NEWS entry. In this case, it should be removed.
(Bedevere will complain, but you may ignore that, and I or another core dev will simply add the "skip news" tag.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove the News, as requested.
Modules/_testmultiphase.c
Outdated
* 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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can make this test more robust in general by replacing the null-pointer dereference with a known-to-be-incorrect assert()
call.
Modules/_testmultiphase.c
Outdated
* 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) { |
There was a problem hiding this comment.
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.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Note that the failing CI check is just looking for a NEWS entry. The entry for this one would go in the "Tests" section, and can be generated with the Blurb CLI or the web service at https://blurb-it.herokuapp.com/ (as per the updated https://devguide.python.org/committing/#what-s-new-and-news-entries section) |
…rectly module creation when the module state has not been created (yet)
I have made the requested changes; please review again. |
Thanks for making the requested changes! @ncoghlan: please review the changes made to this pull request. |
Since I had forgotten why we didn't need to worry about the |
Miss Islington will merge this automatically once CI completes successfully, but after that we'll want to keep an eye on https://buildbot.python.org/all/#/grid?branch=master&tag=stable&tag=nondebug to make sure release mode builds aren't unexpectedly affected by the change. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@aixtools: Status check is done, and it's a success ✅ . |
Fix Modules/_testmultiphase.c so that it exits with non-zero status on AIX just as other systems do (non zero exit status, e.g. as result of a segmentation fault) when a NULL pointer is accessed for data.
https://bugs.python.org/issue34720