Subclassing a swapped simple type and calling from_buffer_copy doesn't swap bytes. Here is a minimal non-working example.
importctypescshort_be=ctypes.c_ushort.__ctype_be__classShort(cshort_be):
passprint(cshort_be.from_buffer_copy(b"\x00\x01").value) # prints 1print(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
The text was updated successfully, but these errors were encountered:
Bug report
Subclassing a swapped simple type and calling
from_buffer_copy
doesn't swap bytes. Here is a minimal non-working example.However, there is a simple workaround:
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
Linux Celap 5.18.0-1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.18.2-1 (2022-06-06) x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered: