I have a structure that looks like the following:
class S(Structure):
_fields_ = [("a", POINTER(c_int))]
s = S()
ia = (c_int * 10)()
s.a = ia
print s.a.contents
The s.a.contents causes the following:
SystemError: ../Objects/listobject.c:105: bad argument
to internal
function
Using the sequence getitem as in: s.a[0] works. However
if you try to assign to it like s.a[0] = 1, the same
exception is thrown.
Clearly it would be nice to allow pointer members to
point to arrays of objects of the respective type. I
understand that this may not be a supported feature of
the Pointer type when it is a struct field. It appears
like this may be supported because the the getitem
access of s.a will reflect the contents of ia.
Regardless, ctypes should probably not allow a type
error like this to reach so far into the Python runtime.
So the actual nature of this bug is unknown. It is
unclear whether assigning an array to a pointer like
this is an allowed feature (it half works at least). It
may be that the pointer access is meant to be read
only. If so, then the error handling should probably be
polished.
Logged In: YES
user_id=11105
This is a bug deep inside ctypes. I will investigate it,
but it may take some time.
As a workaround, you should initialize the array *before*
storing it in the structure. If that's possible.
Logged In: YES
user_id=11105
As I said, deep changes had to be made to make this work.
But now it is fixed, in ctypes 0.9.5.
Thanks.