numarray bug or my?

M

Marco Bubke

Hi

Ok, I get a reproduceable seqmentation fault.

Ok, fist the code:

cdef NumArray array_to_double(NumArray array):
# maybe here is memoty leak!
cdef NumArray flat_array_obj
flat_array_obj = NA_InputArray(NA_updateDataPtr(array), tFloat64,
NUM_C_ARRAY)
return flat_array_obj

cdef NumArray array_to_int(NumArray array):
# maybe here is memoty leak!
cdef NumArray flat_array_obj
flat_array_obj = NA_InputArray(NA_updateDataPtr(array), tInt32,
NUM_C_ARRAY)
return flat_array_obj

def un_project(GLdouble winx, GLdouble winy, GLdouble winz, NumArray model
not None, NumArray proj not None, NumArray viewport not None):
assert NA_elements(model) == 16 and NA_elements(proj) == 16 and
NA_elements(viewport) == 4,\
"modelview matrix, projection matrix or viewport ar of the wrong size"
# cdef GLdouble objx
# cdef GLdouble objy
# cdef GLdouble objz
# cdef NumArray flat_model
# cdef NumArray flat_proj
cdef NumArray flat_view
# flat_model = array_to_double(model)
# flat_proj = array_to_double(proj)
flat_view = array_to_int(viewport) <<<<<<<<<<<<<<<<<<<<<<<
# success = gluUnProject(winx, winy, winz,
<double*>NA_OFFSETDATA(flat_model), <double*>NA_OFFSETDATA(flat_proj),
<int*>NA_OFFSETDATA(flat_view), &objx, &objy, &objz)
# assert success, 'failure in the unprojection'
cdef NumArray new_array
new_array = NA_NewArray(NULL, tFloat32, 1, 3)
# new_array.fromlist([objx, objy, objz])
return new_array


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
 
S

Simon Burton

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.
 
M

Marco Bubke

Simon said:
On Mon, 23 Feb 2004 23:14:03 +0100, Marco Bubke wrote:

...

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
 
M

Marco Bubke

Simon said:
On Mon, 23 Feb 2004 23:14:03 +0100, Marco Bubke wrote:

...

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'
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
 
M

Marco Bubke

Marco said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top