Changes in python/lib/gen_code.py [ce79a9e:6342fd1]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/gen_code.py
rce79a9e r6342fd1 3 3 'buf_size': 'Py_default_vector_length', 4 4 'win_s': 'Py_default_vector_length', 5 'size': 'Py_default_vector_length', 5 6 # and here too 6 7 'hop_size': 'Py_default_vector_length / 2', … … 83 84 'filterbank': 'self->n_filters', 84 85 'tss': 'self->buf_size', 86 'dct': 'self->size', 85 87 } 86 88 … … 177 179 self.do_outputs = get_params_types_names(self.do_proto)[2:] 178 180 struct_output_str = ["PyObject *{0[name]}; {1} c_{0[name]}".format(i, i['type'][:-1]) for i in self.do_outputs] 181 if len(self.prototypes['rdo']): 182 rdo_outputs = get_params_types_names(prototypes['rdo'][0])[2:] 183 struct_output_str += ["PyObject *{0[name]}; {1} c_{0[name]}".format(i, i['type'][:-1]) for i in rdo_outputs] 184 self.outputs += rdo_outputs 179 185 self.struct_outputs = ";\n ".join(struct_output_str) 180 186 … … 191 197 out += self.gen_del() 192 198 out += self.gen_do() 199 if len(self.prototypes['rdo']): 200 self.do_proto = self.prototypes['rdo'][0] 201 self.do_inputs = [get_params_types_names(self.do_proto)[1]] 202 self.do_outputs = get_params_types_names(self.do_proto)[2:] 203 out += self.gen_do(method='rdo') 193 204 out += self.gen_memberdef() 194 205 out += self.gen_set() … … 221 232 222 233 def gen_doc(self): 223 out = """ 224 // TODO: add documentation 225 static char Py_{shortname}_doc[] = \"undefined\"; 234 sig = [] 235 for p in self.input_params: 236 name = p['name'] 237 defval = aubiodefvalue[name].replace('"','\\\"') 238 sig.append("{name}={defval}".format(defval=defval, name=name)) 239 out = """ 240 #ifndef PYAUBIO_{shortname}_doc 241 #define PYAUBIO_{shortname}_doc "{shortname}({sig})" 242 #endif /* PYAUBIO_{shortname}_doc */ 243 244 static char Py_{shortname}_doc[] = "" 245 PYAUBIO_{shortname}_doc 246 ""; 226 247 """ 227 return out.format( **self.__dict__)248 return out.format(sig=', '.join(sig), **self.__dict__) 228 249 229 250 def gen_new(self): … … 371 392 return out 372 393 373 def gen_do(self ):394 def gen_do(self, method = 'do'): 374 395 out = """ 375 396 // do {shortname} 376 397 static PyObject* 377 Py _{shortname}_do(Py_{shortname} * self, PyObject * args)378 {{""".format( **self.__dict__)398 Pyaubio_{shortname}_{method} (Py_{shortname} * self, PyObject * args) 399 {{""".format(method = method, **self.__dict__) 379 400 input_params = self.do_inputs 380 401 output_params = self.do_outputs … … 452 473 """.format(**self.__dict__) 453 474 for set_param in self.prototypes['set']: 454 params = get_params_types_names(set_param)[1] 455 paramtype = params['type'] 475 params = get_params_types_names(set_param)[1:] 476 param = self.shortname.split('_set_')[-1] 477 paramdecls = "".join([""" 478 {0} {1};""".format(p['type'], p['name']) for p in params]) 456 479 method_name = get_name(set_param) 457 480 param = method_name.split('aubio_'+self.shortname+'_set_')[-1] 458 pyparamtype = pyargparse_chars[paramtype] 481 refs = ", ".join(["&%s" % p['name'] for p in params]) 482 paramlist = ", ".join(["%s" % p['name'] for p in params]) 483 if len(params): 484 paramlist = "," + paramlist 485 pyparamtypes = ''.join([pyargparse_chars[p['type']] for p in params]) 459 486 out += """ 460 487 static PyObject * … … 462 489 {{ 463 490 uint_t err = 0; 464 {paramtype} {param}; 465 466 if (!PyArg_ParseTuple (args, "{pyparamtype}", &{param})) {{ 491 {paramdecls} 492 """.format(param = param, paramdecls = paramdecls, **self.__dict__) 493 494 if len(refs) and len(pyparamtypes): 495 out += """ 496 497 if (!PyArg_ParseTuple (args, "{pyparamtypes}", {refs})) {{ 467 498 return NULL; 468 499 }} 469 err = aubio_{shortname}_set_{param} (self->o, {param}); 500 """.format(pyparamtypes = pyparamtypes, refs = refs) 501 502 out += """ 503 err = aubio_{shortname}_set_{param} (self->o {paramlist}); 470 504 471 505 if (err > 0) {{ 472 PyErr_SetString (PyExc_ValueError, "error running aubio_{shortname}_set_{param}"); 506 if (PyErr_Occurred() == NULL) {{ 507 PyErr_SetString (PyExc_ValueError, "error running aubio_{shortname}_set_{param}"); 508 }} else {{ 509 // change the RuntimeError into ValueError 510 PyObject *type, *value, *traceback; 511 PyErr_Fetch(&type, &value, &traceback); 512 PyErr_Restore(PyExc_ValueError, value, traceback); 513 }} 473 514 return NULL; 474 515 }} 475 516 Py_RETURN_NONE; 476 517 }} 477 """.format(param = param, paramtype = paramtype, pyparamtype = pyparamtype, **self.__dict__) 518 """.format(param = param, refs = refs, paramdecls = paramdecls, 519 pyparamtypes = pyparamtypes, paramlist = paramlist, **self.__dict__) 478 520 return out 479 521 … … 516 558 {{"{shortname}", (PyCFunction) Py{name}, 517 559 METH_NOARGS, ""}},""".format(name = name, shortname = shortname) 560 for m in self.prototypes['rdo']: 561 name = get_name(m) 562 shortname = name.replace('aubio_%s_' % self.shortname, '') 563 out += """ 564 {{"{shortname}", (PyCFunction) Py{name}, 565 METH_VARARGS, ""}},""".format(name = name, shortname = shortname) 518 566 out += """ 519 567 {NULL} /* sentinel */ … … 541 589 0, 542 590 0, 543 (ternaryfunc)Py _{shortname}_do,591 (ternaryfunc)Pyaubio_{shortname}_do, 544 592 0, 545 593 0,
Note: See TracChangeset
for help on using the changeset viewer.