Ignore:
Timestamp:
Apr 24, 2016, 6:23:14 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
51b9c83
Parents:
a35db12
Message:

python/ext: simplify memory allocations, removed unneeded malloc/free calls

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/ext/aubiomodule.c

    ra35db12 r569b363  
    8484{
    8585  PyObject *input;
    86   fvec_t *vec;
     86  fvec_t vec;
    8787  smpl_t alpha;
    8888  PyObject *result;
     
    9696  }
    9797
    98   vec = (fvec_t *)malloc(sizeof(fvec_t));
    99   if (!PyAubio_ArrayToCFvec(input, vec)) {
    100     free(vec);
     98  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    10199    return NULL;
    102100  }
    103101
    104102  // compute the function
    105   result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha));
    106   free(vec);
     103  result = Py_BuildValue ("f", fvec_alpha_norm (&vec, alpha));
    107104  if (result == NULL) {
    108105    return NULL;
     
    176173{
    177174  PyObject *input;
    178   fvec_t *vec;
     175  fvec_t vec;
    179176  PyObject *result;
    180177
     
    187184  }
    188185
    189   vec = (fvec_t *)malloc(sizeof(fvec_t));
    190   if (!PyAubio_ArrayToCFvec(input, vec)) {
    191     free(vec);
     186  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    192187    return NULL;
    193188  }
    194189
    195190  // compute the function
    196   result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec));
    197   free(vec);
     191  result = Py_BuildValue ("f", aubio_zero_crossing_rate (&vec));
    198192  if (result == NULL) {
    199193    return NULL;
     
    207201{
    208202  PyObject *input;
    209   fvec_t *vec;
     203  fvec_t vec;
    210204
    211205  if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
     
    217211  }
    218212
    219   vec = (fvec_t *)malloc(sizeof(fvec_t));
    220   if (!PyAubio_ArrayToCFvec(input, vec)) {
    221     free(vec);
     213  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    222214    return NULL;
    223215  }
    224216
    225217  // compute the function
    226   fvec_min_removal (vec);
     218  fvec_min_removal (&vec);
    227219
    228220  // since this function does not return, we could return None
    229221  //Py_RETURN_NONE;
    230222  // however it is convenient to return the modified vector
    231   return (PyObject *) PyAubio_CFvecToArray(vec);
     223  return (PyObject *) PyAubio_CFvecToArray(&vec);
    232224  // or even without converting it back to an array
    233225  //Py_INCREF(vec);
Note: See TracChangeset for help on using the changeset viewer.