out += """ err = aubio_{shortname}_set_{param} (self->o {paramlist}); if (err > 0) {{ if (PyErr_Occurred() == NULL) {{ PyErr_SetString (PyExc_ValueError, "error running aubio_{shortname}_set_{param}"); }} else {{ // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); PyErr_Restore(PyExc_ValueError, value, traceback); }} return NULL; }} Py_RETURN_NONE;}}""".format(param = param, refs = refs, paramdecls = paramdecls, pyparamtypes = pyparamtypes, paramlist = paramlist, **self.__dict__) return out def gen_get(self): out = """// {shortname} getters""".format(**self.__dict__) for method in self.prototypes['get']: params = get_params_types_names(method) method_name = get_name(method) assert len(params) == 1, \ "get method has more than one parameter %s" % params param = method_name.split('aubio_'+self.shortname+'_get_')[-1] paramtype = get_return_type(method) ptypeconv = pyfromtype_fn[paramtype] out += """static PyObject *Pyaubio_{shortname}_get_{param} (Py_{shortname} *self, PyObject *unused){{ {ptype} {param} = aubio_{shortname}_get_{param} (self->o); return (PyObject *){ptypeconv} ({param});}}""".format(param = param, ptype = paramtype, ptypeconv = ptypeconv, **self.__dict__) return out def gen_methodef(self): out = """static PyMethodDef Py_{shortname}_methods[] = {{""".format(**self.__dict__) for m in self.prototypes['set']: name = get_name(m) shortname = name.replace('aubio_%s_' % self.shortname, '') out += """ {{"{shortname}", (PyCFunction) Py{name}, METH_VARARGS, ""}},""".format(name = name, shortname = shortname) for m in self.prototypes['get']: name = get_name(m) shortname = name.replace('aubio_%s_' % self.shortname, '') out += """ {{"{shortname}", (PyCFunction) Py{name}, METH_NOARGS, ""}},""".format(name = name, shortname = shortname) for m in self.prototypes['rdo']: name = get_name(m) shortname = name.replace('aubio_%s_' % self.shortname, '') out += """ {{"{shortname}", (PyCFunction) Py{name}, METH_VARARGS, ""}},""".format(name = name, shortname = shortname) out += """ {NULL} /* sentinel */};""" return out def gen_typeobject(self): return """PyTypeObject Py_{shortname}Type = {{ //PyObject_HEAD_INIT (NULL) //0, PyVarObject_HEAD_INIT (NULL, 0) "aubio.{shortname}", sizeof (Py_{shortname}), 0, (destructor) Py_{shortname}_del, 0, 0, 0, 0, 0, 0, 0, 0, 0, (ternaryfunc)Pyaubio_{shortname}_do, 0, 0, 0, 0, Py_TPFLAGS_DEFAULT, Py_{shortname}_doc, 0, 0, 0, 0, 0, 0, Py_{shortname}_methods, Py_{shortname}_members, 0, 0, 0, 0, 0, 0, (initproc) Py_{shortname}_init, 0, Py_{shortname}_new, 0, 0, 0, 0, 0, 0, 0, 0, 0,}};""".format(**self.__dict__)Lines 501–625 of 625. Previous lines
out += """ err = aubio_{shortname}_set_{param} (self->o {paramlist}); if (err > 0) {{ if (PyErr_Occurred() == NULL) {{ PyErr_SetString (PyExc_ValueError, "error running aubio_{shortname}_set_{param}"); }} else {{ // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); PyErr_Restore(PyExc_ValueError, value, traceback); }} return NULL; }} Py_RETURN_NONE; }} """.format(param = param, refs = refs, paramdecls = paramdecls, pyparamtypes = pyparamtypes, paramlist = paramlist, **self.__dict__) return out def gen_get(self): out = """ // {shortname} getters """.format(**self.__dict__) for method in self.prototypes['get']: params = get_params_types_names(method) method_name = get_name(method) assert len(params) == 1, \ "get method has more than one parameter %s" % params param = method_name.split('aubio_'+self.shortname+'_get_')[-1] paramtype = get_return_type(method) ptypeconv = pyfromtype_fn[paramtype] out += """ static PyObject * Pyaubio_{shortname}_get_{param} (Py_{shortname} *self, PyObject *unused) {{ {ptype} {param} = aubio_{shortname}_get_{param} (self->o); return (PyObject *){ptypeconv} ({param}); }} """.format(param = param, ptype = paramtype, ptypeconv = ptypeconv, **self.__dict__) return out def gen_methodef(self): out = """ static PyMethodDef Py_{shortname}_methods[] = {{""".format(**self.__dict__) for m in self.prototypes['set']: name = get_name(m) shortname = name.replace('aubio_%s_' % self.shortname, '') out += """ {{"{shortname}", (PyCFunction) Py{name}, METH_VARARGS, ""}},""".format(name = name, shortname = shortname) for m in self.prototypes['get']: name = get_name(m) shortname = name.replace('aubio_%s_' % self.shortname, '') out += """ {{"{shortname}", (PyCFunction) Py{name}, METH_NOARGS, ""}},""".format(name = name, shortname = shortname) for m in self.prototypes['rdo']: name = get_name(m) shortname = name.replace('aubio_%s_' % self.shortname, '') out += """ {{"{shortname}", (PyCFunction) Py{name}, METH_VARARGS, ""}},""".format(name = name, shortname = shortname) out += """ {NULL} /* sentinel */ }; """ return out def gen_typeobject(self): return """ PyTypeObject Py_{shortname}Type = {{ //PyObject_HEAD_INIT (NULL) //0, PyVarObject_HEAD_INIT (NULL, 0) "aubio.{shortname}", sizeof (Py_{shortname}), 0, (destructor) Py_{shortname}_del, 0, 0, 0, 0, 0, 0, 0, 0, 0, (ternaryfunc)Pyaubio_{shortname}_do, 0, 0, 0, 0, Py_TPFLAGS_DEFAULT, Py_{shortname}_doc, 0, 0, 0, 0, 0, 0, Py_{shortname}_methods, Py_{shortname}_members, 0, 0, 0, 0, 0, 0, (initproc) Py_{shortname}_init, 0, Py_{shortname}_new, 0, 0, 0, 0, 0, 0, 0, 0, 0, }}; """.format(**self.__dict__)