[Numpy-discussion] numpy/ctypes segfault [was: PEP 3118 array size check]

Angus McMorland amcmorl@gmail....
Wed Aug 10 11:50:39 CDT 2011

On 10 August 2011 04:01, Pauli Virtanen <pav@iki.fi> wrote:
> Mon, 08 Aug 2011 11:27:14 -0400, Angus McMorland wrote:
>> I've just upgraded to the latest numpy from git along with upgrading
>> Ubuntu to natty. Now some of my code, which relies on ctypes-wrapping of
>> data structures from a messaging system, fails with the error message:
>> "RuntimeWarning: Item size computed from the PEP 3118 buffer format
>> string does not match the actual item size."
>> Can anyone tell me if this was a change that has been added into the git
>> version recently, in which case I can checkout a previous version of
>> numpy, or if I've got to try downgrading the whole system (ergh.)
> Python's ctypes module implements its PEP 3118 support incorrectly
> in recent Python versions. There's a patch in waiting:
>        http://bugs.python.org/issue10744
> In the meantime, you can just silence the warnings using the warnings
> module,
>        warnings.simplefilter("ignore", RuntimeWarning)

Thanks Pauli.

I was seeing a segfault everytime I saw the error message, and since
both started happening at the same time, I was guilty of mixing
correlation and causation. After rebuilding numpy about 10 times, I
have identified the first git commit after which the segfault appears
(feb8079070b8a659d7ee) , and a small piece of code that triggers it:

from ctypes import Structure, c_double

#-- copied out of an xml2py generated file
class S(Structure):
S._pack_ = 4
S._fields_ = [
    ('field', c_double * 2),

import numpy as np
print np.version.version
s = S()
print "S", np.asarray(s.field)

Can anyone confirm this, in which case it's probably a bug?


AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh

More information about the NumPy-Discussion mailing list