numarray bug or my?

Marco Bubke marco at bubke.de
Tue Feb 24 18:34:09 CET 2004


Marco Bubke wrote:

> Simon Burton wrote:
> 
>> On Mon, 23 Feb 2004 23:14:03 +0100, Marco Bubke wrote:
>> 
>> ...
>>> Ok, its in Pyrex and has a bug in
>>> flat_view = array_to_int(viewport),
>>> but I don't know why. If I change the code to flat_view =
>>> array_to_double(viewport) its runnig without glitches. I really dont
>>> understand it.
>>> 
>>> Thx
>>> 
>>> Marco
>> 
>> Yes, me too. I wasn't sure if NA_InputArray was supposed
>> to be able to handle type conversions, so I used the python
>> method:
>> 
>> array = array.astype(numarray.Int32)
>> 
>> and then used NA_InputArray on that.
>> 
>> Simon.
> 
> Ok, Than I do that, I get everytime a Segmentation fault. Before it was
> only from time to time. An its 100% NA_InputArray. If I erease
> NA_updateDataPtr before NA_InputArray I get a amok process.
> 
> cdef NumArray array_to_float(NumArray array):
>   # maybe here is memoty leak!
>   cdef NumArray flat_array
>   cdef NumArray new_array
>   print 'mark 1'
>   new_array = array.astype('Float32')
>   print new_array
>   print 'mark 2'
>   new_array = NA_updateDataPtr(new_array)
>   print 'mark 3'
>   NA_IoArray(new_array, tFloat32, NUM_C_ARRAY)
>   print 'mark 4'
>   flat_array = NA_updateDataPtr(flat_array)
>   print 'mark 5'
>   return flat_array


Ok, I have it tracked down to 

static PyArrayObject*
NA_InputArray(PyObject *a, NumarrayType t, int requires)
{
  printf("enter input\n");
  PyArrayObject *wa = NULL;
  if (NA_isPythonScalar(a)) {
    if (t == tAny) 
      t = NA_NumarrayType(a);
    if (t < 0) goto _exit;
    wa = NA_vNewArray( NULL, t, 0, NULL);
    if (!wa) goto _exit;
    if (NA_setFromPythonScalar(wa, 0, a) < 0) {
      Py_DECREF(wa);
      wa = NULL;
    }
    goto _exit;
  } else if ((wa = sequenceAsArray(a, &t))) {
    printf("input 1\n");
    if (!satisfies(wa, requires, t)) {
      printf("input 2\n");  
      PyArrayObject *wa2 = getArray(wa, t, "astype");
      printf("input 3\n");       
      Py_DECREF(wa);
      printf("input 4\n");  
      wa = wa2;
    }
    printf("input 5\n");  
    NA_updateDataPtr(wa);
  }
  _exit:
  printf("leave input\n");
  return wa;
}

static PyArrayObject *
NA_updateDataPtr(PyArrayObject *me)
{
  printf("enter update\n");
  if (!me) return me;
  printf("update 1\n");
  if (getReadBufferDataPtr (me->_data, (void **) &me->data) < 0) {
      printf("update 2\n");
    return (PyArrayObject *) PyErr_Format(_Error, 
        "NA_updateDataPtr: error getting read buffer data ptr");
  }

      printf("update 3\n");
  if (isBufferWriteable( me->_data ))
    me->flags |= WRITABLE;
  else
    me->flags &= ~WRITABLE;
  printf("leave update\n");
  return me;
}

static int 
getReadBufferDataPtr(PyObject *buffobj, void **buff) 
{
  printf("enter read buffer");
  int rval = -1;
  PyObject *buff2;
    printf("read buffer 1");
  if ((buff2 = getBuffer(buffobj))) {
      printf("read buffer 2");
    if (buff2->ob_type->tp_as_buffer->bf_getreadbuffer)
          printf("read buffer 3");
      rval = buff2->ob_type->tp_as_buffer->bf_getreadbuffer(buff2, 
                  0, buff);   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        printf("read buffer 4");
    Py_DECREF(buff2);
  }
  printf("leave read buffer");
  return rval;
}

The Segmentation fault is happen between "read buffer 3" and "read buffer
4". But this a little bit to much Python inside for me. Maybe the .data
isn't right?

regards

Marco



More information about the Python-list mailing list