python/ext: simplify memory allocations, removed unneeded malloc/free calls
[aubio.git] / python / ext / py-filter.c
index fdf0fb0..90b8961 100644 (file)
@@ -5,7 +5,7 @@ typedef struct
   PyObject_HEAD
   aubio_filter_t * o;
   uint_t order;
-  fvec_t *vec;
+  fvec_t vec;
   fvec_t *out;
 } Py_filter;
 
@@ -50,7 +50,6 @@ Py_filter_init (Py_filter * self, PyObject * args, PyObject * kwds)
     return -1;
   }
   self->out = new_fvec(Py_default_vector_length);
-  self->vec = (fvec_t *)malloc(sizeof(fvec_t));
   return 0;
 }
 
@@ -59,7 +58,6 @@ Py_filter_del (Py_filter * self)
 {
   del_fvec(self->out);
   del_aubio_filter (self->o);
-  free(self->vec);
   Py_TYPE(self)->tp_free ((PyObject *) self);
 }
 
@@ -76,17 +74,17 @@ Py_filter_do(Py_filter * self, PyObject * args)
     return NULL;
   }
 
-  if (!PyAubio_ArrayToCFvec(input, self->vec)) {
+  if (!PyAubio_ArrayToCFvec(input, &(self->vec))) {
     return NULL;
   }
 
   // reallocate the output if needed
-  if (self->vec->length != self->out->length) {
+  if (self->vec.length != self->out->length) {
     del_fvec(self->out);
-    self->out = new_fvec(self->vec->length);
+    self->out = new_fvec(self->vec.length);
   }
   // compute the function
-  aubio_filter_do_outplace (self->o, self->vec, self->out);
+  aubio_filter_do_outplace (self->o, &(self->vec), self->out);
   return PyAubio_CFvecToArray(self->out);
 }