Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbf409f

Browse files
committed
Re-enable GC of iter objects.
1 parent d164837 commit dbf409f

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

Objects/iterobject.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ PyObject *
1212
PySeqIter_New(PyObject *seq)
1313
{
1414
seqiterobject *it;
15-
it = PyObject_NEW(seqiterobject, &PySeqIter_Type);
15+
it = PyObject_GC_New(seqiterobject, &PySeqIter_Type);
1616
if (it == NULL)
1717
return NULL;
1818
it->it_index = 0;
1919
Py_INCREF(seq);
2020
it->it_seq = seq;
21-
PyObject_GC_Init(it);
21+
_PyObject_GC_TRACK(it);
2222
return (PyObject *)it;
2323
}
2424
static void
2525
iter_dealloc(seqiterobject *it)
2626
{
27-
PyObject_GC_Fini(it);
27+
_PyObject_GC_UNTRACK(it);
2828
Py_DECREF(it->it_seq);
29-
it = (seqiterobject *) PyObject_AS_GC(it);
30-
PyObject_DEL(it);
29+
PyObject_GC_Del(it);
3130
}
3231

3332
static int
@@ -100,7 +99,7 @@ PyTypeObject PySeqIter_Type = {
10099
PyObject_HEAD_INIT(&PyType_Type)
101100
0, /* ob_size */
102101
"iterator", /* tp_name */
103-
sizeof(seqiterobject) + PyGC_HEAD_SIZE, /* tp_basicsize */
102+
sizeof(seqiterobject), /* tp_basicsize */
104103
0, /* tp_itemsize */
105104
/* methods */
106105
(destructor)iter_dealloc, /* tp_dealloc */
@@ -118,7 +117,7 @@ PyTypeObject PySeqIter_Type = {
118117
PyObject_GenericGetAttr, /* tp_getattro */
119118
0, /* tp_setattro */
120119
0, /* tp_as_buffer */
121-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
120+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
122121
0, /* tp_doc */
123122
(traverseproc)iter_traverse, /* tp_traverse */
124123
0, /* tp_clear */
@@ -147,24 +146,23 @@ PyObject *
147146
PyCallIter_New(PyObject *callable, PyObject *sentinel)
148147
{
149148
calliterobject *it;
150-
it = PyObject_NEW(calliterobject, &PyCallIter_Type);
149+
it = PyObject_GC_New(calliterobject, &PyCallIter_Type);
151150
if (it == NULL)
152151
return NULL;
153152
Py_INCREF(callable);
154153
it->it_callable = callable;
155154
Py_INCREF(sentinel);
156155
it->it_sentinel = sentinel;
157-
PyObject_GC_Init(it);
156+
_PyObject_GC_TRACK(it);
158157
return (PyObject *)it;
159158
}
160159
static void
161160
calliter_dealloc(calliterobject *it)
162161
{
163-
PyObject_GC_Fini(it);
162+
_PyObject_GC_UNTRACK(it);
164163
Py_DECREF(it->it_callable);
165164
Py_DECREF(it->it_sentinel);
166-
it = (calliterobject *) PyObject_AS_GC(it);
167-
PyObject_DEL(it);
165+
PyObject_GC_Del(it);
168166
}
169167

170168
static int
@@ -218,7 +216,7 @@ PyTypeObject PyCallIter_Type = {
218216
PyObject_HEAD_INIT(&PyType_Type)
219217
0, /* ob_size */
220218
"callable-iterator", /* tp_name */
221-
sizeof(calliterobject) + PyGC_HEAD_SIZE,/* tp_basicsize */
219+
sizeof(calliterobject), /* tp_basicsize */
222220
0, /* tp_itemsize */
223221
/* methods */
224222
(destructor)calliter_dealloc, /* tp_dealloc */
@@ -236,7 +234,7 @@ PyTypeObject PyCallIter_Type = {
236234
PyObject_GenericGetAttr, /* tp_getattro */
237235
0, /* tp_setattro */
238236
0, /* tp_as_buffer */
239-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
237+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
240238
0, /* tp_doc */
241239
(traverseproc)calliter_traverse, /* tp_traverse */
242240
0, /* tp_clear */

0 commit comments

Comments
 (0)