Author Anthony.LaTorre
Recipients Anthony.LaTorre
Date 2014-07-14.21:53:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1405374806.18.0.56272254378.issue21983@psf.upfronthosting.co.za>
In-reply-to
Content
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 (https://docs.python.org/2/library/ctypes.html#ctypes.cast) 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/__init__.py", line 488, in cast
    return _cast(obj, obj, typ)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
History
Date User Action Args
2014-07-14 21:53:26Anthony.LaTorresetrecipients: + Anthony.LaTorre
2014-07-14 21:53:26Anthony.LaTorresetmessageid: <1405374806.18.0.56272254378.issue21983@psf.upfronthosting.co.za>
2014-07-14 21:53:26Anthony.LaTorrelinkissue21983 messages
2014-07-14 21:53:26Anthony.LaTorrecreate