Visitar URL original
bpo-42972: Fully implement GC protocol for functools LRU cache by erlend-aasland · Pull Request #26423 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20220216003531/https://github.com/python/cpython/pull/26423/files
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-42972: Fully implement GC protocol for functools LRU cache #26423

Merged
merged 1 commit into from May 28, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1240,8 +1240,8 @@ static int
lru_cache_tp_clear(lru_cache_object *self)
{
lru_list_elem *list = lru_cache_unlink_list(self);
Py_CLEAR(self->func);
Py_CLEAR(self->cache);
Py_CLEAR(self->func);
Py_CLEAR(self->kwd_mark);
Py_CLEAR(self->lru_list_elem_type);
Py_CLEAR(self->cache_info_type);
@@ -1327,15 +1327,17 @@ lru_cache_deepcopy(PyObject *self, PyObject *unused)
static int
lru_cache_tp_traverse(lru_cache_object *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
lru_list_elem *link = self->root.next;
while (link != &self->root) {
lru_list_elem *next = link->next;

This comment has been minimized.

@vstinner

vstinner May 28, 2021
Member

Please add a comment (with a reference to bpo-42972) somewhere (here may be good place) to explain why the link type doesn't implement the GC protocol.

I understand that the code works as if the GC protocol is implemented, but the code is inlined.

Py_VISIT(link->key);
Py_VISIT(link->result);
Py_VISIT(Py_TYPE(link));

This comment has been minimized.

@vstinner

vstinner May 28, 2021
Member

nitpick: I suggest to visit the type first, to visit object members in their definition order.

I'm not sure that I get the rationale why the link type doesn't implement the GC protocol but is "exposed" by this Py_VISIT() call in gc.get_objects(). I'm not sure that it's a good idea to visit the type.

This comment has been minimized.

@erlend-aasland

erlend-aasland May 28, 2021 •
Author Contributor

nitpick: I suggest to visit the type first, to visit object members in their definition order.

Sorry, I was a little bit too fast there. We can fix it later if needed.

link = next;
}
Py_VISIT(self->func);
Py_VISIT(self->cache);
Py_VISIT(self->func);
Py_VISIT(self->kwd_mark);
Py_VISIT(self->lru_list_elem_type);
Py_VISIT(self->cache_info_type);