ctypes: subclassed swapped endianness doesn't swap
還沒有人認領這個 Issue。
評估
研究方向
首先使用 c_ushort.ctype_be 和一個子類別重現最小 ctypes 範例,然後比較位元組交換後的基底型別與子類別的 from_buffer_copy 行為。追蹤 ctypes 對位元組交換簡單型別的處理,並判斷子類別路徑有何不同;當子類別產生與基底型別相同的位元組交換值,且回歸問題由測試涵蓋時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
Bug report
Subclassing a swapped simple type and calling from_buffer_copy doesn't swap bytes. Here is a minimal non-working example.
import ctypes
cshort_be = ctypes.c_ushort.__ctype_be__
class Short(cshort_be):
pass
print(cshort_be.from_buffer_copy(b"\x00\x01").value) # prints 1
print(Short.from_buffer_copy(b"\x00\x01").value) # prints 256
However, there is a simple workaround:
print(Short.__ctype_be__.from_buffer_copy(b"\x00\x01").value) # prints 1
I am not sure what happens, but ctypes behave kinda weird when subclassing native types. So this bug might be related to issue #73456.
My environment
- CPython versions tested on: 3.10.5
- Operating system and architecture:
Linux Celap 5.18.0-1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.18.2-1 (2022-06-06) x86_64 GNU/Linux
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- 平均合併
- 1 天 9 小時
- 30 天內合併 PR
- 558
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/cpython 的其他 Issue
-
docs pending
難度 2/5 1-3 小時 新手友好度 78/100
-
stdlib type-feature
難度 2/5 1-3 小時 新手友好度 78/100
-
stdlib type-feature
難度 2/5 1-3 小時 新手友好度 72/100
-
build type-bug
難度 2/5 1-3 小時 新手友好度 76/100
-
stdlib topic-email type-feature
難度 2/5 1-3 小時 新手友好度 70/100
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 74/100
bancolombia/sentinel#23 ·
-
test md 未關閉CI
難度 2/5 1-3 小時 新手友好度 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
難度 2/5 1-3 小時 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
bug client
難度 2/5 1-3 小時 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 74/100