FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-117398: datetime: Support per-interpreter C-API by neonene · Pull Request #117399 · python/cpython · GitHub

/ cpython Public

gh-117398: datetime: Support per-interpreter C-API - #117399

Closed
neonene wants to merge 7 commits into
python:mainfrom
neonene:dtstate
Closed

gh-117398: datetime: Support per-interpreter C-API#117399
neonene wants to merge 7 commits into
python:mainfrom
neonene:dtstate

Conversation

neonene commented Mar 31, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

This places C-API structure on a module state, which can be accessed through PyInterpreterState or a capsule.

Doc:

For modules using multi-phase initialization, e.g. PyModule_FromDefAndSpec(),
a separate module object is created and initialized for each interpreter.

neonene marked this pull request as draft March 31, 2024 04:33
Comment thread Modules/_datetimemodule.c
PyObject *capsule = PyCapsule_New(capi, PyDateTime_CAPSULE_NAME,
datetime_destructor);
set_datetime_capi(st);
PyObject *capsule = PyCapsule_New(&st->capi, PyDateTime_CAPSULE_NAME, NULL);

Eclips4 Mar 31, 2024
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you explain why do you pass a NULL as a capsule destructor?
Is there any reason not to have destructor for this capsule?

neonene Mar 31, 2024
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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);

Comment thread Modules/_datetimemodule.c Outdated

neonene commented Mar 31, 2024

Copy link
Copy Markdown
Contributor Author

No futher experiment here.

neonene closed this Mar 31, 2024

neonene commented Apr 2, 2024

Copy link
Copy Markdown
Contributor Author

On second thought, exposing a module state to a user is dangerous.

neonene deleted the dtstate branch April 2, 2024 12:56
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL