[Cython] weird declarations in fused types C code
stefan_ml at behnel.de
Fri May 11 08:38:10 CEST 2012
while trying to replace the "import sys; if sys.version_info >= (3,0)" in
the fused types dispatch code by the more straight forward "if
PY_MAJOR_VERSION >= 3" (before I came to think that this particular case
only guards useless code that does the wrong thing), I noticed that the
code generates a declaration of PyErr_Clear() into the outside environment.
When used in cdef classes, this leads to an external method being declared
in the class, essentially like this:
cdef class MyClass:
cdef extern from *:
Surprisingly enough, this actually works. Cython assigns the real C-API
function pointer to it during type initialisation and even calls the
function directly (instead of going through the vtab) when used. A rather
curious feature that I would never had thought of.
Anyway, this side effect is obviously a bug in the fused types dispatch,
but I don't have a good idea on how to fix it. I'm sure Mark put some
thought into this while trying hard to make it work and just didn't notice
the impact on type namespaces.
I've put up a pull request to remove the Py3 specialisation code, but this
is worth some more consideration.
More information about the cython-devel