-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-42972: Fully implement GC protocol for functools LRU cache #26423
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
Py_VISIT(link->key); | ||
Py_VISIT(link->result); | ||
Py_VISIT(Py_TYPE(link)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.