numarray bug or my?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco Bubke

    numarray bug or my?

    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(N A_updateDataPtr (array), tFloat64,
    NUM_C_ARRAY)
    return flat_array_obj

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

    def un_project(GLdo uble winx, GLdouble winy, GLdouble winz, NumArray model
    not None, NumArray proj not None, NumArray viewport not None):
    assert NA_elements(mod el) == 16 and NA_elements(pro j) == 16 and
    NA_elements(vie wport) == 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(vi ewport) <<<<<<<<<<<<<<< <<<<<<<<
    # success = gluUnProject(wi nx, winy, winz,
    <double*>NA_OFF SETDATA(flat_mo del), <double*>NA_OFF SETDATA(flat_pr oj),
    <int*>NA_OFFSET DATA(flat_view) , &objx, &objy, &objz)
    # assert success, 'failure in the unprojection'
    cdef NumArray new_array
    new_array = NA_NewArray(NUL L, tFloat32, 1, 3)
    # new_array.froml ist([objx, objy, objz])
    return new_array


    Ok, its in Pyrex and has a bug in
    flat_view = array_to_int(vi ewport),
    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
  • Simon Burton

    #2
    Re: numarray bug or my?

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

    ....[color=blue]
    > Ok, its in Pyrex and has a bug in
    > flat_view = array_to_int(vi ewport),
    > 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[/color]

    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(nu marray.Int32)

    and then used NA_InputArray on that.

    Simon.

    Comment

    • Marco Bubke

      #3
      Re: numarray bug or my?

      Simon Burton wrote:
      [color=blue]
      > On Mon, 23 Feb 2004 23:14:03 +0100, Marco Bubke wrote:
      >
      > ...[color=green]
      >> Ok, its in Pyrex and has a bug in
      >> flat_view = array_to_int(vi ewport),
      >> 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[/color]
      >
      > 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(nu marray.Int32)
      >
      > and then used NA_InputArray on that.
      >
      > Simon.[/color]

      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_updateDataPt r
      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('F loat32')
      print new_array
      print 'mark 2'
      new_array = NA_updateDataPt r(new_array)
      print 'mark 3'
      NA_IoArray(new_ array, tFloat32, NUM_C_ARRAY)
      print 'mark 4'
      flat_array = NA_updateDataPt r(flat_array)
      print 'mark 5'
      return flat_array

      Comment

      • Marco Bubke

        #4
        Re: numarray bug or my?

        Simon Burton wrote:
        [color=blue]
        > On Mon, 23 Feb 2004 23:14:03 +0100, Marco Bubke wrote:
        >
        > ...[color=green]
        >> Ok, its in Pyrex and has a bug in
        >> flat_view = array_to_int(vi ewport),
        >> 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[/color]
        >
        > 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(nu marray.Int32)
        >
        > and then used NA_InputArray on that.
        >
        > Simon.[/color]

        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_updateDataPt r
        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('F loat32')
        print new_array
        print 'mark 2'
        NA_updateDataPt r(new_array)
        print 'mark 3'
        NA_IoArray(new_ array, tFloat32, NUM_C_ARRAY)
        print 'mark 4'
        flat_array = NA_updateDataPt r(flat_array)
        print 'mark 5'
        return flat_array

        Comment

        • Marco Bubke

          #5
          Re: numarray bug or my?

          Marco Bubke wrote:
          [color=blue]
          > Simon Burton wrote:
          >[color=green]
          >> On Mon, 23 Feb 2004 23:14:03 +0100, Marco Bubke wrote:
          >>
          >> ...[color=darkred]
          >>> Ok, its in Pyrex and has a bug in
          >>> flat_view = array_to_int(vi ewport),
          >>> 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[/color]
          >>
          >> 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(nu marray.Int32)
          >>
          >> and then used NA_InputArray on that.
          >>
          >> Simon.[/color]
          >
          > 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_updateDataPt r 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('F loat32')
          > print new_array
          > print 'mark 2'
          > new_array = NA_updateDataPt r(new_array)
          > print 'mark 3'
          > NA_IoArray(new_ array, tFloat32, NUM_C_ARRAY)
          > print 'mark 4'
          > flat_array = NA_updateDataPt r(flat_array)
          > print 'mark 5'
          > return flat_array[/color]


          Ok, I have it tracked down to

          static PyArrayObject*
          NA_InputArray(P yObject *a, NumarrayType t, int requires)
          {
          printf("enter input\n");
          PyArrayObject *wa = NULL;
          if (NA_isPythonSca lar(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_setFromPyth onScalar(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_updateDataPt r(wa);
          }
          _exit:
          printf("leave input\n");
          return wa;
          }

          static PyArrayObject *
          NA_updateDataPt r(PyArrayObject *me)
          {
          printf("enter update\n");
          if (!me) return me;
          printf("update 1\n");
          if (getReadBufferD ataPtr (me->_data, (void **) &me->data) < 0) {
          printf("update 2\n");
          return (PyArrayObject *) PyErr_Format(_E rror,
          "NA_updateDataP tr: error getting read buffer data ptr");
          }

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

          static int
          getReadBufferDa taPtr(PyObject *buffobj, void **buff)
          {
          printf("enter read buffer");
          int rval = -1;
          PyObject *buff2;
          printf("read buffer 1");
          if ((buff2 = getBuffer(buffo bj))) {
          printf("read buffer 2");
          if (buff2->ob_type->tp_as_buffer->bf_getreadbuff er)
          printf("read buffer 3");
          rval = buff2->ob_type->tp_as_buffer->bf_getreadbuff er(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

          Comment

          Working...