gh-140550: allow slots that repeat information from PyModuleDef#144340
gh-140550: allow slots that repeat information from PyModuleDef#144340encukou wants to merge 4 commits intopython:mainfrom
Conversation
When integrating slots-based module creation is with the inittab, which currently requires PyModuleDef, it would be convenient to reuse the the same slots array for the MethodDef. Allow slots that match what's already present in the PyModuleDef.
|
I can confirm that with this PR the PyO3 tests all pass on my |
| members, the values must match. | ||
| For example, if you use :c:macro:`Py_mod_name` in :c:member:`!m_slots`, | ||
| :c:member:`PyModuleDef.m_name` must be set to the same pointer | ||
| (not just an equal string). |
There was a problem hiding this comment.
"set to the same pointer" is a strong constraint which is difficult to reach in C. For example, your test copies the string "test_capi/parrot", and rely on the compiler to merge equal strings to use the same pointer. Would it be possible to use strcmp() for the name and the docstring?
There was a problem hiding this comment.
Oh, thanks for the catch; I meant to fix that.
The issue is, where do you draw the line? Do m_methods & Py_mod_methods also need to be only “equal”? And the names of the methods contained there?
I'd rather keep this simple. After all, it's only a workaround.
From feedback on the discussion thread:
When integrating slots-based module creation is with the inittab, which currently requires PyModuleDef, it would be convenient to reuse the the same slots array for the MethodDef.
This PR allows slots that match what's already present in the PyModuleDef.
cc @ngoldbaum
📚 Documentation preview 📚: https://cpython-previews--144340.org.readthedocs.build/