Pyrex: Incomplete C types
Edward C. Jones
edcjones at erols.com
Thu May 1 11:26:19 EDT 2003
I have some questions about wrapping incomplete C types in Pyrex.
Where in a C compiler are incomplete types processed? The grammars I am
using don't seem to deal with it (I hope I am wrong here).
Is the file "IncTypes_wrapped.pyx" below correct?
Is there any way to wrap "BBB" without knowing about "CCC" or "DDD"?
Two questions are asked in the code below.
Is there a better way to write the "cdef extern"s? What does Pyrex know
about incomplete types?
Suppose I have a declaration in a C header file. Can I always wrap it in
Pyrex using only information in the declaration itself?
Thanks,
Ed Jones
----------------------
IncTypes.h:
typedef struct {
int jjj;
} AAA;
typedef struct {
int jjj2;
} AAA2;
typedef struct _BBB {
AAA* aaa;
struct AAA2* aaa2; /* Is this correct C? */
struct _BBB *bbb;
struct _CCC *ccc;
struct _DDD *ddd;
} BBB;
typedef struct _CCC {
int iii;
} CCC;
typedef struct _DDD DDD;
----------------------
IncTypes.c:
#include "IncTypes.h"
----------------------
IncTypes_wrapped.pyx:
cdef extern from "IncTypes.h":
ctypedef struct AAA:
int jjj
cdef extern from "IncTypes.h":
ctypedef struct AAA2:
int jjj2
cdef extern from "IncTypes.h":
cdef struct AAA2 # Is this line harmless? If it is, I might be able to
# wrap "BBB" locally, using only the definition
of "BBB"
# in the header file.
cdef struct _BBB
cdef struct _CCC
cdef struct _DDD
ctypedef struct BBB:
AAA * aaa
AAA * aaa2
_BBB * bbb
_CCC * ccc
_DDD * ddd
cdef extern from "IncTypes.h":
ctypedef struct CCC:
int iii
cdef extern from "IncTypes.h":
ctypedef _DDD DDD
----------------------
compileit:
pyrexc IncTypes_wrapped.pyx
gcc -c -fPIC -I/usr/include/python2.2/ IncTypes_wrapped.c
More information about the Python-list
mailing list