[Pyrex] C-API implementation in Pyrex 0.9.6

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Oct 13 12:29:08 CEST 2007


Stefan Behnel wrote:
> I have two
> public types and a public function in a .pyx file called etree.pyx:
> 
> cdef public class _Document [ type LxmlDocumentType, object LxmlDocument ]:
> ...
> 
> cdef public class _Element [ type LxmlElementType, object LxmlElement ]:
> ...
>
> This is the public C-API definition in a separate .pxd file called
> etreepublic.pxd:
> 
>
> cdef extern from "etree.h":
> 
>     cdef class lxml.etree._Document [ object LxmlDocument ]:
>         ...
> 
>     cdef class lxml.etree._Element [ object LxmlElement ]:
>         ...

I'm confused about what you're trying to achieve here. If you
want to export _Document and _Element to other Pyrex modules,
why don't you simply declare them in etree.pyx?

If you're using the facilities properly, you should never have
to include a .h file to get declarations from one Pyrex module
to another. You should only need to cimport from the appropriate
module.

I suspect you're using a mixture of the Cython and Pyrex way
of doing things, which might be responsible for some of your
problems.

I'm not saying there isn't a problem, but it's hard to see from
this example exactly where it lies. I'll try to rework your example
into something less convoluted and see if the situation becomes
clearer.

> (Alternatively, do not require the public API to be
> defined in the module .pxd file).

Actually, I don't -- you can use the "public" and "api" keywords
in the .pyx file to export things to C code only. But that
probably doesn't help you here, as you appear to want to export
them to other Pyrex modules as well, or maybe instead -- that's
one of the things that's not clear.

You need to understand that, in Pyrex, exporting to other Pyrex
modules and exporting to external C code are two different things
that happen to partially share an implementation mechanism.

--
Greg



More information about the Pyrex mailing list