Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-101476: Add _PyType_GetModuleState #101477

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

Merged
merged 11 commits into from
Feb 23, 2023

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Jan 31, 2023

For fast module state access from heap type methods.

For fast module state access from heap type methods.
@erlend-aasland
Copy link
Contributor Author

I'm not sure we should add a NEWS entry for this; this is an internal C API.

Copy link
Contributor

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

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

Nice!

@erlend-aasland
Copy link
Contributor Author

Thanks for the review, Kumar!

Even though I also got thumbs-up from Guido og Steve on Discourse, I'd like to wait for at least one other core dev approval before landing this PR.

@encukou
Copy link
Member

encukou commented Feb 2, 2023

+1 from me, could you just add a comment to clarify the intent, e.g. /* Like PyType_GetModuleState, but skips verification that type is a heap type with an associated module */

@erlend-aasland
Copy link
Contributor Author

+1 from me, could you just add a comment to clarify the intent, e.g. /* Like PyType_GetModuleState, but skips verification that type is a heap type with an associated module */

Thanks for the review, Petr. I'll add the comment right away.

@erlend-aasland erlend-aasland changed the title gh-101476: Add _PyType_GetModuleState gh-101476: Add _PyType_GET_MODULE_STATE Feb 6, 2023
@erlend-aasland erlend-aasland changed the title gh-101476: Add _PyType_GET_MODULE_STATE gh-101476: Add _PyType_GetModuleState Feb 23, 2023
@miss-islington
Copy link
Contributor

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

@miss-islington miss-islington merged commit ccd98a3 into python:main Feb 23, 2023
@erlend-aasland erlend-aasland deleted the pytype-getmodulestate branch February 23, 2023 21:44
@erlend-aasland
Copy link
Contributor Author

Thanks for the reviews, everyone! I'm applying this across the core extension modules. See #102188.

PyHeapTypeObject *et = (PyHeapTypeObject *)type;
assert(et->ht_module);
PyModuleObject *mod = (PyModuleObject *)(et->ht_module);
assert(mod != NULL);
Copy link
Member

Choose a reason for hiding this comment

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

This assertion is the same than assert(et->ht_module);, no? If you only keep one, I suggest keeping assert(mod != NULL); since we use mod below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

... or the first assert could be changed to assert(et != NULL).

JelleZijlstra pushed a commit to JelleZijlstra/cpython that referenced this pull request Sep 10, 2024
For fast module state access from heap type methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add internal API for fast module access from heap type methods
7 participants