Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
gh-145376: Fix GC tracking in structseq.__replace__ (GH-145820)
(cherry picked from commit 00a2585)

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
  • Loading branch information
eendebakpt authored and miss-islington committed Mar 13, 2026
commit 84212fd99b307ff8481ab92159c2c85abd851c22
9 changes: 9 additions & 0 deletions Lib/test/test_structseq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import gc
import os
import pickle
import re
Expand Down Expand Up @@ -355,6 +356,14 @@ def test_reference_cycle(self):
type(t).refcyle = t
"""))

def test_replace_gc_tracked(self):
# Verify that __replace__ results are properly GC-tracked
time_struct = time.gmtime(0)
lst = []
replaced_struct = time_struct.__replace__(tm_year=lst)
lst.append(replaced_struct)

self.assertTrue(gc.is_tracked(replaced_struct))

if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix GC tracking in ``structseq.__replace__()``.
1 change: 1 addition & 0 deletions Objects/structseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ structseq_replace(PyObject *op, PyObject *args, PyObject *kwargs)
}
}

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

error:
Expand Down
Loading