comparison 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
comparison
equal deleted inserted replaced
747:fbf16508421f 748:e5f96902afaf
681 dims=1; 681 dims=1;
682 shape[0]= 2 * ins->nvectors; 682 shape[0]= 2 * ins->nvectors;
683 data = ins->times; 683 data = ins->times;
684 } 684 }
685 685
686 outgoing = PyArray_SimpleNewFromData(dims, shape, NPY_DOUBLE, data); 686 outgoing = PyArray_SimpleNew(dims, shape, NPY_DOUBLE);
687 free(status);
688 free(ins); // free the malloced adb_datum_t structure though
689
690 if (!outgoing){ 687 if (!outgoing){
688 free(status);
689 free(ins); // free the malloced adb_datum_t structure though
690 Py_XDECREF(outgoing);
691 PyErr_SetString(PyExc_TypeError, "Failed to convert retrieved datum to C-Array"); 691 PyErr_SetString(PyExc_TypeError, "Failed to convert retrieved datum to C-Array");
692 return NULL; 692 return NULL;
693 } 693 }
694 // Apprently Python automatically INCREFs the data pointer, so we don't have to call 694
695 // audiodb_free_datum(current_db, ins); 695 /* Copy the data, this allows us to free the allocated memory and let
696 696 * python do the subsequent garbage collection itself.
697 */
698 int num_items = ins->nvectors * ins->dim;
699 double* p = (double*) PyArray_DATA(outgoing);
700 double* d = data;
701 while(num_items--)
702 *p++ = *d++;
703 audiodb_free_datum(current_db, ins); // free the source audiodb_datum
704 free(status); // free the malloced status object
705 free(ins); // free the malloced adb_datum_t structure though
697 return outgoing; 706 return outgoing;
698 } 707 }
699 708
700 709
701 /* close a database */ 710 /* close a database */