◐ Shell
reader mode source ↗
Skip to content

bpo-35943: PyImport_GetModule() can return partially-initialized module#15057

Merged
brettcannon merged 11 commits into
python:masterfrom
nanjekyejoannah:issue35943
Sep 11, 2019
Merged

bpo-35943: PyImport_GetModule() can return partially-initialized module#15057
brettcannon merged 11 commits into
python:masterfrom
nanjekyejoannah:issue35943

Conversation

@nanjekyejoannah

@nanjekyejoannah nanjekyejoannah commented Jul 31, 2019

Copy link
Copy Markdown
Contributor

Added optimization to prevent PyImport_GetModule() from returning partially-initialized module.

https://bugs.python.org/issue35943

@gnprice gnprice left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

This feels like a somewhat tricky bit of logic that it'd be best not to duplicate.

How about pulling it out from PyImport_ImportModuleLevelObject as its own function? I think I'd take the whole body of the if (mod != NULL ...) block. A good description of what it means might be "ensure initialized", so perhaps spelled import_ensure_initialized.

(I'd make it a static function, so it isn't visible outside this file -- that avoids any need to worry about the API.)

Then this function here only needs to add a couple of lines, invoking that one.

@gnprice gnprice left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

Thanks @nanjekyejoannah for the update! I think this refactor worked out very well.

@nanjekyejoannah

Copy link
Copy Markdown
Contributor Author

@gnprice and @serhiy-storchaka, I have made some changes PTAL.

@gnprice gnprice left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

LGTM! Thanks @nanjekyejoannah for this patch, and for all the updates.

@serhiy-storchaka

Copy link
Copy Markdown
Member

LGTM. @ericsnowcurrently, please take a look.

nanjekyejoannah and others added 2 commits August 3, 2019 12:32
Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
24 hidden items Load more…
@nanjekyejoannah

Copy link
Copy Markdown
Contributor Author

I have made the requested changes @ericsnowcurrently , @serhiy-storchaka , @gnprice PTAL .

@brettcannon

Copy link
Copy Markdown
Member

@nanjekyejoannah FYI you forgot to use the phrase "I have made the requested changes; please review again" to tell the bot to flag this PR as ready for re-review. I'll go ahead and do the label change manually.

@nanjekyejoannah

Copy link
Copy Markdown
Contributor Author

@nanjekyejoannah FYI you forgot to use the phrase "I have made the requested changes; please review again" to tell the bot to flag this PR as ready for re-review. I'll go ahead and do the label change manually.

My bad. Thanks for the reminder.

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@serhiy-storchaka, @ericsnowcurrently: please review the changes made to this pull request.

@vstinner

Copy link
Copy Markdown
Member

I didn't follow this change closely. When I look at the final merged change, it looks simple. But here I see a long discussion, which makes me understand that writing this change was quite difficult. So, well done Joannah for helping to make Python more correct ✨ 🍰 ✨ ;-)

DinoV pushed a commit to DinoV/cpython that referenced this pull request Sep 12, 2019
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @nanjekyejoannah for the PR, and @brettcannon for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @nanjekyejoannah and @brettcannon, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 37c22206981f52ae35c28b39f7530f8438afbfdb 3.7

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.

9 participants