From 305182faa63ab006fe82e08449fb3014aed398b7 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 20 Oct 2026 15:18:38 -0700 Subject: [PATCH] gh-159739: Collect grapheme iterator and segment type cycles Backport to 3.15. --- .../next/Library/2026-10-20-00-00-00.gh-issue-159739.0c4ae9.rst | 2 ++ Modules/unicodedata.c | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-10-20-00-00-00.gh-issue-159739.0c4ae9.rst diff --git a/Misc/NEWS.d/next/Library/2026-10-20-00-00-00.gh-issue-159739.0c4ae9.rst b/Misc/NEWS.d/next/Library/2026-10-20-00-00-00.gh-issue-159739.0c4ae9.rst new file mode 100644 index 00000000000000..3392832f714adc --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-20-00-00-00.gh-issue-159739.0c4ae9.rst @@ -0,0 +1,2 @@ +Fix reference cycles involving the types of grapheme iterators and segments +created by :func:`unicodedata.iter_graphemes`. diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c index 9bd3639d9c3f41..811d6af7220a73 100644 --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -1989,6 +1989,7 @@ Segment_dealloc(PyObject *self) static int Segment_traverse(PyObject *self, visitproc visit, void *arg) { + Py_VISIT(Py_TYPE(self)); Py_VISIT(((SegmentObject *)self)->string); return 0; } @@ -2057,6 +2058,7 @@ GBI_dealloc(PyObject *self) static int GBI_traverse(PyObject *self, visitproc visit, void *arg) { + Py_VISIT(Py_TYPE(self)); Py_VISIT(((GraphemeBreakIterator *)self)->iter.str); return 0; }