Old code that ran normal with python < 3.12 now tracebacks in 3.12 with
ctypes.ArgumentError: argument 5: TypeError: expected LP_c_ubyte instance instead of c_byte_Array_3520
Looking at changes in 3.12 in python.org don’t seems to show something relevant.
General searchs on the web didn’t found mentions of changes, but a result pointing to python docs for 2.5 says
14.14.1.15 Type conversions
Usually, ctypes does strict type checking… There are some exceptions to this rule … For example, you can pass compatible array instances instead of pointer types. So, for POINTER(c_int), ctypes accepts an array of c_int
Okay, what if 3.12 dropped this exception?
I did a ctypes.cast at the calling site on the offending parameter, cast(_data, POINTER(ctypes.c_ubyte))
, where _data
was an c_byte_Array_ , and the code does not traceback and seems to work as in py3.11
My questions are
- anybody see ctypes be stricter than before?
- it is an intended ctypes change?
- any link about ctypes changes in 3.12?
- this was on Windows, does this happen in Linux?
Sorry to not provide short demo code, I don’t currently have compiler toolchain for Windows, nor have a Linux instance to use glibc as target lib to write one, as shown in the python’s ctypes docs.
Some more details at win32_gdi_font tracebacks in python 3.12 · Issue #964 · pyglet/pyglet · GitHub