Skip to content

_ctypes fails to extend the return value per libffi contract #156933

Closed

Description

@miladfarca

Bug report

Bug description:

The current implementation is relying on restype->size to write the data into a buffer, however, per libffi contract

integral types narrower than the system register size are widened

Which is not happening here. This has caused a failure on s390x when using libclang. cindex.py calls into libclang through ctypes, which builds the callback closures using libffi. With a c_int return, ctypes writes only the low 32 bits and skips the extension that both the ABI and libffi's closure contract require.

We have also opened a PR to fix this temporarily under llvm: llvm/llvm-project#221024

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

Activity

  1. ZeroIntensity commented on Sep 5, 2026

    @ZeroIntensity
    Member

    Would you like to submit a PR?

  2. miladfarca commented on Sep 25, 2026

    @miladfarca
    Author

    There is already a PR submitted which seems to pass the single test case I have shared there.

  3. added a commit that references this issue on Sep 27, 2026
  4. added 2 commits that reference this issue on Sep 27, 2026
  5. ZeroIntensity commented on Sep 27, 2026

    @ZeroIntensity
    Member

    3.15 backport will be merged separately. Thanks @miladfarca and @lazerg for the fix!

  6. added a commit that references this issue on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions