Index: python/ext/aubio-types.h
===================================================================
--- python/ext/aubio-types.h	(revision f2ce0fcdfdf7744b5a730f04f603dfb089110190)
+++ python/ext/aubio-types.h	(revision bfe8256155757161c8d96033b2c000685a63e001)
@@ -56,11 +56,11 @@
 // defined in aubio-proxy.c
 extern PyObject *PyAubio_CFvecToArray (fvec_t * self);
-extern fvec_t *PyAubio_ArrayToCFvec (PyObject * self);
+extern int PyAubio_ArrayToCFvec (PyObject * self, fvec_t *out);
 
-extern Py_cvec *PyAubio_CCvecToPyCvec (cvec_t * self);
-extern cvec_t *PyAubio_ArrayToCCvec (PyObject *input);
+extern PyObject * PyAubio_CCvecToPyCvec (cvec_t * self, Py_cvec *out);
+extern int PyAubio_ArrayToCCvec (PyObject *input, cvec_t *i);
 
 extern PyObject *PyAubio_CFmatToArray (fmat_t * self);
-extern fmat_t *PyAubio_ArrayToCFmat (PyObject *input);
+extern int PyAubio_ArrayToCFmat (PyObject *input, fmat_t *out);
 
 // hand written wrappers
Index: python/ext/aubioproxy.c
===================================================================
--- python/ext/aubioproxy.c	(revision f2ce0fcdfdf7744b5a730f04f603dfb089110190)
+++ python/ext/aubioproxy.c	(revision bfe8256155757161c8d96033b2c000685a63e001)
@@ -1,61 +1,3 @@
 #include "aubio-types.h"
-
-fvec_t *
-PyAubio_ArrayToCFvec (PyObject *input) {
-  PyObject *array;
-  fvec_t *vec;
-  if (input == NULL) {
-    PyErr_SetString (PyExc_ValueError, "input array is not a python object");
-    goto fail;
-  }
-  // parsing input object into a Py_fvec
-  if (PyArray_Check(input)) {
-
-    // we got an array, convert it to an fvec
-    if (PyArray_NDIM ((PyArrayObject *)input) == 0) {
-      PyErr_SetString (PyExc_ValueError, "input array is a scalar");
-      goto fail;
-    } else if (PyArray_NDIM ((PyArrayObject *)input) > 1) {
-      PyErr_SetString (PyExc_ValueError,
-          "input array has more than one dimensions");
-      goto fail;
-    }
-
-    if (!PyArray_ISFLOAT ((PyArrayObject *)input)) {
-      PyErr_SetString (PyExc_ValueError, "input array should be float");
-      goto fail;
-    } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) {
-      PyErr_SetString (PyExc_ValueError, "input array should be float32");
-      goto fail;
-    } else {
-      // input data type is float32, nothing else to do
-      array = input;
-    }
-
-    // vec = new_fvec (vec->length);
-    // no need to really allocate fvec, just its struct member
-    vec = (fvec_t *)malloc(sizeof(fvec_t));
-    long length = PyArray_SIZE ((PyArrayObject *)array);
-    if (length > 0) {
-      vec->length = (uint_t)length;
-    } else {
-      PyErr_SetString (PyExc_ValueError, "input array size should be greater than 0");
-      goto fail;
-    }
-    vec->data = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)array, 0);
-
-  } else if (PyObject_TypeCheck (input, &PyList_Type)) {
-    PyErr_SetString (PyExc_ValueError, "does not convert from list yet");
-    return NULL;
-  } else {
-    PyErr_SetString (PyExc_ValueError, "can only accept vector of float as input");
-    return NULL;
-  }
-
-  return vec;
-
-fail:
-  return NULL;
-}
 
 PyObject *
@@ -66,20 +8,72 @@
 }
 
-Py_cvec *
-PyAubio_CCvecToPyCvec (cvec_t * input) {
-  Py_cvec *vec = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
+int
+PyAubio_ArrayToCFvec (PyObject *input, fvec_t *out) {
+  if (input == NULL) {
+    PyErr_SetString (PyExc_ValueError, "input array is not a python object");
+    return 0;
+  }
+  // parsing input object into a Py_fvec
+  if (PyArray_Check(input)) {
+
+    // we got an array, convert it to an fvec
+    if (PyArray_NDIM ((PyArrayObject *)input) == 0) {
+      PyErr_SetString (PyExc_ValueError, "input array is a scalar");
+      return 0;
+    } else if (PyArray_NDIM ((PyArrayObject *)input) > 1) {
+      PyErr_SetString (PyExc_ValueError,
+          "input array has more than one dimensions");
+      return 0;
+    }
+
+    if (!PyArray_ISFLOAT ((PyArrayObject *)input)) {
+      PyErr_SetString (PyExc_ValueError, "input array should be float");
+      return 0;
+    } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) {
+      PyErr_SetString (PyExc_ValueError, "input array should be float32");
+      return 0;
+    }
+
+    // vec = new_fvec (vec->length);
+    // no need to really allocate fvec, just its struct member
+    long length = PyArray_SIZE ((PyArrayObject *)input);
+    if (length <= 0) {
+      PyErr_SetString (PyExc_ValueError, "input array size should be greater than 0");
+      return 0;
+    }
+
+  } else if (PyObject_TypeCheck (input, &PyList_Type)) {
+    PyErr_SetString (PyExc_ValueError, "does not convert from list yet");
+    return 0;
+  } else {
+    PyErr_SetString (PyExc_ValueError, "can only accept vector of float as input");
+    return 0;
+  }
+
+  out->length = (uint_t) PyArray_SIZE ((PyArrayObject *)input);
+  out->data = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)input, 0);
+  return 1;
+}
+
+PyObject *
+PyAubio_CCvecToPyCvec (cvec_t * input, Py_cvec *vec) {
   vec->length = input->length;
   vec->o = input;
+  // keep a reference to re-use after returning it
   Py_INCREF(vec);
-  return vec;
+  return (PyObject *)vec;
 }
 
-cvec_t *
-PyAubio_ArrayToCCvec (PyObject *input) {
+int
+PyAubio_ArrayToCCvec (PyObject *input, cvec_t *i) {
   if (PyObject_TypeCheck (input, &Py_cvecType)) {
-      return ((Py_cvec*)input)->o;
+      //*i = *(((Py_cvec*)input)->o);
+      i->norm = ((Py_cvec*)input)->o->norm;
+      i->phas = ((Py_cvec*)input)->o->phas;
+      i->length = ((Py_cvec*)input)->o->length;
+      return 1;
   } else {
       PyErr_SetString (PyExc_ValueError, "input array should be float32");
-      return NULL;
+      return 0;
   }
 }
@@ -102,12 +96,10 @@
 }
 
-fmat_t *
-PyAubio_ArrayToCFmat (PyObject *input) {
-  PyObject *array;
-  fmat_t *mat;
+int
+PyAubio_ArrayToCFmat (PyObject *input, fmat_t *mat) {
   uint_t i;
   if (input == NULL) {
     PyErr_SetString (PyExc_ValueError, "input array is not a python object");
-    goto fail;
+    return 0;
   }
   // parsing input object into a Py_fvec
@@ -117,55 +109,54 @@
     if (PyArray_NDIM ((PyArrayObject *)input) == 0) {
       PyErr_SetString (PyExc_ValueError, "input array is a scalar");
-      goto fail;
+      return 0;
     } else if (PyArray_NDIM ((PyArrayObject *)input) > 2) {
       PyErr_SetString (PyExc_ValueError,
           "input array has more than two dimensions");
-      goto fail;
+      return 0;
     }
 
     if (!PyArray_ISFLOAT ((PyArrayObject *)input)) {
       PyErr_SetString (PyExc_ValueError, "input array should be float");
-      goto fail;
+      return 0;
     } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) {
       PyErr_SetString (PyExc_ValueError, "input array should be float32");
-      goto fail;
-    } else {
-      // input data type is float32, nothing else to do
-      array = input;
+      return 0;
     }
 
     // no need to really allocate fvec, just its struct member
-    mat = (fmat_t *)malloc(sizeof(fmat_t));
-    long length = PyArray_DIM ((PyArrayObject *)array, 1);
-    if (length > 0) {
-      mat->length = (uint_t)length;
-    } else {
+    long length = PyArray_DIM ((PyArrayObject *)input, 1);
+    if (length <= 0) {
       PyErr_SetString (PyExc_ValueError, "input array dimension 1 should be greater than 0");
-      goto fail;
+      return 0;
     }
-    long height = PyArray_DIM ((PyArrayObject *)array, 0);
-    if (height > 0) {
-      mat->height = (uint_t)height;
-    } else {
+    long height = PyArray_DIM ((PyArrayObject *)input, 0);
+    if (height <= 0) {
       PyErr_SetString (PyExc_ValueError, "input array dimension 0 should be greater than 0");
-      goto fail;
-    }
-    mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height);
-    for (i=0; i< mat->height; i++) {
-      mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)array, i);
+      return 0;
     }
 
   } else if (PyObject_TypeCheck (input, &PyList_Type)) {
     PyErr_SetString (PyExc_ValueError, "can not convert list to fmat");
-    return NULL;
+    return 0;
   } else {
     PyErr_SetString (PyExc_ValueError, "can only accept matrix of float as input");
-    return NULL;
+    return 0;
   }
 
-  return mat;
+  if (mat->height != (uint_t)PyArray_DIM ((PyArrayObject *)input, 0)) {
+    /*
+    free(mat->data);
+    mat->height = (uint_t)PyArray_DIM ((PyArrayObject *)input, 0);
+    mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height);
+    */
+    PyErr_Format(PyExc_ValueError, "too many rows, %d but %ld expected",
+                      mat->height, PyArray_DIM ((PyArrayObject *)input, 0) );
+    return 0;
+  }
 
-fail:
-  return NULL;
+  mat->length = (uint_t)PyArray_DIM ((PyArrayObject *)input, 1);
+  for (i=0; i< mat->height; i++) {
+    mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)input, i);
+  }
+  return 1;
 }
-
