Skip to content

Commit 839184f

Browse files
authored
bpo-43268: local_clear() uses _PyInterpreterState_GET() (GH-24583)
Cleanup also the code.
1 parent bcb094b commit 839184f

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

Modules/_threadmodule.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -828,27 +828,26 @@ local_traverse(localobject *self, visitproc visit, void *arg)
828828
static int
829829
local_clear(localobject *self)
830830
{
831-
PyThreadState *tstate;
832831
Py_CLEAR(self->args);
833832
Py_CLEAR(self->kw);
834833
Py_CLEAR(self->dummies);
835834
Py_CLEAR(self->wr_callback);
836835
/* Remove all strong references to dummies from the thread states */
837-
if (self->key
838-
&& (tstate = PyThreadState_Get())
839-
&& tstate->interp) {
840-
for(tstate = PyInterpreterState_ThreadHead(tstate->interp);
841-
tstate;
842-
tstate = PyThreadState_Next(tstate))
843-
if (tstate->dict) {
844-
PyObject *v = _PyDict_Pop(tstate->dict, self->key, Py_None);
845-
if (v == NULL) {
846-
PyErr_Clear();
847-
}
848-
else {
849-
Py_DECREF(v);
850-
}
836+
if (self->key) {
837+
PyInterpreterState *interp = _PyInterpreterState_GET();
838+
PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
839+
for(; tstate; tstate = PyThreadState_Next(tstate)) {
840+
if (tstate->dict == NULL) {
841+
continue;
851842
}
843+
PyObject *v = _PyDict_Pop(tstate->dict, self->key, Py_None);
844+
if (v != NULL) {
845+
Py_DECREF(v);
846+
}
847+
else {
848+
PyErr_Clear();
849+
}
850+
}
852851
}
853852
return 0;
854853
}

0 commit comments

Comments
 (0)