Mercurial > hg > audiodb
diff bindings/python/pyadbmodule.c @ 748:e5f96902afaf
Added wrappers for liszt, retrieve_datum, solved Py_XDECREF by copying source data and freeing retrieved memory
author | mas01mc |
---|---|
date | Mon, 22 Nov 2010 17:58:27 +0000 |
parents | fbf16508421f |
children | dd4b9fec8d85 |
line wrap: on
line diff
--- a/bindings/python/pyadbmodule.c Sat Nov 20 15:32:58 2010 +0000 +++ b/bindings/python/pyadbmodule.c Mon Nov 22 17:58:27 2010 +0000 @@ -683,17 +683,26 @@ data = ins->times; } - outgoing = PyArray_SimpleNewFromData(dims, shape, NPY_DOUBLE, data); - free(status); - free(ins); // free the malloced adb_datum_t structure though - + outgoing = PyArray_SimpleNew(dims, shape, NPY_DOUBLE); if (!outgoing){ + free(status); + free(ins); // free the malloced adb_datum_t structure though + Py_XDECREF(outgoing); PyErr_SetString(PyExc_TypeError, "Failed to convert retrieved datum to C-Array"); return NULL; - } - // Apprently Python automatically INCREFs the data pointer, so we don't have to call - // audiodb_free_datum(current_db, ins); + } + /* Copy the data, this allows us to free the allocated memory and let + * python do the subsequent garbage collection itself. + */ + int num_items = ins->nvectors * ins->dim; + double* p = (double*) PyArray_DATA(outgoing); + double* d = data; + while(num_items--) + *p++ = *d++; + audiodb_free_datum(current_db, ins); // free the source audiodb_datum + free(status); // free the malloced status object + free(ins); // free the malloced adb_datum_t structure though return outgoing; }