-
Notifications
You must be signed in to change notification settings - Fork 71
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
PEP489 support: multi-phase module initialization, heap based types #307
Conversation
Sort the constant string decls from the ones to be moved to module state.
Include methods for initializing, traversing, and clearing it. Tidy up module method defs w/ constant docstrings.
Use named members for clarity.
Tidy spelings for pointer vars.
- Store created objects in the module state first, then copy them where they are needed (in the future, into the module's __dict__ so that Python can use them). - At this point, the module and the types are still all static. - Use 'PyModule_AddType' as a clearer statement of intent. We are going to be creating the types on the heap later, and so will have their addresses to hand.
- Stores imported values and flag on the module state struct, rather than in global statics.
Drop statics previously used to call 'PyObject_GetAttr'.
The 'PyModule_AddType' API was added in that release.
And remove the static used to call 'PyDict_GetItem'.
Note that those functions are still ignoring that value: this is prep for the next step, where they will use the '_zic_module_state' machinery
Leave forward decls behind FBO type methods. This step is in preparation for using the '_zic_module_state', rather than the global statics.
This is a stopgap, for the statically-initialized module. It will be replaced by 'PyType_GetModuleByDef' once we have multi-phase init and heap types in place.
Instead, look them up via module state versions.
Look it up instead from module state via type with a new helper, '_get_adapter_hooks'.
Move actual explanatory comment for '_get_adapter_hooks' to its impl.
Look it up instead from from module state via the type with a new helper, '_get_specification_base_class'.
At least one bug remains (some interfaces return a 'member_descriptor' for their '__module__').
Drop vestiges of manual 'weakreflist' management. Rename type structs and methods for consistency.
Make them conditional, along with the manual weakreflist managerment, on Python < 3.12, which added the 'Py_TPFLAGS_MANAGED_WEAKREF' flag. Builds and tests pass on 3.11 with this change.
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.
Please don't include me in reviews for C code, I just can't help there.
@dataflake Sorry about that! |
'PyObject_GetAttrString' creates new string objects from 'char*'.
Member descriptor behavior is tricky across Python versions, and across static vs. heap-allocated types. The 'InterfaceBase' base type is a singleton, and has a known/desired "implements name".
Co-authored-by: David Glick <[email protected]>
Co-authored-by: David Glick <[email protected]>
Co-authored-by: David Glick <[email protected]>
Co-authored-by: David Glick <[email protected]>
…pe.interface into tseaver-rework_pep_489
Rather than checking the Python version repeatedly. See: https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_weaklistoffset
4cad888
to
6bb37a5
Compare
…post_pr_307 chore: garden changelog post PR #307
These changes seem to break |
Continuation of PR #301, after moving the branch to this repository.