diff options
author | Victor Stinner <vstinner@python.org> | 2021-02-19 14:51:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-19 14:51:36 (GMT) |
commit | 839184f85cb2d2ad514fff9b431733d1c9607533 (patch) | |
tree | e9ac4073f57a74645203b447cefaca3e35a7dda8 | |
parent | bcb094b41f7fe4dd1686c50891d85632fcf0d481 (diff) | |
download | cpython-839184f85cb2d2ad514fff9b431733d1c9607533.zip cpython-839184f85cb2d2ad514fff9b431733d1c9607533.tar.gz cpython-839184f85cb2d2ad514fff9b431733d1c9607533.tar.bz2 |
bpo-43268: local_clear() uses _PyInterpreterState_GET() (GH-24583)
Cleanup also the code.
-rw-r--r-- | Modules/_threadmodule.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 9b87577..f6217e6 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -828,27 +828,26 @@ local_traverse(localobject *self, visitproc visit, void *arg) static int local_clear(localobject *self) { - PyThreadState *tstate; Py_CLEAR(self->args); Py_CLEAR(self->kw); Py_CLEAR(self->dummies); Py_CLEAR(self->wr_callback); /* Remove all strong references to dummies from the thread states */ - if (self->key - && (tstate = PyThreadState_Get()) - && tstate->interp) { - for(tstate = PyInterpreterState_ThreadHead(tstate->interp); - tstate; - tstate = PyThreadState_Next(tstate)) - if (tstate->dict) { - PyObject *v = _PyDict_Pop(tstate->dict, self->key, Py_None); - if (v == NULL) { - PyErr_Clear(); - } - else { - Py_DECREF(v); - } + if (self->key) { + PyInterpreterState *interp = _PyInterpreterState_GET(); + PyThreadState *tstate = PyInterpreterState_ThreadHead(interp); + for(; tstate; tstate = PyThreadState_Next(tstate)) { + if (tstate->dict == NULL) { + continue; } + PyObject *v = _PyDict_Pop(tstate->dict, self->key, Py_None); + if (v != NULL) { + Py_DECREF(v); + } + else { + PyErr_Clear(); + } + } } return 0; } |