Some time ago, I was a heavy and rather-advanced SWIG user. Next I
switched to Cython (except for a few legacy in-house codes), but there
is a feature I still miss. As I dislike to ask others (read: Dag,
Stefan, Robert, i.e, core devs) to think or implement about something
I need but I'm not in position to contribute, I never commented on
this.

Suppose Cython could be enhanced by a mechanism where users can setup
mappings C->Py and Py->C for any type using a user-provided cdef
functions or even external functions. Then we should be able to do:

cdef current_encoding = "latin-1"

cdef unicode charp2unicode(char* p):
    return p.decode(current_encoding)

and (somehow) add a to mapping (new syntax likely required):

C_2_Python['char*'] = charp2unicode


Of course, the other way is also possible and nice to have.

Implementing this idea would enable some niceties:

1) Robert will be able to decide on a module-by-module base how to
make the mappings char*<->str.

2) Projects that wraps other OO libs (like mpi4py and petsc4py, lxml?)
could easily coerce Py instances (of cdef classes) to C handles, and
the other way around.

3) ...(have you anything to add to this list)

At some point in the future when Danilo's C++ support is merged, and
some C/C++ header parser is available, Cython typemaps would enable
AUTOMATIC wrapper generation, pretty much like SWIG does right now.


Just a wild idea.


-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to