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
gh-94401: Remove unneeded overlapped module state #94403
gh-94401: Remove unneeded overlapped module state #94403
Conversation
erlend-aasland
commented
Jun 29, 2022
•
edited by bedevere-bot
edited by bedevere-bot
- Issue: gh-94401
@@ -2045,14 +2011,15 @@ overlapped_exec(PyObject *module) | |||
return -1; | |||
} | |||
|
|||
OverlappedState *st = overlapped_get_state(module); | |||
st->overlapped_type = (PyTypeObject *)PyType_FromModuleAndSpec( | |||
PyTypeObject *overlapped_type = (PyTypeObject *)PyType_FromModuleAndSpec( |
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.
Is PyType_FromModuleAndSpec
the correct API to retrieve a type object from a module by spec? It calls PyType_FromMetaclass
, which does a lot of extra work.
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.
All the PyType_From*
APIs call PyType_FromMetaclass
. The recent changes to the PyType_From*
APIs should not result in a lot of extra work. If that is the case, PyType_FromMetaclass
should be optimised, if possible.
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 was under the assumption that the PyType_From*
APIs are used to create a new type object from a spec, not fetch an existing type. It may even leak memory . PyType_FromMetaclass
calls PyMem_Malloc
and eventually assigns it to type->tp_name
eventually without a check.
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.
Each call allocates a whole new type on the heap memory.
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.
IMO, if there are issues with PEP-489 and the PyType_From*
APIs they should be addressed in a separate issue and discussed there. Suggesting to mark this conversation as resolved and continue this discussion in an appropriate issue if needed.
Thanks for the review! |