gh-117398: datetime: Support per-interpreter C-API by neonene · Pull Request #117399 · python/cpython
Closed
wants to merge 7 commits into
Conversation
This places C-API structure on a module state, which can be accessed through PyInterpreterState or a capsule.
For modules using multi-phase initialization, e.g. PyModule_FromDefAndSpec(),
a separate module object is created and initialized for each interpreter.
| PyObject *capsule = PyCapsule_New(capi, PyDateTime_CAPSULE_NAME, | ||
| datetime_destructor); | ||
| set_datetime_capi(st); | ||
| PyObject *capsule = PyCapsule_New(&st->capi, PyDateTime_CAPSULE_NAME, NULL); |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why do you pass a NULL as a capsule destructor?
Is there any reason not to have destructor for this capsule?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, the capsule just views a memory allocated and freed by the moduleobject.
| if (m->md_state != NULL) | |
| PyMem_Free(m->md_state); |
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