History

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

Paul Brossier committed 10 years ago

Commit de81d2b1 parent 202697a1 file · +35 −14Browse files

Showing the changes to python/ext (1 of 1 file). Show all

Unified · Split

python/ext/py-fft.c+35−14
@@ -2,7 +2,14 @@ · 1 unmodified line
22
33 static char Py_fft_doc[] = "fft object";
44
5−AUBIO_DECLARE(fft, uint_t win_s)
5+typedef struct
6+{
7+ PyObject_HEAD
8+ aubio_fft_t * o;
9+ uint_t win_s;
10+ cvec_t *out;
11+ fvec_t *rout;
12+} Py_fft;
613
714 //AUBIO_NEW(fft)
815 static PyObject *
@@ -36,17 +43,36 @@ Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds) · 27 unmodified lines
3643 return (PyObject *) self;
3744 }
3845
46+static int
47+Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds)
48+{
49+ self->o = new_aubio_fft (self->win_s);
50+ if (self->o == NULL) {
51+ char_t errstr[30];
52+ sprintf(errstr, "error creating fft with win_s=%d", self->win_s);
53+ PyErr_SetString (PyExc_StandardError, errstr);
54+ return -1;
55+ }
56+ self->out = new_cvec(self->win_s);
57+ self->rout = new_fvec(self->win_s);
3958
40−AUBIO_INIT(fft, self->win_s)
59+ return 0;
60+}
4161
42−AUBIO_DEL(fft)
62+static void
63+Py_fft_del (Py_fft *self, PyObject *unused)
64+{
65+ del_aubio_fft(self->o);
66+ del_cvec(self->out);
67+ del_fvec(self->rout);
68+ self->ob_type->tp_free((PyObject *) self);
69+}
4370
4471 static PyObject *
45−Py_fft_do(PyObject * self, PyObject * args)
72+Py_fft_do(Py_fft * self, PyObject * args)
4673 {
4774 PyObject *input;
4875 fvec_t *vec;
49− cvec_t *output;
5076
5177 if (!PyArg_ParseTuple (args, "O", &input)) {
5278 return NULL;
@@ -58,11 +84,9 @@ Py_fft_do(PyObject * self, PyObject * args) · 5 unmodified lines
5884 return NULL;
5985 }
6086
61− output = new_cvec(((Py_fft *) self)->win_s);
62−
6387 // compute the function
64− aubio_fft_do (((Py_fft *)self)->o, vec, output);
65− return (PyObject *)PyAubio_CCvecToPyCvec(output);
88+ aubio_fft_do (((Py_fft *)self)->o, vec, self->out);
89+ return (PyObject *)PyAubio_CCvecToPyCvec(self->out);
6690 }
6791
6892 AUBIO_MEMBERS_START(fft)
@@ -75,7 +99,6 @@ Py_fft_rdo(Py_fft * self, PyObject * args) · 6 unmodified lines
7599 {
76100 PyObject *input;
77101 cvec_t *vec;
78− fvec_t *output;
79102
80103 if (!PyArg_ParseTuple (args, "O", &input)) {
81104 return NULL;
@@ -87,11 +110,9 @@ Py_fft_rdo(Py_fft * self, PyObject * args) · 5 unmodified lines
87110 return NULL;
88111 }
89112
90− output = new_fvec(self->win_s);
91−
92113 // compute the function
93− aubio_fft_rdo (((Py_fft *)self)->o, vec, output);
94− return (PyObject *)PyAubio_CFvecToArray(output);
114+ aubio_fft_rdo (((Py_fft *)self)->o, vec, self->rout);
115+ return (PyObject *)PyAubio_CFvecToArray(self->rout);
95116 }
96117
97118 static PyMethodDef Py_fft_methods[] = {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t