|
Re: using C char array problem: msg#00030python.pyrex
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 |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: pyrexembed: How to make a method which returns a struct: 00030, Helmut Jarausch |
|---|---|
| Next by Date: | Callbacks from other threads (crash in PyGILState_Release): 00030, Geoff Schmidt |
| Previous by Thread: | Re: pyrexembed: How to make a method which returns a structi: 00030, Helmut Jarausch |
| Next by Thread: | Callbacks from other threads (crash in PyGILState_Release): 00030, Geoff Schmidt |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |