cython-codegen

cycodegenlib - an hack to generate cython code from XML output generated by gccxml
Download

cython-codegen Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • David Cournapeau

cython-codegen Tags


cython-codegen Description

cycodegenlib - an hack to generate cython code from XML output generated by gccxml cython-codegen is a hack to generate cython code from XML output generated by gccxml.This is a small package to generate cython code from header file: instead of having to write all the function declarations and structures by yourself, xml2cython can use gccxml output files to generate all the declarations automatically.Usage:Say you have a header foo.h you want to wrap with cython. First, you need togenerate an xml file from gccxml. You can use the h2xml script from ctypelibs: h2xml -I. foo.h -o foo.xmlYou can then generate the cython file with xml2cython: xml2cython.py -l 'foo' foo.h foo.xmlThis tells xml2cython to generate a cython file from foo.xml, originating fromfoo.h by gccxml, and to only pull items whose location match the string foo.Location:By default, xml2cython pull out every function in the xml file, and every 'dependency' (necessary to generate correct cython function declarations). This is likely to generate invalid cython code because of compilers intrisincs and so on, so you should filter the items pulled out from the xml file.Location is a gccxml 'concept' related to the origin of each item in the parsed tree built by gccxml. Location refers to both file and line location for each C item (structure, typedef, function declaration, etc...). Simply using the -l option of xml2cython on the name of the header file hence will only pull functions declared in that file. You can also use a regex, which will be matched against the file location of each item.If you need more control, you will likely need to do it by yourself.CaveatLimitationsMany. xml2cython is nothing more than an hack to avoid writing by hand cython files to wrap large API. Since I know nothing about compilers and parsing, it is likely that the implementation makes you laugh, too.Many C declarations are not supported by cython (for example complex numbers) and no check is made that xml2cython generates valid cython code. Any header file which crashes xml2cython is a bug, but a non-buildable cython file may not be.Another problem is that the query system is limited, meaning the generated files are quickly very big, hence slow to compile with cython. I am adding a few filters capabilities (to filter on function names, file origin, etc...), but it is unlikely to get fancy.That being said, xml2cython is useful :) It can generate valid code for non trivial header (I am using it successfully to wrap alsa - a C api with > 1000 functions, hundred of typedefs and structures as well as CoreAudio on Mac OS X).C vs C++Unfortunately, gccxml only parses C++ files. So if your header is not C++ compatible, it will not work. No C++ concept is supported by xml2cython, most of them are removed from the AST by xml2cython to avoid conflict with cython (which does not support C++ constructs either). Requirements: · Python · pygccxml · codegenlib from ctypeslib


cython-codegen Related Software