I'm just starting to understand Cython, trying to wrap some structures from the C library with Python methods and classes. What I really don't understand is how to work with (initialized) C structures in the appropriate Python class. What I miss here:
Excerpt from the C header file:
struct test_struct {
int _something;
complex_struct* _another;
};
typedef struct test_struct test;
test *test_new(void);
int some_method(test **n, int irrelevant);
Relevant snippet from my .pxd:
cdef struct test_struct:
pass
ctypedef test_struct test
test* test_new()
int some_method(test **n, int irrelevant)
My.pyx:
def do_something(int irrelevant):
cdef test* t = test_new()
ret = some_method(&t, irrelevant)
return <Test?>t
cdef class Test:
cdef test* _t
Everything that works with the return statement works fine. I get the correct value in ret, etc. But the cast in the return statement seems wrong or its missing information is bigger. With the release of t = do_something(42)Python segfaults.
Segfault itself doesn't help at all:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7a9e74b in internal_print () from /usr/lib/libpython2.7.so.1.0
(gdb) bt
, do_something Python Test. , ? Python? - , ?