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