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/py-fft.c (1 of 1 file). Show all

Unified · Split

python/ext/py-fft.c+35−14
@@ -2,7 +2,14 @@ · 1 unmodified line
2 2
3static char Py_fft_doc[] = "fft object";3static char Py_fft_doc[] = "fft object";
4 4
5AUBIO_DECLARE(fft, uint_t win_s)5typedef 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;
6 13
7//AUBIO_NEW(fft)14//AUBIO_NEW(fft)
8static PyObject *15static PyObject *
@@ -36,17 +43,36 @@ Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds) · 27 unmodified lines
36 return (PyObject *) self;43 return (PyObject *) self;
37}44}
38 45
46static int
47Py_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);
39 58
40AUBIO_INIT(fft, self->win_s)59 return 0;
60}
41 61
42AUBIO_DEL(fft)62static void
63Py_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}
43 70
44static PyObject * 71static PyObject *
45Py_fft_do(PyObject * self, PyObject * args)72Py_fft_do(Py_fft * self, PyObject * args)
46{73{
47 PyObject *input;74 PyObject *input;
48 fvec_t *vec;75 fvec_t *vec;
49 cvec_t *output;
50 76
51 if (!PyArg_ParseTuple (args, "O", &input)) {77 if (!PyArg_ParseTuple (args, "O", &input)) {
52 return NULL;78 return NULL;
@@ -58,11 +84,9 @@ Py_fft_do(PyObject * self, PyObject * args) · 5 unmodified lines
58 return NULL;84 return NULL;
59 }85 }
60 86
61 output = new_cvec(((Py_fft *) self)->win_s);
62
63 // compute the function87 // compute the function
64 aubio_fft_do (((Py_fft *)self)->o, vec, output);88 aubio_fft_do (((Py_fft *)self)->o, vec, self->out);
65 return (PyObject *)PyAubio_CCvecToPyCvec(output);89 return (PyObject *)PyAubio_CCvecToPyCvec(self->out);
66}90}
67 91
68AUBIO_MEMBERS_START(fft) 92AUBIO_MEMBERS_START(fft)
@@ -75,7 +99,6 @@ Py_fft_rdo(Py_fft * self, PyObject * args) · 6 unmodified lines
75{99{
76 PyObject *input;100 PyObject *input;
77 cvec_t *vec;101 cvec_t *vec;
78 fvec_t *output;
79 102
80 if (!PyArg_ParseTuple (args, "O", &input)) {103 if (!PyArg_ParseTuple (args, "O", &input)) {
81 return NULL;104 return NULL;
@@ -87,11 +110,9 @@ Py_fft_rdo(Py_fft * self, PyObject * args) · 5 unmodified lines
87 return NULL;110 return NULL;
88 }111 }
89 112
90 output = new_fvec(self->win_s);
91
92 // compute the function113 // compute the function
93 aubio_fft_rdo (((Py_fft *)self)->o, vec, output);114 aubio_fft_rdo (((Py_fft *)self)->o, vec, self->rout);
94 return (PyObject *)PyAubio_CFvecToArray(output);115 return (PyObject *)PyAubio_CFvecToArray(self->rout);
95}116}
96 117
97static PyMethodDef Py_fft_methods[] = {118static 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