diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-01-01 14:11:22 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-01-01 14:11:22 (GMT) |
commit | aa687902f21dc32a72f578a992cc9e44444ced44 (patch) | |
tree | dcd5060070b8236e3f8a3c8561030099d95992f7 /Objects/dictobject.c | |
parent | 4ba9f412bfec4462e17c91e6fe63aeda80b43974 (diff) | |
download | cpython-aa687902f21dc32a72f578a992cc9e44444ced44.zip cpython-aa687902f21dc32a72f578a992cc9e44444ced44.tar.gz cpython-aa687902f21dc32a72f578a992cc9e44444ced44.tar.bz2 |
Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index f2ef4b0..f4d8683 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2331,7 +2331,7 @@ static PyObject * dictiter_new(PyDictObject *dict, PyTypeObject *itertype) { dictiterobject *di; - di = PyObject_New(dictiterobject, itertype); + di = PyObject_GC_New(dictiterobject, itertype); if (di == NULL) return NULL; Py_INCREF(dict); @@ -2348,6 +2348,7 @@ dictiter_new(PyDictObject *dict, PyTypeObject *itertype) } else di->di_result = NULL; + _PyObject_GC_TRACK(di); return (PyObject *)di; } @@ -2356,7 +2357,15 @@ dictiter_dealloc(dictiterobject *di) { Py_XDECREF(di->di_dict); Py_XDECREF(di->di_result); - PyObject_Del(di); + PyObject_GC_Del(di); +} + +static int +dictiter_traverse(dictiterobject *di, visitproc visit, void *arg) +{ + Py_VISIT(di->di_dict); + Py_VISIT(di->di_result); + return 0; } static PyObject * @@ -2435,9 +2444,9 @@ PyTypeObject PyDictIterKey_Type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2507,9 +2516,9 @@ PyTypeObject PyDictIterValue_Type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2593,9 +2602,9 @@ PyTypeObject PyDictIterItem_Type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ |