Skip to content

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions