Re: [pygccxml-development] ctypes code generation?
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2008-10-13 20:39:53
|
On Mon, Oct 13, 2008 at 4:46 PM, Gordon Kindlmann <gk...@bw...> wrote: > Hello, > > I'm new to pygccxml and have a simple question: does anyone have > suggestions on how to use pygccxml to generate python code > corresponding to the structs, functions, and variables that are > available (from a shared library) in ctypes? > > I'm thinking of something that takes a C header like: > > typedef struct { > int aaaa, bbbb; > } tst; > > extern int tstSet(tst *t, int v); > > and generates python code which includes things like: > > class tst(Structure): > pass > tst._fields_ = [ > ('aaaa', c_int), > ('bbbb', c_int), > ] > > tstSet.restype = c_int > tstSet.argtypes = [POINTER(tst), c_int] > > I know that ctypeslib serves this purpose: > > http://starship.python.net/crew/theller/wiki/CodeGenerator > > (and my example above is based on its output) but I've had problems > using it with the current version of gccxml: its xml2py phase doesn't > pick up the fields in C structs and convert them to a "_fields_" > assignment. The author of ctypeslib has warned me that ctypeslib is > not really maintained anymore, and he pointed me to a python-only C- > parser (pyglet/tools/wraptypes/wrap.py) included in pyglet <http:// > www.pyglet.org/>, but that choked on some of my header files, and > pyglet doesn't really seem to be the right tool for this job. > > pygccxml, however, seems theoretically perfect, since it works > directly from gccxml, right? There are some ctypes-related comments > that show up in the pygccxml-commit mailing list archive, but nothing > (I could find, anyway) about ctypes in the documentation, or on this > list. > > I'd very much appreciate any tips, suggestions, or examples that > might help me. I don't think that I can help you right now, may be in future. I am developing Py++, a code generator for Boost.Python library, and recently integrated some functionality, which allows to export some "C" code easily. There are few other solutions that help to export and create Pythonic interface for "C" classes and functions. For example take a look on functions transformation future ( http://language-binding.net/pyplusplus/documentation/functions/transformation/transformation.html ). Do you want to reconsider your approach :-) ? May be the best solution for you is to add missing functionality to ctypeslib? It is not too difficult after all. I can help you with gccxml. I did not know that ctypes code generator is not maintained. I think, I am going to evaluate and may be to support it. If you want we can join the efforts. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |