GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-155151: Check the recursion limit in CALL_EX_PY and CALL_KW_BOUND_METHOD by shoutoutuoadi325 · Pull Request #155405 · python/cpython

Conversation

@shoutoutuoadi325

@shoutoutuoadi325 shoutoutuoadi325 commented Aug 9, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Fixes #155151

Problem

The generic CALL_FUNCTION_EX and CALL_KW reach start_frame, which calls
_Py_EnterRecursivePy() and raises RecursionError before the callee runs.
Their specialized forms end in _PUSH_FRAME, which decrements
py_recursion_remaining without checking it. So once a call site had been
warmed up, the callee was entered and returned normally where the
unspecialized instruction raised — warming a call site changed whether the
target function executed.

Solution

CALL_KW_PY and CALL_BOUND_METHOD_EXACT_ARGS already guard their frame push
with _CHECK_RECURSION_REMAINING. This adds it to the two that were missing
it: CALL_EX_PY and CALL_KW_BOUND_METHOD.

Changes

  • Added _CHECK_RECURSION_REMAINING to CALL_EX_PY and CALL_KW_BOUND_METHOD macros in Python/bytecodes.c
  • Regenerated opcode metadata and generated cases
  • Added regression tests in Lib/test/test_opcache.py
  • Added NEWS entry

Testing

  • Added test_recursion_check_for_call_ex_py and test_recursion_check_for_call_kw_bound_method tests
  • Verified that specialized opcodes now raise RecursionError before entering the callee when the recursion limit is reached
  • All existing tests pass
  • Issue: CALL_EX_PY and CALL_KW_BOUND_METHOD can bypass RecursionError after specialization #155151

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chatgpt-codex-connector[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@shoutoutuoadi325
gh-155151: Check the recursion limit in CALL_EX_PY and CALL_KW_BOUND_…
6424e2e
…METHOD

The generic CALL_FUNCTION_EX and CALL_KW reach start_frame, which calls
_Py_EnterRecursivePy() and raises RecursionError before the callee runs.
Their specialized forms end in _PUSH_FRAME, which decrements
py_recursion_remaining without checking it. So once a call site had been
warmed up, the callee was entered and returned normally where the
unspecialized instruction raised — warming a call site changed whether the
target function executed.

CALL_KW_PY and CALL_BOUND_METHOD_EXACT_ARGS already guard their frame push
with _CHECK_RECURSION_REMAINING. This adds it to the two that were missing
it.
@shoutoutuoadi325
shoutoutuoadi325 requested a review from markshannon as a code owner August 9, 2026 05:14
Copilot AI lite review requested due to automatic review settings August 9, 2026 05:14
@bedevere-app bedevere-app Bot mentioned this pull request Aug 9, 2026
CALL_EX_PY and CALL_KW_BOUND_METHOD can bypass RecursionError after specialization #155151
Open
@bedevere-app bedevere-app Bot added the awaiting review label Aug 9, 2026
Copilot started reviewing on behalf of shoutoutuoadi325 August 9, 2026 05:15
View session
Copilot AI reviewed Aug 9, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a behavioral mismatch at the Python recursion limit between generic call opcodes (CALL_FUNCTION_EX, CALL_KW) and their specialized forms (CALL_EX_PY, CALL_KW_BOUND_METHOD). Previously, once a call site specialized, the specialized fast-path could enter and run the callee in situations where the generic opcode would raise RecursionError before the callee executed.

Changes:

  • Added _CHECK_RECURSION_REMAINING guards to the CALL_EX_PY and CALL_KW_BOUND_METHOD macros so low recursion budget triggers deoptimization back to the generic opcode.
  • Regenerated interpreter generated code (generated_cases.c.h) and opcode macro metadata to reflect the new uop sequence.
  • Added regression tests ensuring warmed (specialized) call sites do not execute the callee at the recursion boundary, plus a NEWS entry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Python/bytecodes.c Inserts _CHECK_RECURSION_REMAINING into the two specialized call macros that could previously bypass the recursion check.
Python/generated_cases.c.h Regenerated cases include the corresponding deopt-on-low-recursion blocks for the specialized opcodes.
Include/internal/pycore_opcode_metadata.h Regenerated macro expansion metadata updates uop counts/sequences for the affected opcodes.
Lib/test/test_opcache.py Adds regression tests to ensure specialization does not change recursion-limit behavior (callee must not run).
Misc/NEWS.d/next/Core_and_Builtins/2026-08-09-05-10-00.gh-issue-155151.b2A2eQ.rst Documents the behavioral fix in the NEWS entry.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@shoutoutuoadi325
gh-155151: Add missing test_cases.c.h to generated files
7a1ad88
This file should have been included in the original commit but was missed.
@picnixz

picnixz commented Aug 9, 2026

Copy link
Copy Markdown
Member

Identical (the test!) to #155272 and fully AI generated, I am closing this. PLease don't open PRs on advanced topics unless you (as a human, without an LLM) are able to do the same. I rather have someone who KNOWS the interpreter itself to make the work and the tests. Should you continue open fully-AI generated PRs, we will restrict your access to our repositories as it goes against the fair use of AI tools.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz closed this Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

CALL_EX_PY and CALL_KW_BOUND_METHOD can bypass RecursionError after specialization

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@shoutoutuoadi325 @picnixz
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.