Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_structseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,10 @@ def test_replace_gc_tracked(self):

self.assertTrue(gc.is_tracked(replaced_struct))

def test_gc_tracked(self):
# PyStructSequence objects created via C API or Python should be GC-tracked
self.assertTrue(gc.is_tracked(time.gmtime()))
self.assertTrue(gc.is_tracked(os.stat(__file__)))

if __name__ == "__main__":
unittest.main()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in Library.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I didn't pay attention to the section of the Changelog entry. Sadly, I saw your comment after the PR was merged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote #158983 to move it.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix GC tracking for :class:`!PyStructSequence` instances created via :c:func:`PyStructSequence_New`. Patch by Shamil Abdulaev.
3 changes: 1 addition & 2 deletions Objects/structseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ PyStructSequence_New(PyTypeObject *type)
for (i = 0; i < size; i++)
obj->ob_item[i] = NULL;

_PyObject_GC_TRACK(obj);
Comment thread
ashm-dev marked this conversation as resolved.
Resolved
return (PyObject*)obj;
}

Expand Down Expand Up @@ -265,7 +266,6 @@ structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict)
}
}

_PyObject_GC_TRACK(res);
return (PyObject*) res;
}

Expand Down Expand Up @@ -449,7 +449,6 @@ structseq_replace(PyObject *op, PyObject *args, PyObject *kwargs)
}
}

_PyObject_GC_TRACK(result);
return (PyObject *)result;

error:
Expand Down
Loading