gh-145376: Fix GC tracking in structseq.__replace__ (#145820)

This commit is contained in:
Pieter Eendebak 2026-03-13 16:42:19 +01:00 committed by GitHub
parent 79b91e7c50
commit 00a25859a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 0 deletions

View file

@ -1,4 +1,5 @@
import copy
import gc
import os
import pickle
import re
@ -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()

View file

@ -0,0 +1 @@
Fix GC tracking in ``structseq.__replace__()``.

View file

@ -445,6 +445,7 @@ structseq_replace(PyObject *op, PyObject *args, PyObject *kwargs)
}
}
_PyObject_GC_TRACK(result);
return (PyObject *)result;
error: