Hello Cython developers,

recently I started to refactor my C++/Python project, where I used a SWIG tool 
to build extention, and I discovered that Pyrex/Cython tool is much more faster 
and eats less memory. But there are some cons, it cannot create shadow C++ 
classes automaticly, so user must write them by hands. Of course this is needed 
base functionality for such tools, but it is not what developers want (lazy, 
like me :) ).

So I've decided make an addition to Cython tool to provide such functionality. 
Because I'm not very experienced in how Pyrex/Cython works (and there are some 
specific, because tool must parse .h) I've decided to write preprocessor wich 
would roll out simple modified 'extern from' construction. It integrates with 
Cython in Utils.py module (by ihooks) and provides preprocessed files instead 
of original ones.

There are a few constructions parsed by preprocessor (I called it ccython 
because of lack of imagination):

cdef extern from "China.hpp" import Dress, Phone:
    pass
-------------------------
cdef extern from "China.hpp":
    ctypedef struct c_Dress "Dress":
       void tearAtaTouch();
    c_Dress *new_Dress "new Dress" ()
    void del_Dress "delete" (c_Dress * ptr)
    ctypedef struct c_Phone "Phone":
       void ring();
       int break(int days);
    c_Phone *new_Phone "new Phone" ()
    void del_Phone "delete" (c_Phone * ptr)
etc.. all classes specified in import list will be imported, also using of * is 
possible. And:

cdef class Phone import *:
   pass
-------------------------
cdef class Phone:
   cdef c_Phone *thisptr
   def __cinit__(self): new_Phone()
   def __dealloc__(self): del_Phone(self.thisptr)
   def ring(self): self.thisptr.break()
   def break(self, days): return self.thisptr.break(days)

(all like in C++ example on cython.org)
also instead of pass other methods can be specified by hands. Only specified .h 
file and specified class definition parsed, but there is a possibility to use 
'gcc -E' output (all included) and look at all class hierarchy.

I used pyparsing module to parse .pyx and .h files. Now tool is in pre-alpha, 
so I have some question:
- how it corellate with Cython developers goals? Does exist a little chance for 
such features to be implemented in original Cython (my project is only a little 
test).
- is that syntax good ?
- what should I do with arguments of C++ class types? (create shadows for them!)

Now TODO list looks like:
- parse C preprocessed files instead of headers (may be done by pythonic tools 
or just 'gcc -E')
- add import lists for extern structs (I not intends to spam local scope with 
identifiers what I've never seen)
- resolve conflicts with already declared names (how?)
- look through all class tree for public methods and attributes

Thanks for attention!


_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to