Skip to content
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

Merged
merged 44 commits into from
Aug 5, 2024

Conversation

tseaver
Copy link
Member

@tseaver tseaver commented May 27, 2024

Continuation of PR #301, after moving the branch to this repository.

tseaver added 30 commits May 22, 2024 23:57
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.
- 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.
Copy link
Member

@dataflake dataflake left a 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.

@tseaver
Copy link
Member Author

tseaver commented May 28, 2024

@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".
src/zope/interface/_zope_interface_coptimizations.c Outdated Show resolved Hide resolved
src/zope/interface/_zope_interface_coptimizations.c Outdated Show resolved Hide resolved
src/zope/interface/_zope_interface_coptimizations.c Outdated Show resolved Hide resolved
src/zope/interface/_zope_interface_coptimizations.c Outdated Show resolved Hide resolved
src/zope/interface/_zope_interface_coptimizations.c Outdated Show resolved Hide resolved
src/zope/interface/_zope_interface_coptimizations.c Outdated Show resolved Hide resolved
src/zope/interface/_zope_interface_coptimizations.c Outdated Show resolved Hide resolved
src/zope/interface/_zope_interface_coptimizations.c Outdated Show resolved Hide resolved
src/zope/interface/_zope_interface_coptimizations.c Outdated Show resolved Hide resolved
@tseaver tseaver merged commit 8e90a23 into master Aug 5, 2024
54 checks passed
@tseaver tseaver deleted the tseaver-rework_pep_489 branch August 5, 2024 14:12
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
@icemac
Copy link
Member

icemac commented Aug 6, 2024

These changes seem to break zope.proxy, see https://github.com/zopefoundation/z3c.pt/actions/runs/10110195498/job/28389675912?pr=30 – I can also create a new ticket for this issue if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants