Skip to content

[3.15] gh-156933: Widen narrow integer results in ctypes callbacks (GH-157045) - #158295

Merged
hugovk merged 2 commits into
python:3.15from
miss-islington:backport-b6f9a50-3.15
Sep 28, 2026
Merged

hugovk merged 2 commits into
python:3.15from
miss-islington:backport-b6f9a50-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

_CallPythonObject() only wrote restype->size bytes into the closure's result buffer, leaving the unused high-order bits of the ffi_arg-sized register untouched. libffi's ffi_prep_closure_loc() documents that integral types narrower than a machine register must be widened to fill it, sign-extending signed types. On architectures that always read the full register for narrow return values (s390x), this leaves garbage in the high bits, which broke libclang callbacks used by cindex.py.
(cherry picked from commit b6f9a50)

Co-authored-by: Lazizbek Ergashev lazerg2@gmail.com

…ythonGH-157045)

_CallPythonObject() only wrote restype->size bytes into the closure's result buffer, leaving the unused high-order bits of the ffi_arg-sized register untouched. libffi's ffi_prep_closure_loc() documents that integral types narrower than a machine register must be widened to fill it, sign-extending signed types. On architectures that always read the full register for narrow return values (s390x), this leaves garbage in the high bits, which broke libclang callbacks used by cindex.py.
(cherry picked from commit b6f9a50)

Co-authored-by: Lazizbek Ergashev <lazerg2@gmail.com>
@ZeroIntensity

Copy link
Copy Markdown
Member

Oh, wait a minute, this is going to fail because 3.15 doesn't have the utility we're using in the tests. I'll fix that.

@ZeroIntensity

Copy link
Copy Markdown
Member

Should be fixed now.

@hugovk
hugovk merged commit cc3ab21 into python:3.15 Sep 28, 2026
54 checks passed
@miss-islington
miss-islington deleted the backport-b6f9a50-3.15 branch September 28, 2026 06:03
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.

4 participants