From 9e6695dca9069ab4e93079152607fd698f404677 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 7 Mar 2013 21:52:01 -0500 Subject: [PATCH] python/: use Py_RETURN_NONE, fixing a memory bug triggered after opening many sinks --- python/ext/aubiomodule.c | 2 +- python/ext/py-filter.c | 6 +++--- python/ext/py-filterbank.c | 6 +++--- python/gen_pyobject.py | 4 ++-- python/tests/test_sink.py | 15 ++++++++++++--- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/python/ext/aubiomodule.c b/python/ext/aubiomodule.c index 3f3ee277..5afcee56 100644 --- a/python/ext/aubiomodule.c +++ b/python/ext/aubiomodule.c @@ -164,7 +164,7 @@ Py_min_removal(PyObject * self, PyObject * args) fvec_min_removal (vec); // since this function does not return, we could return None - //return Py_None; + //Py_RETURN_NONE; // however it is convenient to return the modified vector return (PyObject *) PyAubio_CFvecToArray(vec); // or even without converting it back to an array diff --git a/python/ext/py-filter.c b/python/ext/py-filter.c index 5b9fee64..416bba83 100644 --- a/python/ext/py-filter.c +++ b/python/ext/py-filter.c @@ -99,7 +99,7 @@ Py_filter_set_c_weighting (Py_filter * self, PyObject *args) "error when setting filter to C-weighting"); return NULL; } - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -117,7 +117,7 @@ Py_filter_set_a_weighting (Py_filter * self, PyObject *args) "error when setting filter to A-weighting"); return NULL; } - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -135,7 +135,7 @@ Py_filter_set_biquad(Py_filter * self, PyObject *args) "error when setting filter with biquad coefficients"); return NULL; } - return Py_None; + Py_RETURN_NONE; } static PyMemberDef Py_filter_members[] = { diff --git a/python/ext/py-filterbank.c b/python/ext/py-filterbank.c index cc0da481..60e5c5d2 100644 --- a/python/ext/py-filterbank.c +++ b/python/ext/py-filterbank.c @@ -109,7 +109,7 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) "error when setting filter to A-weighting"); return NULL; } - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -128,7 +128,7 @@ Py_filterbank_set_mel_coeffs_slaney (Py_filterbank * self, PyObject *args) "error when setting filter to A-weighting"); return NULL; } - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -158,7 +158,7 @@ Py_filterbank_set_coeffs (Py_filterbank * self, PyObject *args) "error when setting filter coefficients"); return NULL; } - return Py_None; + Py_RETURN_NONE; } static PyObject * diff --git a/python/gen_pyobject.py b/python/gen_pyobject.py index 20f4534a..91c427ac 100644 --- a/python/gen_pyobject.py +++ b/python/gen_pyobject.py @@ -342,7 +342,7 @@ def gen_do_output_params(outputparams, name): else: returnval += " return (PyObject *)" + aubiovectopyobj[p['type']] + " (" + p['name'] + ")" else: - returnval = " return Py_None;"; + returnval += " Py_RETURN_NONE" # end of output strings return outputvecs, outputcreate, returnval @@ -473,7 +473,7 @@ Py%(funcname)s (Py_%(objname)s *self, PyObject *args) "error running %(funcname)s"); return NULL; } - return Py_None; + Py_RETURN_NONE; } """ % {'funcname': method_name, 'objname': name, 'out_type': out_type, 'setter_args': setter_args, 'parse_args': parse_args } diff --git a/python/tests/test_sink.py b/python/tests/test_sink.py index f0104d11..033ba546 100755 --- a/python/tests/test_sink.py +++ b/python/tests/test_sink.py @@ -13,6 +13,15 @@ class aubio_sink_test_case(TestCase): def setUp(self): if not len(list_of_sounds): self.skipTest('add some sound files in \'python/tests/sounds\'') + def test_many_sinks(self): + for i in range(100): + g = sink('/tmp/f.wav', 0) + write = 256 + for n in range(200): + vec = fvec(write) + g(vec, write) + del g + def test_read(self): for path in list_of_sounds: for samplerate, hop_size in zip([0, 44100, 8000, 32000], [512, 1024, 64, 256]): @@ -30,8 +39,8 @@ class aubio_sink_test_case(TestCase): print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")", print "from", f.uri, print "to", g.uri + #del f, g if __name__ == '__main__': - from unittest import main - main() - + from unittest import main + main() -- 2.26.2