History

python/: use Py_RETURN_NONE, fixing a memory bug triggered after opening many sinks

Paul Brossier committed 13 years ago

Commit 9e6695d1 parent 90a8f2f5 files · +21 −12Browse files

Showing the changes to python (5 of 5 files). Show all

Unified · Split

5 files
  1. python/ext/aubiomodule.c +1 −1
  2. python/ext/py-filter.c +3 −3
  3. python/ext/py-filterbank.c +3 −3
  4. python/gen_pyobject.py +2 −2
  5. python/tests/test_sink.py +12 −3
python/ext/aubiomodule.c+1−1
@@ -164,7 +164,7 @@ Py_min_removal(PyObject * self, PyObject * args) · 163 unmodified lines
164164 fvec_min_removal (vec);
165165
166166 // since this function does not return, we could return None
167− //return Py_None;
167+ //Py_RETURN_NONE;
168168 // however it is convenient to return the modified vector
169169 return (PyObject *) PyAubio_CFvecToArray(vec);
170170 // or even without converting it back to an array
python/ext/py-filter.c+3−3
@@ -99,7 +99,7 @@ Py_filter_set_c_weighting (Py_filter * self, PyObject *args) · 98 unmodified lines
9999 "error when setting filter to C-weighting");
100100 return NULL;
101101 }
102− return Py_None;
102+ Py_RETURN_NONE;
103103 }
104104
105105 static PyObject *
@@ -117,7 +117,7 @@ Py_filter_set_a_weighting (Py_filter * self, PyObject *args) · 11 unmodified lines
117117 "error when setting filter to A-weighting");
118118 return NULL;
119119 }
120− return Py_None;
120+ Py_RETURN_NONE;
121121 }
122122
123123 static PyObject *
@@ -135,7 +135,7 @@ Py_filter_set_biquad(Py_filter * self, PyObject *args) · 11 unmodified lines
135135 "error when setting filter with biquad coefficients");
136136 return NULL;
137137 }
138− return Py_None;
138+ Py_RETURN_NONE;
139139 }
140140
141141 static PyMemberDef Py_filter_members[] = {
python/ext/py-filterbank.c+3−3
@@ -109,7 +109,7 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) · 108 unmodified lines
109109 "error when setting filter to A-weighting");
110110 return NULL;
111111 }
112− return Py_None;
112+ Py_RETURN_NONE;
113113 }
114114
115115 static PyObject *
@@ -128,7 +128,7 @@ Py_filterbank_set_mel_coeffs_slaney (Py_filterbank * self, PyObject *args) · 12 unmodified lines
128128 "error when setting filter to A-weighting");
129129 return NULL;
130130 }
131− return Py_None;
131+ Py_RETURN_NONE;
132132 }
133133
134134 static PyObject *
@@ -158,7 +158,7 @@ Py_filterbank_set_coeffs (Py_filterbank * self, PyObject *args) · 23 unmodified lines
158158 "error when setting filter coefficients");
159159 return NULL;
160160 }
161− return Py_None;
161+ Py_RETURN_NONE;
162162 }
163163
164164 static PyObject *
python/gen_pyobject.py+2−2
@@ -342,7 +342,7 @@ def gen_do_output_params(outputparams, name): · 341 unmodified lines
342342 else:
343343 returnval += " return (PyObject *)" + aubiovectopyobj[p['type']] + " (" + p['name'] + ")"
344344 else:
345− returnval = " return Py_None;";
345+ returnval += " Py_RETURN_NONE"
346346 # end of output strings
347347 return outputvecs, outputcreate, returnval
348348
@@ -473,7 +473,7 @@ Py%(funcname)s (Py_%(objname)s *self, PyObject *args) · 124 unmodified lines
473473 "error running %(funcname)s");
474474 return NULL;
475475 }
476− return Py_None;
476+ Py_RETURN_NONE;
477477 }
478478 """ % {'funcname': method_name, 'objname': name,
479479 'out_type': out_type, 'setter_args': setter_args, 'parse_args': parse_args }
python/tests/test_sink.py+12−3
@@ -13,6 +13,15 @@ class aubio_sink_test_case(TestCase): · 12 unmodified lines
1313 def setUp(self):
1414 if not len(list_of_sounds): self.skipTest('add some sound files in \'python/tests/sounds\'')
1515
16+ def test_many_sinks(self):
17+ for i in range(100):
18+ g = sink('/tmp/f.wav', 0)
19+ write = 256
20+ for n in range(200):
21+ vec = fvec(write)
22+ g(vec, write)
23+ del g
24+
1625 def test_read(self):
1726 for path in list_of_sounds:
1827 for samplerate, hop_size in zip([0, 44100, 8000, 32000], [512, 1024, 64, 256]):
@@ -30,8 +39,8 @@ class aubio_sink_test_case(TestCase): · 11 unmodified lines
3039 print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
3140 print "from", f.uri,
3241 print "to", g.uri
42+ #del f, g
3343
3444 if __name__ == '__main__':
35− from unittest import main
36− main()
37−
45+ from unittest import main
46+ main()

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