Pyrex

François Pinard pinard at iro.umontreal.ca
Mon Dec 30 14:02:04 EST 2002


[fcabaud at free.fr]

>   I would like to get from python to C:
>     one string + 2 lists of strings.
>   The code in python which return these data is easy to write.
>   The code in C to get the data is difficult to write.

>   In what way, pyrex could simplify my life ?

There are many ways.  The main difficulty is probably tearing the lists
into separate strings.  This is more easily written in Pyrex than in C.

So, a simplistic approach might be to call a Pyrex function from Python,
passing it your string and your two lists, which the Pyrex function
saves in local variables within your Pyrex module, before calling a
paramater-less C function of yours.  This C function could call back a
few special Pyrex functions to return the first string, or the length of
each list.  Two of those Pyrex functions might accept an integer ordinal
and return the list element, each function from one of the saved lists.

Another approach might be to, within Pyrex, allocate C-style arrays to
hold all strings from the lists, and then pass pointers to these arrays
to your C function, freeing memory on your way back.  Or you might decide
that it is not be worth that trouble.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list