summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-12-02 18:36:57 (GMT)
committerGitHub <noreply@github.com>2022-12-02 18:36:57 (GMT)
commit0547a981ae413248b21a6bb0cb62dda7d236fe45 (patch)
tree284f9abff17da763537e6087b30452a6f4aeadc9 /Python
parentab02262cd0385a2fb5eb8a6ee3cedd4b4bb969f3 (diff)
downloadcpython-0547a981ae413248b21a6bb0cb62dda7d236fe45.zip
cpython-0547a981ae413248b21a6bb0cb62dda7d236fe45.tar.gz
cpython-0547a981ae413248b21a6bb0cb62dda7d236fe45.tar.bz2
gh-99741: Clean Up the _xxsubinterpreters Module (gh-99940)
This cleanup up resolves a few subtle bugs and makes the implementation for multi-phase init much cleaner. https://github.com/python/cpython/issues/99741
Diffstat (limited to 'Python')
-rw-r--r--Python/pystate.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 2554cc2..0fdcdf1 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -1865,7 +1865,7 @@ _PyObject_GetCrossInterpreterData(PyObject *obj, _PyCrossInterpreterData *data)
// Fill in the blanks and validate the result.
data->interp = interp->id;
if (_check_xidata(tstate, data) != 0) {
- _PyCrossInterpreterData_Release(data);
+ (void)_PyCrossInterpreterData_Release(data);
return -1;
}
@@ -1878,8 +1878,8 @@ _release_xidata(void *arg)
_PyCrossInterpreterData *data = (_PyCrossInterpreterData *)arg;
if (data->free != NULL) {
data->free(data->data);
- data->data = NULL;
}
+ data->data = NULL;
Py_CLEAR(data->obj);
}
@@ -1910,27 +1910,29 @@ _call_in_interpreter(struct _gilstate_runtime_state *gilstate,
}
}
-void
+int
_PyCrossInterpreterData_Release(_PyCrossInterpreterData *data)
{
- if (data->data == NULL && data->obj == NULL) {
+ if (data->free == NULL && data->obj == NULL) {
// Nothing to release!
- return;
+ data->data = NULL;
+ return 0;
}
// Switch to the original interpreter.
PyInterpreterState *interp = _PyInterpreterState_LookUpID(data->interp);
if (interp == NULL) {
// The interpreter was already destroyed.
- if (data->free != NULL) {
- // XXX Someone leaked some memory...
- }
- return;
+ // This function shouldn't have been called.
+ // XXX Someone leaked some memory...
+ assert(PyErr_Occurred());
+ return -1;
}
// "Release" the data and/or the object.
struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
_call_in_interpreter(gilstate, interp, _release_xidata, data);
+ return 0;
}
PyObject *