PEP489 support: multi-phase module initialization, heap based types - #307
Merged
Merged
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.
dataflake
reviewed
May 27, 2024
dataflake
left a comment
Member
There was a problem hiding this comment.
Please don't include me in reviews for C code, I just can't help there.
Member
Author
|
@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".
davisagli
reviewed
Jun 19, 2024
Co-authored-by: David Glick <david@glicksoftware.com>
Co-authored-by: David Glick <david@glicksoftware.com>
Co-authored-by: David Glick <david@glicksoftware.com>
Co-authored-by: David Glick <david@glicksoftware.com>
…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
tseaver
force-pushed
the
tseaver-rework_pep_489
branch
from
August 1, 2024 17:35
4cad888 to
6bb37a5
Compare
davisagli
approved these changes
Aug 4, 2024
tseaver
added a commit
that referenced
this pull request
Aug 5, 2024
tseaver
added a commit
that referenced
this pull request
Aug 5, 2024
…post_pr_307 chore: garden changelog post PR #307
Member
|
These changes seem to break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuation of PR #301, after moving the branch to this repository.