Author Anthony.LaTorre
Recipients Anthony.LaTorre
Date 2014-07-14.21:53:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I get a segfault when trying to cast a string to a structure. 
>>> import ctypes
>>> class Struct(ctypes.Structure):
...     _fields_ = [('a', ctypes.c_uint32)]
>>> s = '0'*100
>>> ctypes.cast(s,Struct)
Segmentation fault

The docs ( say that `obj` "must be an object that can be interpreted as a pointer", so I assume this should return the same exception you get when trying to cast a list:

>>> ctypes.cast(range(10),Struct)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/ctypes/", line 488, in cast
    return _cast(obj, obj, typ)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
Date User Action Args
2014-07-14 21:53:26Anthony.LaTorresetrecipients: + Anthony.LaTorre
2014-07-14 21:53:26Anthony.LaTorresetmessageid: <>
2014-07-14 21:53:26Anthony.LaTorrelinkissue21983 messages
2014-07-14 21:53:26Anthony.LaTorrecreate