diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 1fcaf299e6..0f5160c215 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -784,6 +784,7 @@ typedef struct lru_cache_object { PyObject *cache_info_type; PyObject *dict; PyObject *weakreflist; + _functools_state *state; } lru_cache_object; static PyObject * @@ -872,8 +873,7 @@ infinite_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwd { PyObject *result; Py_hash_t hash; - _functools_state *state; - state = get_functools_state_by_type(Py_TYPE(self)); + _functools_state *state = self->state; if (state == NULL) { return NULL; } @@ -977,9 +977,8 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds lru_list_elem *link; PyObject *key, *result, *testresult; Py_hash_t hash; - _functools_state *state; + _functools_state *state = self->state; - state = get_functools_state_by_type(Py_TYPE(self)); if (state == NULL) { return NULL; } @@ -1207,6 +1206,7 @@ lru_cache_new(PyTypeObject *type, PyObject *args, PyObject *kw) obj->cache_info_type = cache_info_type; obj->dict = NULL; obj->weakreflist = NULL; + obj->state = get_functools_state_by_type(type); return (PyObject *)obj; }