views:

72

answers:

1

Hello,

I am attempting to wrap some C code in Python using Pyrex. I've run into an issue with defining two structs. In this case, the structures have been defined in terms of one another, and Pyrex cannot seem to handle the conflict. The structures look something like so:

typedef struct a {
    b * b_pointer;
} a;

typedef struct b {
    a a_obj;
} b;

They are placed in different files. The code I am 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 the structure definitions, but it includes the source files that define these structures. Is there some way I can wrap both of these structures?

+2  A: 

You can use an incomplete type (you do need the corresponding C typedefs in to be in a .h file, not just a .c file):

cdef extern from "some.h":
  ctypedef struct b
  ctypedef struct a:
    b * b_pointer
  ctypedef struct b:
    a a_obj
Alex Martelli