[Pyrex] using C char array problem
Helmut Jarausch
jarausch at skynet.be
Mon Jun 19 15:40:54 UTC 2006
On 23 May, Eric Colleu wrote:
> Hi,
>
> I have a problem with pyrex array management.
> 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.
> Below is my C code and pyrex code.
> Please help me or I'm gonna be crazy...
>
For Pyrex there is no difference between a
char* variable and a machaine type variable.
> cdef extern from "apienc.h":
> ctypedef char machaine[10]
replace this with a simple
ctypedef char* machaine
> void testDeTableauDeString(machaine *montableau, int nbelt)
>
> def testapi(stringlist):
> cdef machaine *myarray
> cdef machaine *p[10]
> cdef int buflen
> for i, s in enumerate(stringlist):
> print "Value of s : " + s
> PyObject_AsReadBuffer(s, <void **>&myarray, &buflen)
> p[i] = myarray
> print "buflen =", buflen
> print "Value of myarray : %s" %
> PyString_FromStringAndSize(<char *>myarray, buflen)
> print "Value of p : %s" % PyString_FromStringAndSize(<char
> *>p[i], buflen)
> testDeTableauDeString(p[0], len(stringlist))
In C (not C++) the linkage for a function with a char* parameter
and a corresponding one with a machaine type parameter is the
same. So, nobody will notice the difference.
The difference shows up only when you compile the C-source of any
functions taking a machaine type parameter.
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
More information about the Pyrex
mailing list