Changeset 59cb451 for python/ext


Ignore:
Timestamp:
Apr 18, 2016, 8:31:20 PM (9 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:
202697a
Parents:
a28dab6
Message:

ext/py-filterbank.c: continue fixing memory leak (#49)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/ext/py-filterbank.c

    ra28dab6 r59cb451  
    33static char Py_filterbank_doc[] = "filterbank object";
    44
    5 AUBIO_DECLARE(filterbank, uint_t n_filters; uint_t win_s)
     5typedef struct
     6{
     7  PyObject_HEAD
     8  aubio_filterbank_t * o;
     9  uint_t n_filters;
     10  uint_t win_s;
     11  fvec_t *out;
     12} Py_filterbank;
    613
    714//AUBIO_NEW(filterbank)
     
    4552}
    4653
    47 
    48 AUBIO_INIT(filterbank, self->n_filters, self->win_s)
    49 
    50 AUBIO_DEL(filterbank)
     54static int
     55Py_filterbank_init (Py_filterbank * self, PyObject * args, PyObject * kwds)
     56{
     57  self->o = new_aubio_filterbank (self->n_filters, self->win_s);
     58  if (self->o == NULL) {
     59    char_t errstr[30];
     60    sprintf(errstr, "error creating filterbank with n_filters=%d, win_s=%d",
     61        self->n_filters, self->win_s);
     62    PyErr_SetString (PyExc_StandardError, errstr);
     63    return -1;
     64  }
     65  self->out = new_fvec(self->n_filters);
     66
     67  return 0;
     68}
     69
     70static void
     71Py_filterbank_del (Py_filterbank *self, PyObject *unused)
     72{
     73  del_aubio_filterbank(self->o);
     74  del_fvec(self->out);
     75  self->ob_type->tp_free((PyObject *) self);
     76}
    5177
    5278static PyObject *
     
    5581  PyObject *input;
    5682  cvec_t *vec;
    57   fvec_t *out;
    5883
    5984  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    6792  }
    6893
    69   out = new_fvec (self->n_filters);
    70 
    7194  // compute the function
    72   aubio_filterbank_do (self->o, vec, out);
    73   return (PyObject *)PyAubio_CFvecToArray(out);
     95  aubio_filterbank_do (self->o, vec, self->out);
     96  return (PyObject *)PyAubio_CFvecToArray(self->out);
    7497}
    7598
Note: See TracChangeset for help on using the changeset viewer.