[Pyrex] using C char array problem

Greg Ewing greg.ewing at canterbury.ac.nz
Wed May 24 02:05:39 UTC 2006


Eric Colleu wrote:

> I define a type
>   ctypedef char machaine[10]
> And I try to pass an array of this type to a C function with no success.

I think what's happening here is that testDeTableauDeString is
expecting a 2D array, i.e. an array of machaine arrays laid out
consecutively in memory. But in testapi,

 >         cdef machaine *p[10]

declares a 1D array of pointers to separate machaine arrays.

What to do about this depends on the requirements. If it's
vital that testDeTableauDeString gets its montableau argument
as a single block of memory, you will need to declare or
allocate one and copy all the strings into it before calling
testDeTableauDeString.

If not, you could modify testDeTableauDeString so that it
takes an array of pointers to machaines instead of an array
of machaines, e.g.

void testDeTableauDeString(machaine *montableau[], int nbelt)

Also, if the strings aren't required to be exactly 10 chars
long, you could just pass an array of string pointers instead,
e.g.

void testDeTableauDeString(char *montableau[], int nbelt)

--
Greg



More information about the Pyrex mailing list