[pygccxml-development] ctypes code generation?
                
                Brought to you by:
                
                    mbaas,
                    
                
                    roman_yakovenko
                    
                
            
            
        
        
        
    | 
      
      
      From: Gordon K. <gk...@bw...> - 2008-10-13 15:02:22
      
     | 
| 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.
Thanks in advance,
Gordon
 |