From 93acd9fba5743f4c58fb2d7d007b8b54f371d922 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 8 Mar 2013 20:27:10 -0500 Subject: [PATCH] lib/generator.py: move add_generated_objects and generated_types_ready to .c file --- python/lib/generator.py | 52 +++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/python/lib/generator.py b/python/lib/generator.py index ead37cf7..d93e8ce2 100755 --- a/python/lib/generator.py +++ b/python/lib/generator.py @@ -142,37 +142,53 @@ def generate_object_files(output_path): """ - for each in generated_objects: - s += "extern PyTypeObject Py_%sType;\n" % \ - each.replace('aubio_','').replace('_t','') - types_ready = [] for each in generated_objects: types_ready.append(" PyType_Ready (&Py_%sType) < 0" % \ each.replace('aubio_','').replace('_t','') ) + s = """// generated list of objects created with generator.py + +#include "aubio-generated.h" +""" + s += """ - int - generated_types_ready (void) - { - return ( - """ +int generated_types_ready (void) +{ + return ( +""" s += ('\n ||').join(types_ready) s += """); - } - """ +} +""" s += """ - void - add_generated_objects ( PyObject *m ) - {""" +void add_generated_objects ( PyObject *m ) +{""" for each in generated_objects: - s += """ Py_INCREF (&Py_%(name)sType); - PyModule_AddObject (m, "%(name)s", (PyObject *) & Py_%(name)sType);""" % \ - { 'name': ( each.replace('aubio_','').replace('_t','') ) } + s += """ + Py_INCREF (&Py_%(name)sType); + PyModule_AddObject (m, "%(name)s", (PyObject *) & Py_%(name)sType);""" % \ + { 'name': ( each.replace('aubio_','').replace('_t','') ) } s += """ - }""" +}""" + + fd = open(os.path.join(output_path,'aubio-generated.c'), 'w') + fd.write(s) + + s = """// generated list of objects created with generator.py + +#include "Python.h" + +""" + + for each in generated_objects: + s += "extern PyTypeObject Py_%sType;\n" % \ + each.replace('aubio_','').replace('_t','') + + s+= "int generated_objects ( void );\n" + s+= "void add_generated_objects( PyObject *m );\n" fd = open(os.path.join(output_path,'aubio-generated.h'), 'w') fd.write(s) -- 2.26.2