gh-151763: Restore exception if parser recovery path leaves none set (OOM-0021)#154717
Closed
Vamsi-klu wants to merge 1 commit into
Closed
gh-151763: Restore exception if parser recovery path leaves none set (OOM-0021)#154717Vamsi-klu wants to merge 1 commit into
Vamsi-klu wants to merge 1 commit into
Conversation
…e set After the diagnostic second parse pass, call PyErr_NoMemory() when no exception is set so callers do not hit _Py_CheckFunctionResult fatals (OOM-0021).
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Vamsi-klu
marked this pull request as draft
July 26, 2026 08:01
Author
|
Closing this PR. Thank you for the review attention. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix OOM-0021 under umbrella gh-151763: the parser recovery / diagnostic second pass can return
NULLwith no exception set, which later tripsPy_FatalError("a function returned NULL without setting an exception")in_Py_CheckFunctionResult.What the issue is
_PyPegen_run_parseralready guardsres != NULL && PyErr_Occurred()(OOM-0013). Onres == NULLit still runs a heavier second parse pass and_PyPegen_set_syntax_error_metadata, which canPyErr_Clear()internally. Under sustained OOM the recovery path can finish withtstate->current_exception == NULLandreturn NULL, violating the C-API result/error contract. Callers such as the symtable path then fatal inObjects/call.c.Why I solved it that way
Restore the contract at the return site with:
This matches the idiom already used nearby after OOM-0013 (
Parser/pegen.cother arms).PyErr_NoMemory()is safe under OOM (preallocated singleton).Do not remove
_Py_CheckFunctionResult's fatal — that enforces the contract for the whole C API; weakening it would hide extension bugs.Do not yet rewrite
_PyPegen_set_syntax_error_metadatato save/restore around itsPyErr_Clearcalls — that is a nicer long-term fix but larger and riskier; the belt at the return site closes the crash now.Separate PR from other OOM findings per umbrella policy (one PR per bug).
How I did it
At the end of the
res == NULLblock in_PyPegen_run_parser, after syntax-error metadata setup and beforereturn NULL:NEWS under Core and Builtins for gh-151763 (OOM-0021).
Impact
MemoryError.res != NULLcontradiction).Testing plan
test_peg_generatorneeds extra resources (skipped in default run).set_nomemorysweep — not automated here.Everything else
Requested reviewers (subject-matter experts)
Could the following SMEs take a look when convenient (I cannot formally request reviews from this fork account):
Thank you!