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

Conversation

aixtools
Copy link
Contributor

@aixtools aixtools commented Sep 18, 2018

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

@aixtools
Copy link
Contributor Author

close, and reopen, to rerun the tests (still showing one red X atm).

@aixtools aixtools closed this Oct 14, 2018
@aixtools aixtools reopened this Oct 14, 2018
@@ -0,0 +1 @@
Fix `test_importlib.test_bad_traverse` for AIX
Copy link
Contributor

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.)

Copy link
Contributor Author

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.

* 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.

Copy link
Contributor

@ncoghlan ncoghlan left a 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.

* 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.

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.

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ncoghlan
Copy link
Contributor

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)
@aixtools
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@ncoghlan: please review the changes made to this pull request.

@ncoghlan
Copy link
Contributor

Since I had forgotten why we didn't need to worry about the assert() getting compiled out in fully optimised release builds, I modified the block comment in the test traversal function to explain the details of that.

@ncoghlan
Copy link
Contributor

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.

@miss-islington

This comment has been minimized.

@miss-islington

This comment has been minimized.

@miss-islington
Copy link
Contributor

@aixtools: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit 1bf8845 into python:master Feb 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants