From: Paul Brossier Date: Tue, 12 Jul 2016 18:17:12 +0000 (+0200) Subject: python/lib/gen_code.py: add input size checks (see #63) X-Git-Tag: 0.4.4~292 X-Git-Url: https://git.aubio.org/?p=aubio.git;a=commitdiff_plain;h=bf54364819ceb94d388bce516855566b3f1fe10d python/lib/gen_code.py: add input size checks (see #63) --- diff --git a/python/lib/gen_code.py b/python/lib/gen_code.py index b602b6d5..1f9b9dc2 100644 --- a/python/lib/gen_code.py +++ b/python/lib/gen_code.py @@ -84,6 +84,17 @@ objoutsize = { '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('*','') @@ -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']]) - 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: