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/aubioproxy.c

    ra35db12 r569b363  
    144144  }
    145145
    146   if (mat->height != (uint_t)PyArray_DIM ((PyArrayObject *)input, 0)) {
    147     /*
    148     free(mat->data);
    149     mat->height = (uint_t)PyArray_DIM ((PyArrayObject *)input, 0);
    150     mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height);
    151     */
    152     PyErr_Format(PyExc_ValueError, "too many rows, %d but %ld expected",
    153                       mat->height, PyArray_DIM ((PyArrayObject *)input, 0) );
    154     return 0;
     146  uint_t new_height = (uint_t)PyArray_DIM ((PyArrayObject *)input, 0);
     147  if (mat->height != new_height) {
     148    if (mat->data) {
     149      free(mat->data);
     150    }
     151    mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * new_height);
    155152  }
    156153
     154  mat->height = new_height;
    157155  mat->length = (uint_t)PyArray_DIM ((PyArrayObject *)input, 1);
    158156  for (i=0; i< mat->height; i++) {
Note: See TracChangeset for help on using the changeset viewer.