Skip to content

Commit 930fbe1

Browse files
Use PyType_GetModuleState for types which cannot be subclassed
1 parent 4264f8b commit 930fbe1

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Modules/itertoolsmodule.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,7 @@ static PyObject *
741741
teedataobject_jumplink(teedataobject *tdo)
742742
{
743743
if (tdo->nextlink == NULL) {
744-
PyTypeObject *tp = Py_TYPE(tdo);
745-
itertools_state *state = find_state_by_type(tp);
744+
itertools_state *state = get_module_state_by_cls(Py_TYPE(tdo));
746745
tdo->nextlink = teedataobject_newinternal(state, tdo->it);
747746
}
748747
return Py_XNewRef(tdo->nextlink);
@@ -811,7 +810,7 @@ teedataobject_clear(teedataobject *tdo)
811810
Py_CLEAR(tdo->values[i]);
812811
tmp = tdo->nextlink;
813812
tdo->nextlink = NULL;
814-
itertools_state *state = find_state_by_type(Py_TYPE(tdo));
813+
itertools_state *state = get_module_state_by_cls(Py_TYPE(tdo));
815814
teedataobject_safe_decref(tmp, state->teedataobject_type);
816815
return 0;
817816
}
@@ -862,7 +861,7 @@ itertools_teedataobject_impl(PyTypeObject *type, PyObject *it,
862861
teedataobject *tdo;
863862
Py_ssize_t i, len;
864863

865-
itertools_state *state = find_state_by_type(type);
864+
itertools_state *state = get_module_state_by_cls(type);
866865
assert(type == state->teedataobject_type);
867866

868867
tdo = (teedataobject *)teedataobject_newinternal(state, it);
@@ -1013,7 +1012,7 @@ static PyObject *
10131012
itertools__tee_impl(PyTypeObject *type, PyObject *iterable)
10141013
/*[clinic end generated code: output=b02d3fd26c810c3f input=adc0779d2afe37a2]*/
10151014
{
1016-
itertools_state *state = find_state_by_type(type);
1015+
itertools_state *state = get_module_state_by_cls(type);
10171016
return tee_fromiterable(state, iterable);
10181017
}
10191018

@@ -1051,8 +1050,8 @@ tee_setstate(teeobject *to, PyObject *state)
10511050
PyErr_SetString(PyExc_TypeError, "state is not a tuple");
10521051
return NULL;
10531052
}
1054-
itertools_state *m_state = find_state_by_type(Py_TYPE(to));
1055-
PyTypeObject *tdo_type = m_state->teedataobject_type;
1053+
itertools_state *mod_st = get_module_state_by_cls(Py_TYPE(to));
1054+
PyTypeObject *tdo_type = mod_st->teedataobject_type;
10561055
if (!PyArg_ParseTuple(state, "O!i", tdo_type, &tdo, &index)) {
10571056
return NULL;
10581057
}

0 commit comments

Comments
 (0)