Python ctypes structure keeps converting its fields -
i have ran following code:
from ctypes import * class innerstructure(structure): pass innerstructure._fields_ = [ ('d', c_ulong), ] class complexstructure(structure): pass complexstructure._fields_ = [ ('a', innerstructure * 2), ('b', c_ushort * 2 * 2), ('c', c_ulong), ] input_structure = complexstructure() print(type(input_structure.a)) print(type(input_structure.a[0])) print(type(input_structure.a[0].d)) print(type(input_structure.b)) print(type(input_structure.b[0])) print(type(input_structure.b[0][0])) print(type(input_structure.c)) print(type(c_ushort(1))) print(type(c_long(1)))
and i'd expect type of input_structure.a[0].d
c_ulong
, obtain looks in following way:
<class 'struct_utils_tests.innerstructure_array_2'> <class 'struct_utils_tests.innerstructure'> <type 'long'> <class 'struct_utils_tests.c_ushort_array_2_array_2'> <class 'struct_utils_tests.c_ushort_array_2'> <type 'int'> <type 'long'> <class 'ctypes.c_ushort'> <class 'ctypes.c_long'>
it serious problem, because cannot force member of structure of type c_*
, because of cannot instance address of structure members (function addressof works ctypes types). expected behaviour or should write definition of these structures differently?
thanks in advance!
Comments
Post a Comment