Hi,
typemaps sound very useful to me. However, what always bothers me in
SWIG's implementation is that the map is associated with a C type. So, if
you have, say, two 'char *' arguments in a function to be wrapped that need
to be converted differently you need some strange argument name pattern
matching to tell SWIG which conversion to use where.
In Cython, we are free to define new types. What about an extension to the
'ctypedef' syntax similar to the property syntax?
As an example, let's say that in our C code, "char *" is sometimes a
unicode string and sometimes an array of bytes. Then we might introduce
ctypedef char* unicode with:
cdef char* __py2c__( str a ):
...
cdef str __c2py__( char* ):
...
ctypedef char * byte_array with:
cdef char* __py2c__( list a ):
...
cdef list __c2py__( char * ):
...
If one then has an external C function
void foo( char* aByteArray, char* aUnicodeString );
one might declare it in Cython as
cdef extern void foo( byte_array aByteArray, unicode aUnicodeString )
and it will appear to calling Python code as accepting a list and a
string,
which are then converted by the two '__py2c__' functions.
Of course, if a type only appears as parameter type or only as return
type, one needs to declare only one of __py2c__ or __c2py__ (similar to
SWIG's 'in' and 'out' typemaps).
(BTW, as this is my first post to this list: Many thanks for Cython, it is
an incredibly useful tool!)
Cheers
Simon
+---
| Dr. Simon Anders, Dipl.-Phys.
| European Molecular Biology Laboratory (EMBL), Heidelberg
| office phone +49-6221-387-8632
| preferred (permanent) e-mail: [email protected]
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev