[NumPy-Tickets] [NumPy] #1770: Segfault with python 3.2 structured array non-existent field

NumPy Trac numpy-tickets@scipy....
Wed Mar 16 18:04:43 CDT 2011


#1770: Segfault with python 3.2 structured array non-existent field
----------------------------+-----------------------------------------------
  Reporter:  matthew.brett  |       Owner:  somebody   
      Type:  defect         |      Status:  reopened   
  Priority:  normal         |   Milestone:  Unscheduled
 Component:  Other          |     Version:  devel      
Resolution:                 |    Keywords:             
----------------------------+-----------------------------------------------

Comment(by cgohlke):

 How about doing this pedestrian? Works for me on win-amd64 with Python
 2.6, 2.7, 3.1 and 3.2.

 {{{
 diff --git a/numpy/core/src/multiarray/mapping.c
 b/numpy/core/src/multiarray/mapping.c
 index 8db85bf..20c3501 100644
 --- a/numpy/core/src/multiarray/mapping.c
 +++ b/numpy/core/src/multiarray/mapping.c
 @@ -812,10 +812,24 @@ array_ass_sub(PyArrayObject *self, PyObject *index,
 PyObject *op)
                  }
              }
          }
 -
 -        PyErr_Format(PyExc_ValueError,
 -                     "field named %s not found.",
 -                     PyString_AsString(index));
 +#if defined(NPY_PY3K)
 +        PyErr_Format(PyExc_ValueError, "field named %S not found.",
 index);
 +#else
 +        if (PyUnicode_Check(index)) {
 +            PyObject* temp = PyUnicode_AsUnicodeEscapeString(index);
 +            if (temp == NULL) {
 +                Py_DECREF(temp);
 +                return -1;
 +            }
 +            PyErr_Format(PyExc_ValueError, "field named %s not found.",
 +                         PyString_AsString(temp));
 +            Py_DECREF(temp);
 +        }
 +        else {
 +            PyErr_Format(PyExc_ValueError, "field named %s not found.",
 +                         PyString_AsString(index));
 +        }
 +#endif
          return -1;
      }

 }}}

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1770#comment:6>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list