[Python-Dev] Re: Re: subprocess - updated popen5 module
theller at python.net
Mon Oct 11 09:26:35 CEST 2004
Guido van Rossum <gvanrossum at gmail.com> writes:
> And what about all the stuff that's defined in header files? In the
> past, in the Unix world, I experimented with translating .h files to
> Python modules to save me from the burden of having to add large
> numbers of symbol definitions to C extensions. (Look for files named
> Lib/plat-XXX/regen in the source tree.) One by one, that approach has
> proven to be problematic, and nearly all of those have eventually been
> turned into systematic lists of symbol definitions in C code. See for
> example the posix, socket, fcntl, and signal modules.
I have two solutions here, both based on gccxml (see
http://www.gccxml.org/). This is the C++ parser part of gcc, with a
backend that turns the declaration in C header files into xml. gccxml
runs on windows too, and since the installer even does some small
patches to the MS header files to make them compliant, it parses the
windows H files without a problem. You can even request it to simulate
MSVC 6, MSVC 7.0, or MSVC 7.1.
Now I have written an XML parser/Python code generator combo which
generates a valid Python module from header files. This includes enums,
structures, unions, and exported functions, but not #define symbol
definitions, of course. You could even specify the symbols you want to
be generated, it handles dependencies correctly and will include all
that is needed.
For the #define symbols, I let gccxml dump the preprocessor definitions
after running it on the header files. This is to find the defined
names. The actual code generation into Python code is done by a set of
C++ function templates. This works better than Tools/scripts/h2py.py.
Both things are still work in progress, but they do work.
More information about the Python-Dev