ctypes: subclassed swapped endianness doesn't swap
まだ誰も着手していません。
評価
調査の方向性
まず、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時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
-
area/auth bug comp/agent P3 platform/discord type/security
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#117848 ·
-
難易度 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