aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/crossinterp.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2025-04-24 18:25:29 -0600
committerGitHub <noreply@github.com>2025-04-24 18:25:29 -0600
commite54e8288521c1bd5fa496dfa281d034af20d8f42 (patch)
treeb2bfe83090c980b39c2e1097e3d33b59f33e6c05 /Python/crossinterp.c
parentc9f3f5b4ed52d7bed6073ffa39717ece47202558 (diff)
downloadcpython-e54e8288521c1bd5fa496dfa281d034af20d8f42.tar.gz
cpython-e54e8288521c1bd5fa496dfa281d034af20d8f42.zip
gh-132776: Cleanup for XIBufferViewType (gh-132821)
* add notes * rename XIBufferViewObject to xibufferview * move memoryview XIData code to memoryobject.c
Diffstat (limited to 'Python/crossinterp.c')
-rw-r--r--Python/crossinterp.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/Python/crossinterp.c b/Python/crossinterp.c
index 094bbbe54f2..7a19cc3da1f 100644
--- a/Python/crossinterp.c
+++ b/Python/crossinterp.c
@@ -1902,7 +1902,25 @@ _PyXI_Fini(PyInterpreterState *interp)
PyStatus
_PyXI_InitTypes(PyInterpreterState *interp)
{
- if (init_static_exctypes(&_PyXI_GET_STATE(interp)->exceptions, interp) < 0) {
+ if (_Py_IsMainInterpreter(interp)) {
+ _PyXI_global_state_t *global_state = _PyXI_GET_GLOBAL_STATE(interp);
+ if (global_state == NULL) {
+ PyErr_PrintEx(0);
+ return _PyStatus_ERR(
+ "failed to get global cross-interpreter state");
+ }
+ xid_lookup_init(&global_state->data_lookup);
+ }
+
+ _PyXI_state_t *state = _PyXI_GET_STATE(interp);
+ if (state == NULL) {
+ PyErr_PrintEx(0);
+ return _PyStatus_ERR(
+ "failed to get interpreter's cross-interpreter state");
+ }
+ xid_lookup_init(&state->data_lookup);
+
+ if (init_static_exctypes(&state->exceptions, interp) < 0) {
PyErr_PrintEx(0);
return _PyStatus_ERR(
"failed to initialize the cross-interpreter exception types");
@@ -1915,9 +1933,21 @@ _PyXI_InitTypes(PyInterpreterState *interp)
void
_PyXI_FiniTypes(PyInterpreterState *interp)
{
- // We would finalize heap types here too but that leads to ref leaks.
- // Instead, we finalize them in _PyXI_Fini().
- fini_static_exctypes(&_PyXI_GET_STATE(interp)->exceptions, interp);
+ _PyXI_state_t *state = _PyXI_GET_STATE(interp);
+ if (state != NULL) {
+ // We would finalize heap types here too but that leads to ref leaks.
+ // Instead, we finalize them in _PyXI_Fini().
+ fini_static_exctypes(&state->exceptions, interp);
+
+ xid_lookup_fini(&state->data_lookup);
+ }
+
+ if (_Py_IsMainInterpreter(interp)) {
+ _PyXI_global_state_t *global_state = _PyXI_GET_GLOBAL_STATE(interp);
+ if (global_state != NULL) {
+ xid_lookup_fini(&global_state->data_lookup);
+ }
+ }
}