-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
bpo-42972: Fully implement GC protocol for functools keywrapper and partial types #26363
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 1 commit
8ef6e98
6d7cdaf
a15b49f
0c8df1f
f9ac4c5
fc39917
07f2182
0861788
7c2f750
6313247
1539195
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
This reverts commit 6d7cdaf.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -762,10 +762,28 @@ typedef struct lru_list_elem { | |
| PyObject *key, *result; | ||
| } lru_list_elem; | ||
|
|
||
| static int | ||
| lru_list_elem_clear(lru_list_elem *link) | ||
| { | ||
| Py_CLEAR(link->key); | ||
| Py_CLEAR(link->result); | ||
| return 0; | ||
| } | ||
|
|
||
| static int | ||
| lru_list_elem_traverse(lru_list_elem *link, visitproc visit, void *arg) | ||
| { | ||
| Py_VISIT(link->key); | ||
| Py_VISIT(link->result); | ||
| Py_VISIT(Py_TYPE(link)); | ||
| return 0; | ||
| } | ||
|
||
|
|
||
| static void | ||
| lru_list_elem_dealloc(lru_list_elem *link) | ||
| { | ||
| PyTypeObject *tp = Py_TYPE(link); | ||
| PyObject_GC_UnTrack(link); | ||
| Py_XDECREF(link->key); | ||
| Py_XDECREF(link->result); | ||
| tp->tp_free(link); | ||
erlend-aasland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -774,13 +792,16 @@ lru_list_elem_dealloc(lru_list_elem *link) | |
|
|
||
| static PyType_Slot lru_list_elem_type_slots[] = { | ||
| {Py_tp_dealloc, lru_list_elem_dealloc}, | ||
| {Py_tp_traverse, lru_list_elem_traverse}, | ||
| {Py_tp_clear, lru_list_elem_clear}, | ||
| {0, 0} | ||
| }; | ||
|
|
||
| static PyType_Spec lru_list_elem_type_spec = { | ||
| .name = "functools._lru_list_elem", | ||
| .basicsize = sizeof(lru_list_elem), | ||
| .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION, | ||
| .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION | | ||
| Py_TPFLAGS_HAVE_GC), | ||
| .slots = lru_list_elem_type_slots | ||
| }; | ||
|
|
||
|
|
@@ -1045,8 +1066,8 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds | |
| self->root.next == &self->root) | ||
| { | ||
| /* Cache is not full, so put the result in a new link */ | ||
| link = (lru_list_elem *)PyObject_New(lru_list_elem, | ||
| self->lru_list_elem_type); | ||
| link = (lru_list_elem *)PyObject_GC_New(lru_list_elem, | ||
| self->lru_list_elem_type); | ||
| if (link == NULL) { | ||
| Py_DECREF(key); | ||
| Py_DECREF(result); | ||
|
|
@@ -1056,6 +1077,7 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds | |
| link->hash = hash; | ||
| link->key = key; | ||
| link->result = result; | ||
| PyObject_GC_Track(link); | ||
| /* What is really needed here is a SetItem variant with a "no clobber" | ||
| option. If the __eq__ call triggers a reentrant call that adds | ||
| this same key, then this setitem call will update the cache dict | ||
|
|
@@ -1345,9 +1367,7 @@ lru_cache_tp_traverse(lru_cache_object *self, visitproc visit, void *arg) | |
| lru_list_elem *link = self->root.next; | ||
| while (link != &self->root) { | ||
| lru_list_elem *next = link->next; | ||
erlend-aasland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Py_VISIT(link->key); | ||
| Py_VISIT(link->result); | ||
| Py_VISIT(Py_TYPE(link)); | ||
| Py_VISIT(link); | ||
erlend-aasland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| link = next; | ||
| } | ||
| Py_VISIT(self->cache); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.