Open px528 opened 2 years ago
I get similar error without unions. Below is a test snippet that passes on Windows but fails on Ubuntu WSL2.
import ctypes
for field_width in range(32, 1, -1):
class TestStruct(ctypes.Structure):
_fields_ = [
("Field1", ctypes.c_uint32, field_width),
("Field2", ctypes.c_uint8, 8)
]
cmd = TestStruct()
cmd.Field2 = 1
if cmd.Field2 != 1:
raise RuntimeError(f"{field_width=}, {cmd.Field2=} != 1")
print("All good")
I get following output in WSL2 Ubuntu
$ python --version
Python 3.8.10
$ python -c 'import ctypes; print(ctypes.__version__)'
1.1.0
$ python ctypes_test.py
Traceback (most recent call last):
File "ctypes_test.py", line 13, in <module>
raise RuntimeError(f"{field_width=}, {cmd.Field2=} != 1")
RuntimeError: field_width=24, cmd.Field2=0 != 1
I tried Python 3.9 on WSL2 Ubuntu too with same result.
Your E-mail has been received and I will reply as soon as possible
below example is simple and can be reproduced.