python/lib/gen_code.py: add support for rdo
authorPaul Brossier <piem@piem.org>
Sat, 16 Sep 2017 21:46:17 +0000 (23:46 +0200)
committerPaul Brossier <piem@piem.org>
Sat, 16 Sep 2017 21:46:17 +0000 (23:46 +0200)
python/lib/gen_code.py
python/lib/gen_external.py

index 0498aa2..b29a59f 100644 (file)
@@ -192,6 +192,11 @@ class MappedObject(object):
             out += self.gen_init()
             out += self.gen_del()
             out += self.gen_do()
+            if len(self.prototypes['rdo']):
+                self.do_proto = self.prototypes['rdo'][0]
+                self.do_inputs = [get_params_types_names(self.do_proto)[1]]
+                self.do_outputs = get_params_types_names(self.do_proto)[2:]
+                out += self.gen_do(method='rdo')
             out += self.gen_memberdef()
             out += self.gen_set()
             out += self.gen_get()
@@ -372,12 +377,12 @@ Py_{shortname}_del  (Py_{shortname} * self, PyObject * unused)
 """.format(del_fn = del_fn)
         return out
 
-    def gen_do(self):
+    def gen_do(self, method = 'do'):
         out = """
 // do {shortname}
 static PyObject*
-Py_{shortname}_do  (Py_{shortname} * self, PyObject * args)
-{{""".format(**self.__dict__)
+Pyaubio_{shortname}_{method}  (Py_{shortname} * self, PyObject * args)
+{{""".format(**self.__dict__, method = method)
         input_params = self.do_inputs
         output_params = self.do_outputs
         #print input_params
@@ -517,6 +522,12 @@ static PyMethodDef Py_{shortname}_methods[] = {{""".format(**self.__dict__)
             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 */
 };
@@ -542,7 +553,7 @@ PyTypeObject Py_{shortname}Type = {{
   0,
   0,
   0,
-  (ternaryfunc)Py_{shortname}_do,
+  (ternaryfunc)Pyaubio_{shortname}_do,
   0,
   0,
   0,
index 8095cb6..1e35bfd 100644 (file)
@@ -181,7 +181,7 @@ def generate_lib_from_c_declarations(cpp_objects, c_declarations):
         if o[:6] == 'aubio_':
             shortname = o[6:-2]  # without aubio_ prefix and _t suffix
 
-        lib[shortname] = {'struct': [], 'new': [], 'del': [], 'do': [], 'get': [], 'set': [], 'other': []}
+        lib[shortname] = {'struct': [], 'new': [], 'del': [], 'do': [], 'rdo': [], 'get': [], 'set': [], 'other': []}
         lib[shortname]['longname'] = o
         lib[shortname]['shortname'] = shortname
 
@@ -195,6 +195,8 @@ def generate_lib_from_c_declarations(cpp_objects, c_declarations):
                     lib[shortname]['struct'].append(fn)
                 elif '_do' in fn:
                     lib[shortname]['do'].append(fn)
+                elif '_rdo' in fn:
+                    lib[shortname]['rdo'].append(fn)
                 elif 'new_' in fn:
                     lib[shortname]['new'].append(fn)
                 elif 'del_' in fn: