Skip to content

gh-158095: Fix reference cycles in re scanners - #158100

Merged
eendebakpt merged 6 commits into
python:mainfrom
YangSiJun528:fix-re-scanner-gc
Nov 3, 2026
Merged

eendebakpt merged 6 commits into
python:mainfrom
YangSiJun528:fix-re-scanner-gc

Conversation

@YangSiJun528

@YangSiJun528 YangSiJun528 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #158095.

Visit the owned references in state.string and state.buffer.obj from scanner_traverse() so cycles involving re.finditer() and Pattern.scanner() can be collected.

Add a regression test for re.finditer() with str and bytearray subclasses. The test fails before the fix and passes after it.

AI assistance: Codex helped investigate, implement, test, and draft this PR.

Comment thread Modules/_sre/sre.c Resolved

@eendebakpt eendebakpt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @YangSiJun528.

@eendebakpt
eendebakpt merged commit 8c3b566 into python:main Nov 3, 2026
60 checks passed
@eendebakpt eendebakpt added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 3, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @YangSiJun528 for the PR, and @eendebakpt for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @YangSiJun528 for the PR, and @eendebakpt for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 3, 2026

Copy link
Copy Markdown

GH-161245 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 3, 2026
@bedevere-app

bedevere-app Bot commented Nov 3, 2026

Copy link
Copy Markdown

GH-161246 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 3, 2026
eendebakpt pushed a commit that referenced this pull request Nov 3, 2026
…61246)

gh-158095: Fix reference cycles in re scanners (GH-158100)

* Fix reference cycles in re scanners

* 📜🤖 Added by blurb_it.

* gh-158095: Normalize NEWS line endings

* gh-158095: Clear input references in re scanners

* ci: rerun checks

Assisted-by: Codex:GPT-6

---------
(cherry picked from commit 8c3b566)

Co-authored-by: sijun-yang <yangsijun5528@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
eendebakpt pushed a commit that referenced this pull request Nov 3, 2026
…61245)

gh-158095: Fix reference cycles in re scanners (GH-158100)

* Fix reference cycles in re scanners

* 📜🤖 Added by blurb_it.

* gh-158095: Normalize NEWS line endings

* gh-158095: Clear input references in re scanners

* ci: rerun checks

Assisted-by: Codex:GPT-6

---------
(cherry picked from commit 8c3b566)

Co-authored-by: sijun-yang <yangsijun5528@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

re.finditer() leaks reference cycles through its input

2 participants