[pypy-dev] offtopic, ontopic, ...

Stefan Behnel stefan_ml at behnel.de
Mon Feb 13 23:26:53 CET 2012

Amaury Forgeot d'Arc, 13.02.2012 22:06:
> 2012/2/13 Stefan Behnel
>> Given how important Cython has become for the Python ecosystem in
>> many regards, it's sad that PyPy still doesn't have it available
> Last time I looked, Cython still generates code that PyPy cannot handle:
> for example, it explicitly messes with tstate->curexc_type &co,
> Couldn't PyErr_Fetch() and PyErr_Restore() be used instead?

Just two general comments on this, because these internals are really
off-topic for this list and much better suited for the cython-dev list.

1) These things are usually done for two reasons: sometimes for better
performance (inlining!), but also because there are cases where CPython
fails to match its own Python-level semantics at the C-API level (simply
because no-one else but Cython actually needs them there). So we sometimes
end up rewriting parts of its C-API in a way that allows us to reimplement
the correct Python semantics on top of them.

Also note that Python 2 and 3 behave severely different in some corners,
but Cython must be able to support both behaviours regardless of which of
the two C-APIs the C compiler finds at compile time. Exception handling is
a particularly shining example, I can tell.

2) Given that PyPy has proper Python semantics built-in, it would be much
better to reuse those and sort-of add Cython semantics to them in some way,
than to try to interface with PyPy at the bare C-API level.

However, note that Cython's type system is really complex. That's basically
all the Cython language adds over Python: a bunch of types and a huge set
of pretty smart rules to fit them together. That makes a true
Cython-backend for PyPy a much more ambitious longer-term goal than a set
of "quick and dirty but doesn't always work" kind of C-API hacks to improve
the connection between the two. Personally, I think both are worth exploring.


More information about the pypy-dev mailing list