[Pyrex] Idea for imporving "C name specifications"

Edward C. Jones edcjones at erols.com
Mon Apr 28 16:39:01 CEST 2003


I am writing a program which outputs wrappers for some complex C header 
files. Obviously, I would prefer to wrap each declaration independently 
of all the others. But I have "namespace" problems.

Here are two C structs from "astruct.h":

typedef struct ABC
{
     int abc;
     int* xyz;
} ABC;

typedef struct DEF
{
     ABC* abcp;
} DEF;

Here is part of the code for wrapping these:

cdef extern from "astruct.h":
     ctypedef struct c_ABC "ABC":
         int abc
         int* xyz

cdef extern from "astruct.h":
     ctypedef struct c_DEF "DEF":
         c_ABC* abcp

Note the "c_ABC" in the last line. When I wrap "DEF", I need to know 
that "ABC" is wrapped in the same Pyrex file. This can be done by 
processing the header file twice. It would be nicer if I could do 
something like:

use c_ABC for ABC:
     cdef extern from "astruct.h":
         ctypedef struct c_ABC:
             int abc
             int* xyz

use c_DEF for DEF:
     cdef extern from "astruct.h":
         ctypedef struct c_DEF:
             ABC* abcp

Note that this removes the unpythonic c_ABC "ABC". I am no language 
designer so I will not defend the "use ... for ..." syntax.





More information about the Pyrex mailing list