[Pyrex] Idea for improving "C name specifications"

Edward C. Jones edcjones at erols.com
Tue Apr 29 16:21:25 CEST 2003


Greg Ewing wrote:

>"Edward C. Jones" <edcjones at erols.com>:
>
>  
>
>>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.
>>    
>>
>
>I haven't had much experience using this feature yet, so
>it's possible that its design is not optimal. I'm open
>to suggestions.
>
>  
>
>>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
>>    
>>
>
>I'm not sure of the semantics you intend here. Presumably
>you're trying to decouple the renaming from the declarations,
>but I don't quite see how it works in this example.
>  
>
I want the renaming to apply only to part of the Pyrex file. The 
semantics has something to do somehow with namespaces. It is as if I 
were combining two ".pyx' files into one. Suppose I have 
"wrappedABC.pyx" containing

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

and "wrappedDEF.pyx" containing:

cdef struct ABC

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

I compile them into the shared libraries "wrappedABC.so" and 
"wrappedDEF.so".

If I am wrapping 100 structs, I get 100 shared libraries which is 
NotAcceptable. So I want to put all the code in one Pyrex file where the 
"c_" names are visible in only part of the file.

Also, IMHO, decoupling is more Pythonic.

Thanks,
Ed Jones






More information about the Pyrex mailing list