From: Paul Brossier Date: Sat, 9 Mar 2013 01:27:10 +0000 (-0500) Subject: lib/generator.py: move add_generated_objects and generated_types_ready to .c file X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=93acd9fba5743f4c58fb2d7d007b8b54f371d922;p=aubio.git lib/generator.py: move add_generated_objects and generated_types_ready to .c file --- 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)