Skip to content

Commit a1e622e

Browse files
committed
Use hard references
1 parent 58bc078 commit a1e622e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Modules/_functoolsmodule.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,10 @@ lru_cache_new(PyTypeObject *type, PyObject *args, PyObject *kw)
12051205
obj->func = func;
12061206
obj->misses = obj->hits = 0;
12071207
obj->maxsize = maxsize;
1208-
obj->kwd_mark = state->kwd_mark; // Borrowed
1209-
obj->lru_list_elem_type = state->lru_list_elem_type; // Borrowed
1208+
Py_INCREF(state->kwd_mark);
1209+
obj->kwd_mark = state->kwd_mark;
1210+
Py_INCREF(state->lru_list_elem_type);
1211+
obj->lru_list_elem_type = state->lru_list_elem_type;
12101212
Py_INCREF(cache_info_type);
12111213
obj->cache_info_type = cache_info_type;
12121214
obj->dict = NULL;
@@ -1242,6 +1244,8 @@ lru_cache_tp_clear(lru_cache_object *self)
12421244
lru_list_elem *list = lru_cache_unlink_list(self);
12431245
Py_CLEAR(self->func);
12441246
Py_CLEAR(self->cache);
1247+
Py_CLEAR(self->kwd_mark);
1248+
Py_CLEAR(self->lru_list_elem_type);
12451249
Py_CLEAR(self->cache_info_type);
12461250
Py_CLEAR(self->dict);
12471251
lru_cache_clear_list(list);
@@ -1334,6 +1338,8 @@ lru_cache_tp_traverse(lru_cache_object *self, visitproc visit, void *arg)
13341338
}
13351339
Py_VISIT(self->func);
13361340
Py_VISIT(self->cache);
1341+
Py_VISIT(self->kwd_mark);
1342+
Py_VISIT(self->lru_list_elem_type);
13371343
Py_VISIT(self->cache_info_type);
13381344
Py_VISIT(self->dict);
13391345
return 0;

0 commit comments

Comments
 (0)