-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-117398: datetime: Support per-interpreter C-API #117399
Conversation
PyObject *capsule = PyCapsule_New(capi, PyDateTime_CAPSULE_NAME, | ||
datetime_destructor); | ||
set_datetime_capi(st); | ||
PyObject *capsule = PyCapsule_New(&st->capi, PyDateTime_CAPSULE_NAME, NULL); |
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.
Can you explain why do you pass a NULL
as a capsule destructor?
Is there any reason not to have destructor for this capsule?
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.
In this case, the capsule just views a memory allocated and freed by the moduleobject.
cpython/Objects/moduleobject.c
Lines 739 to 740 in bfc57d4
if (m->md_state != NULL) | |
PyMem_Free(m->md_state); |
No futher experiment here. |
On second thought, exposing a module state to a user is dangerous. |
This places C-API structure on a module state, which can be accessed through
PyInterpreterState
or a capsule.Doc: