python / python/cpython

_ctypes fails to extend the return value per libffi contract

未關閉
#156,933 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

extension-modules topic-ctypes type-bug
主要語言
Python
星號
77.2k
分支
36k
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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Modules/_ctypes/callbacks.c 中連結的回傳值處理部分開始,並閱讀所參照的 libffi closure contract。重現或檢查 s390x 上的 c_int callback 行為,然後驗證窄整數回傳值遵循所需的 ABI 擴充,而不是只複製 restype->size 個位元組。檢查連結的 CPython PR,了解已經在進行的工作。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c, python
領域
backend
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。