Wrapping interdependent structures in Pyrex
I am trying to port some C code to Python using Pyrex. I am having a problem defining two structures. In this case, the structs were defined in terms of each other and Pyrex doesn't seem to handle the conflict. The structures look something like this:
typedef struct a {
b * b_pointer;
} a;
typedef struct b {
a a_obj;
} b;
They are located in different files. The code I'm using to wrap the structures looks like this:
def extern from "file.c":
ctypdef struct a:
b * b_pointer
ctypedef struct b:
a a_obj
File.c
is a separate file containing function definitions as opposed to structure definitions, but includes source files that define these structures. Is there a way to wrap both of these structures?
source to share
You can use an incomplete type (you need the corresponding C typedefs in the file .h
, not just .c
):
cdef extern from "some.h":
ctypedef struct b
ctypedef struct a:
b * b_pointer
ctypedef struct b:
a a_obj
source to share