Re: [cython-users] Help on my pyx file using c library in cython

27 views
Skip to first unread message

Stefan Behnel

unread,
Oct 22, 2012, 11:48:02 PM10/22/12
to cython...@googlegroups.com
Userl, 19.10.2012 21:18:
> I am writing a wrapper routine using c libraries in cython. I have a
> function that return a pointer to a structure
>
> t1 * func1(int a, char b ,int c)
>
>
> my pxd file:
>
> cdef extern from "libscript/script.h"
>
> ctypedef struct t1 :
> pass

You might want to declare the struct fields in case you want to use them in
your code. If you don't care about them then it's ok like this.

> t1* func1(int a , char b, int c)
>
>
> Do you think my pyx file is correct.

Note that the bad indentation makes it really hard to read.


> cimport cwrapper
> cdef class routines
>
> cdef cwrapper.t1 *c_t1

It's ok so far.

> def __cinit__(self,int,bytes,int):

You are declaring three variables here: "self", "int" and "bytes", actually
declaring "int" twice. What you likely wanted to do is to declare four
variables as follows:

def __cinit__(self, int var1, bytes var2, int var3):


> self.c_t1 =self.c_func1(int,bytes,int)
>
>
> cdef t1* c_func1(self):
> cdef t1 *x =null
> x=func1(int,bytes,int)

This won't compile because "int,bytes,int" are undefined.

> return x

Did you read through the wrapping tutorial?

http://docs.cython.org/src/tutorial/clibraries.html

Stefan

Reply all
Reply to author
Forward
0 new messages