projects
/
aubio.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
34e753c
)
python/lib/gen_code.py: add input size checks (see #63)
author
Paul Brossier
<piem@piem.org>
Tue, 12 Jul 2016 18:17:12 +0000
(20:17 +0200)
committer
Paul Brossier
<piem@piem.org>
Tue, 12 Jul 2016 18:17:12 +0000
(20:17 +0200)
python/lib/gen_code.py
patch
|
blob
|
history
diff --git
a/python/lib/gen_code.py
b/python/lib/gen_code.py
index
b602b6d
..
1f9b9dc
100644
(file)
--- a/
python/lib/gen_code.py
+++ b/
python/lib/gen_code.py
@@
-84,6
+84,17
@@
objoutsize = {
'tss': 'self->hop_size',
}
'tss': 'self->hop_size',
}
+objinputsize = {
+ 'mfcc': 'self->buf_size / 2 + 1',
+ 'notes': 'self->hop_size',
+ 'onset': 'self->hop_size',
+ 'pitch': 'self->hop_size',
+ 'sampler': 'self->hop_size',
+ 'specdesc': 'self->buf_size / 2 + 1',
+ 'tempo': 'self->hop_size',
+ 'wavetable': 'self->hop_size',
+ }
+
def get_name(proto):
name = proto.replace(' *', '* ').split()[1].split('(')[0]
name = name.replace('*','')
def get_name(proto):
name = proto.replace(' *', '* ').split()[1].split('(')[0]
name = name.replace('*','')
@@
-377,7
+388,17
@@
Py_{shortname}_do (Py_{shortname} * self, PyObject * args)
if (!{pytoaubio}(py_{0[name]}, &(self->{0[name]}))) {{
return NULL;
}}""".format(input_param, pytoaubio = pytoaubio_fn[input_param['type']])
if (!{pytoaubio}(py_{0[name]}, &(self->{0[name]}))) {{
return NULL;
}}""".format(input_param, pytoaubio = pytoaubio_fn[input_param['type']])
- out += """
+ if self.shortname in objinputsize:
+ out += """
+
+ if (self->{0[name]}.length != {expected_size}) {{
+ PyErr_Format (PyExc_ValueError,
+ "input size of {shortname} should be %d, not %d",
+ {expected_size}, self->{0[name]}.length);
+ return NULL;
+ }}""".format(input_param, expected_size = objinputsize[self.shortname], **self.__dict__)
+ else:
+ out += """
// TODO: check input sizes"""
for output_param in output_params:
// TODO: check input sizes"""
for output_param in output_params: