[Pyrex] Circular cimports
Greg Ewing
greg.ewing at canterbury.ac.nz
Sun Jun 11 00:10:02 UTC 2006
Mike Wyatt wrote:
> In C/C++, I believe this problem would be solved like this:
>
> ***matrix.h***
> #ifndef MATRIX_H
> #define MATRIX_H
The cause of the problem is different in Pyrex, though.
It's already smart enough not to read the same .pxd file
twice, so an ifdef wouldn't help.
I think the problem is that it generates code to import
all of the extension types referenced by a particular module
before doing anything else, including creation of the type
objects defined in that module. So with circular imports it
ends up trying to import a type object that hasn't been
created yet.
Thinking about this in the shower yesterday, I decided
that this can probably be fixed by only importing the
types used as base classes of a type defined in the
module first, then creating the types, and then doing
any other imports. That will require a compiler change,
however.
In the meantime, the only workaround I can think of is
to define all the mutually-referencing extension types
in the same module (you can use the include statement
to split it into multiple files if you want).
--
Greg
More information about the Pyrex
mailing list