[3.14] gh-145376: Fix GC tracking in structseq.__replace__ (GH-145820) (#145922)

gh-145376: Fix GC tracking in `structseq.__replace__` (GH-145820)
(cherry picked from commit 00a25859a9)

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
This commit is contained in:
Miss Islington (bot) 2026-03-16 10:08:15 +01:00 committed by GitHub
parent 88e52acf90
commit cccd9dd3e4
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: