Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(26)

Unified Diff: Objects/odictobject.c

Issue 25935: OrderedDict prevents garbage collection if a circulary referenced class is used as key
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Objects/odictobject.c Sun Dec 27 13:17:04 2015 -0800
+++ b/Objects/odictobject.c Mon Dec 28 23:43:26 2015 +0200
@@ -772,19 +772,17 @@ static void
{
_ODictNode *node, *next;
- if (!_odict_EMPTY(od)) {
- node = _odict_FIRST(od);
- while (node != NULL) {
- next = _odictnode_NEXT(node);
- _odictnode_DEALLOC(node);
- node = next;
- }
- _odict_FIRST(od) = NULL;
- _odict_LAST(od) = NULL;
- }
-
_odict_free_fast_nodes(od);
od->od_fast_nodes = NULL;
+
+ node = _odict_FIRST(od);
+ _odict_FIRST(od) = NULL;
+ _odict_LAST(od) = NULL;
+ while (node != NULL) {
+ next = _odictnode_NEXT(node);
+ _odictnode_DEALLOC(node);
+ node = next;
+ }
}
/* There isn't any memory management of nodes past this point. */
@@ -1233,8 +1231,6 @@ odict_clear(register PyODictObject *od)
{
PyDict_Clear((PyObject *)od);
_odict_clear_nodes(od);
- _odict_FIRST(od) = NULL;
- _odict_LAST(od) = NULL;
if (_odict_resize(od) < 0)
return NULL;
Py_RETURN_NONE;
@@ -1556,8 +1552,13 @@ PyDoc_STRVAR(odict_doc,
static int
odict_traverse(PyODictObject *od, visitproc visit, void *arg)
{
+ _ODictNode *node;
+
Py_VISIT(od->od_inst_dict);
Py_VISIT(od->od_weakreflist);
+ _odict_FOREACH(od, node) {
+ Py_VISIT(_odictnode_KEY(node));
+ }
return PyDict_Type.tp_traverse((PyObject *)od, visit, arg);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+