Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
bpo-1635741: Port _locale extension module to multiphase initialization (PEP 489)#18358
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
Conversation
shihai1991 commented Feb 5, 2020 • edited by bedevere-bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-bot
Uh oh!
There was an error while loading. Please reload this page.
codecovbot commented Feb 5, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Codecov Report
@@ Coverage Diff @@## master #18358 +/- ## ========================================== - Coverage 82.11% 82.07% -0.05% ========================================== Files 1955 1955 Lines 588624 584187 -4437 Branches 44406 44464 +58 ========================================== - Hits 483366 479456 -3910 + Misses 95615 95110 -505 + Partials 9643 9621 -22
Continue to review full report at Codecov.
|
Modules/_localemodule.c Outdated
| state=PyModule_GetState(self); | ||
| if (state==NULL){ | ||
| returnNULL; | ||
| } |
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 don't think that it's worth it to check for error: this function cannot fail, self is always a module object.
I would prefer a function like:
static inline _locale_state* get_locale_state(PyObject *mod){void *state = PyModule_GetState(mod); assert(state != NULL); return (_locale_state*)state} And then use:
PyErr_SetString(get_locale_state(self)->Error, "invalid locale category"); 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.
Make sense, I update this PR.
Do we need add a global macros of get_state?
I found some other extension modules use local macro do this behavior too. such as: https://github.com/python/cpython/blob/master/Modules/_hashopenssl.c#L55
Thanks a million, victor. You helpe me merge much PRs today ;)
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.
A static inline function is a bit better than a macro.
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.
Sure, I remember victor have explained in other bpo/PR(oh, I forgot which one is). It's easy for debuging and something else.
I will try to add this inline function in free time.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
shihai1991 commented Feb 18, 2020
Looks CI gate of |
Uh oh!
There was an error while loading. Please reload this page.
bedevere-bot commented Feb 18, 2020
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 |
shihai1991 commented Feb 18, 2020
I remove assert operation in some error info like: and the trace back: |
shihai1991 commented Feb 18, 2020
I have made the requested changes; please review again. |
bedevere-bot commented Feb 18, 2020
Thanks for making the requested changes! @encukou: please review the changes made to this pull request. |
encukou commented Feb 25, 2020
The assertion was good! If you remove it, you should add I hope you don't mind me pushing to this branch directly – I already made the change and ran tests on it locally. |
shihai1991 commented Feb 25, 2020
petr, pls go ahead ;) |
shihai1991 commented Feb 25, 2020
Hi, petr. Do you have wins env to test this PR? #18608. |
encukou left a comment
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.
Looks good to me. I plan to merge when I have time to watch the buildbots afterwards.
| locale_traverse(PyObject*m, visitprocvisit, void*arg) | ||
| { | ||
| _locale_state*state= (_locale_state*)PyModule_GetState(m); | ||
| if (state){ |
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.
As I asked on your two other PRs (binascii, audioop), I don't think that state can be NULL here. Same remark in locale_clear().
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.
Hi, victor. There have some description info about traverse slot in https://docs.python.org/3/c-api/module.html?highlight=pymoduledef#c.PyModuleDef:
A traversal function to call during GC traversal of the module object, or NULL if not needed. This function may be called before module state is allocated (PyModule_GetState() may return NULL), and before the Py_mod_exec function is executed. So this behavior is a planned behavior, isn't it?
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.
Let's discuss that in https://bugs.python.org/issue39824
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.
The discussion won't be over before Nick Coghlan is satisfied (and that's a good thing!)
Meanwhile, this PR is correct according to current behavior and documentation. I don't think bpo-39824 should block it.
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.
Alright. I expected https://bugs.python.org/issue39824 to be resolved quick, but I'm ok to merge @shihai1991 PR's first, and revisit the code later if we decided that m_clear/m_free cannot be called with a NULL state.
https://bugs.python.org/issue1635741