mirror of
https://github.com/python/cpython.git
synced 2026-04-13 23:31:02 +00:00
[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:
parent
88e52acf90
commit
cccd9dd3e4
3 changed files with 11 additions and 0 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
Fix GC tracking in ``structseq.__replace__()``.
|
||||
|
|
@ -445,6 +445,7 @@ structseq_replace(PyObject *op, PyObject *args, PyObject *kwargs)
|
|||
}
|
||||
}
|
||||
|
||||
_PyObject_GC_TRACK(result);
|
||||
return (PyObject *)result;
|
||||
|
||||
error:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue