[3.12] gh-115874: Don't use module state in teedataobject tp_dealloc (GH-116204) (#116955)

(cherry picked from commit e2fcaf19d3)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
This commit is contained in:
Miss Islington (bot) 2024-03-18 13:40:34 +01:00 committed by GitHub
parent 25243b1461
commit 1c0c6c91af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View file

@ -810,10 +810,9 @@ teedataobject_traverse(teedataobject *tdo, visitproc visit, void * arg)
}
static void
teedataobject_safe_decref(PyObject *obj, PyTypeObject *tdo_type)
teedataobject_safe_decref(PyObject *obj)
{
while (obj && Py_IS_TYPE(obj, tdo_type) &&
Py_REFCNT(obj) == 1) {
while (obj && Py_REFCNT(obj) == 1) {
PyObject *nextlink = ((teedataobject *)obj)->nextlink;
((teedataobject *)obj)->nextlink = NULL;
Py_SETREF(obj, nextlink);
@ -832,8 +831,7 @@ teedataobject_clear(teedataobject *tdo)
Py_CLEAR(tdo->values[i]);
tmp = tdo->nextlink;
tdo->nextlink = NULL;
itertools_state *state = get_module_state_by_cls(Py_TYPE(tdo));
teedataobject_safe_decref(tmp, state->teedataobject_type);
teedataobject_safe_decref(tmp);
return 0;
}