Skip to content

Commit ad2aa7b

Browse files
committed
fix(structseq): enable GC tracking in PyStructSequence_New
1 parent 7a562c4 commit ad2aa7b

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/test/test_structseq.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,5 +365,10 @@ def test_replace_gc_tracked(self):
365365

366366
self.assertTrue(gc.is_tracked(replaced_struct))
367367

368+
def test_gc_tracked(self):
369+
# PyStructSequence objects created via C API or Python should be GC-tracked
370+
self.assertTrue(gc.is_tracked(time.gmtime()))
371+
self.assertTrue(gc.is_tracked(os.stat(__file__)))
372+
368373
if __name__ == "__main__":
369374
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix GC tracking for :class:`!PyStructSequence` instances created via :c:func:`PyStructSequence_New`. Patch by Shamil Abdulaev.

Objects/structseq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ PyStructSequence_New(PyTypeObject *type)
8484
for (i = 0; i < size; i++)
8585
obj->ob_item[i] = NULL;
8686

87+
_PyObject_GC_TRACK(obj);
8788
return (PyObject*)obj;
8889
}
8990

@@ -265,7 +266,6 @@ structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict)
265266
}
266267
}
267268

268-
_PyObject_GC_TRACK(res);
269269
return (PyObject*) res;
270270
}
271271

@@ -449,7 +449,6 @@ structseq_replace(PyObject *op, PyObject *args, PyObject *kwargs)
449449
}
450450
}
451451

452-
_PyObject_GC_TRACK(result);
453452
return (PyObject *)result;
454453

455454
error:

0 commit comments

Comments
 (0)