python / python/cpython

_ctypes fails to extend the return value per libffi contract

オープン
#156,933 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

extension-modules topic-ctypes type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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: https://github.com/llvm/llvm-project/pull/221024

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs
  • gh-157045

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Modules/_ctypes/callbacks.c のリンク先の戻り値処理から始め、参照されている libffi の closure contract を読んでください。s390x での c_int callback の動作を再現または調査し、そのうえで、狭い整数型の戻り値が restype->size バイトをコピーするだけでなく、必要な ABI 拡張に従っていることを確認してください。すでに進行中の作業について、リンク先の CPython PR を確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, python
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。