[Numpy-discussion] Segfault with python 3.2 structured array non-existent field

Charles R Harris charlesr.harris at gmail.com
Sun Mar 13 15:11:38 EDT 2011


On Sun, Mar 13, 2011 at 12:51 PM, Christoph Gohlke <cgohlke at uci.edu> wrote:

>
>
> On 3/13/2011 11:29 AM, Matthew Brett wrote:
> > Hi
> >
> > On Sun, Mar 13, 2011 at 9:54 AM, Christoph Gohlke<cgohlke at uci.edu>
>  wrote:
> >> On 3/13/2011 1:57 AM, Matthew Brett wrote:
> >>> Hi,
> >>> I have this on my OSX 10.6 system and numpy 1.5.1 and current numpy
> >>> head (30ee1d352):
> >>>
> >>> $ python3.2
> >>> Python 3.2 (r32:88452, Feb 20 2011, 11:12:31)
> >>> [GCC 4.2.1 (Apple Inc. build 5664)] on darwin
> >>> Type "help", "copyright", "credits" or "license" for more information.
> >>>>>> import numpy as np
> >>>>>> a = np.zeros((1,), dtype=[('f1', 'f')])
> >>>>>> a['f1'] = 1
> >>>>>> a['f2'] = 1
> >>> Segmentation fault
> >>>
> >>> All tests pass with np.test()
> >>>
> >>> Expected behavior with same code on python2.6:
> >>>
> >>>>>> a['f2'] = 1
> >>> Traceback (most recent call last):
> >>>     File "<stdin>", line 1, in<module>
> >>> ValueError: field named f2 not found.
> >>>
> >>> Cheers,
> >>>
> >>> Matthew
> >>
> >> Confirmed on Windows. The crash is in line 816 of mapping.c:
> >>
> >>          PyErr_Format(PyExc_ValueError,
> >>                       "field named %s not found.",
> >>                       PyString_AsString(index));
> >>
> >> This works with Python 3.x:
> >>
> >>          PyErr_Format(PyExc_ValueError,
> >>                       "field named %S not found.",
> >>                       index);
> >
> > Sure enough, in python3.2:
> >
> >>>> a[b'f2'] = 1
> > Traceback (most recent call last):
> >    File "<stdin>", line 1, in<module>
> > ValueError: field named f2 not found.
> >
> > That is - it is specifically passing a python 3 string that causes the
> > segmentation fault.
> >
> > Is this a release blocker?  I'm afraid I don't know the code well
> > enough to be confident of the right fix.  Is there something I can do
> > to help?
>
> Please open a ticket at <http://projects.scipy.org/numpy> and refer to
> this discussion and proposed fix.
>
> diff --git a/numpy/core/src/multiarray/mapping.c
> b/numpy/core/src/multiarray/mapping.c
> index 8db85bf..3a72811 100644
> --- a/numpy/core/src/multiarray/mapping.c
> +++ b/numpy/core/src/multiarray/mapping.c
> @@ -812,10 +812,16 @@ array_ass_sub(PyArrayObject *self, PyObject
> *index, PyObject *op)
>                  }
>              }
>          }
> -
> +#if defined(NPY_PY3K)
> +        PyErr_Format(PyExc_ValueError,
> +                     "field named %S not found.",
> +                     index);
> +#else
>           PyErr_Format(PyExc_ValueError,
>                       "field named %s not found.",
>                       PyString_AsString(index));
> +#endif
> +
>          return -1;
>      }
>
>
> Christoph
>
>
There are two more occurrences of this construction in  descriptor.c.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110313/efec800a/attachment.html>


More information about the NumPy-Discussion mailing list