Skip to content

GH-149501: Fix compilation warning for _YIELD_VALUE#149502

Merged
kumaraditya303 merged 11 commits into
python:mainfrom
sergey-miryanov:bug/149501-fix-msvc-warning
May 12, 2026
Merged

GH-149501: Fix compilation warning for _YIELD_VALUE#149502
kumaraditya303 merged 11 commits into
python:mainfrom
sergey-miryanov:bug/149501-fix-msvc-warning

Conversation

@sergey-miryanov
Copy link
Copy Markdown
Contributor

@sergey-miryanov sergey-miryanov commented May 7, 2026

@sergey-miryanov
Copy link
Copy Markdown
Contributor Author

cc @vstinner as an author of the change

@sergey-miryanov sergey-miryanov force-pushed the bug/149501-fix-msvc-warning branch from f3eadda to 0cb3e7d Compare May 7, 2026 17:02
@vstinner
Copy link
Copy Markdown
Member

vstinner commented May 7, 2026

Would it be possible to change i type to size_t or Py_ssize_t instead?

Comment thread Include/internal/pycore_code.h
Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Sorry, but in fact I prefer the initial fix: int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame));.

I don't think that changing _Py_GetBaseCodeUnit() parameter type from int to Py_ssize_t is worth it, since PyCode_New() checks indirectly that the size fits into an int:

    if (PyBytes_GET_SIZE(con->code) > INT_MAX) {
        PyErr_SetString(PyExc_OverflowError,
                        "code: co_code larger than INT_MAX");
        return -1;
    }

@sergey-miryanov
Copy link
Copy Markdown
Contributor Author

@vstinner
I've updated the intermediate value to use Py_ssize_t and added an assertion to ensure it fits in an int before casting. What do you think? Does this approach look good?

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Yes, I'm fine with the assert() approach.

Comment thread Python/bytecodes.c Outdated
@sergey-miryanov
Copy link
Copy Markdown
Contributor Author

JIT fail seems unrelated to the changes.

@kumaraditya303 kumaraditya303 merged commit 1a79fd0 into python:main May 12, 2026
78 of 79 checks passed
@sergey-miryanov
Copy link
Copy Markdown
Contributor Author

Thanks all!

@sergey-miryanov sergey-miryanov added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 12, 2026
@miss-islington-app
Copy link
Copy Markdown

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

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 12, 2026

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 12, 2026
kumaraditya303 pushed a commit that referenced this pull request May 12, 2026
…49502) (#149737)

GH-149501: Fix compilation warning in `_YIELD_VALUE` uop (GH-149502)
(cherry picked from commit 1a79fd0)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants