[pypy-dev] Bringing Cython and PyPy closer together

Maciej Fijalkowski fijall at gmail.com
Mon Mar 19 09:11:13 CET 2012

On Mon, Mar 19, 2012 at 8:44 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Stefan Behnel, 26.02.2012 20:54:
>> Amaury Forgeot d'Arc, 18.02.2012 15:41:
>>> 2012/2/18 Stefan Behnel
>>>> Here's an example.
>>>> Python code:
>>>>  def print_excinfo():
>>>>      print(sys.exc_info())
>>>> Cython code:
>>>>  from stuff import print_excinfo
>>>>  try:
>>>>      raise TypeError
>>>>  except TypeError:
>>>>      print_excinfo()
>>>> With the code removed, Cython will not store the TypeError in
>>>> sys.exc_info(), so the Python code cannot see it. This may seem like an
>>>> unimportant use case (who uses sys.exc_info() anyway, right?), but this
>>>> becomes very visible when the code that uses sys.exc_info() is not user
>>>> code but CPython itself, e.g. when raising another exception or when
>>>> inspecting frames. Things grow really bad here, especially in Python 3.
>>> I think I understand now, thanks for your example.
>>> Things are a bit simpler in PyPy because these exceptions are
>>> stored in the frame that is currently handling it. At least better than
>>> CPython
>>> which stores it in one place, and has to somehow save the state of the
>>> previous frames.
>>> Did you consider adding such a function to CPython?
>>> "PyErr_SetCurrentFrameExceptionInfo"?
>>> For the record, pypy could implement it as:
>>> space.getexecutioncontext().gettopframe_nohidden().last_exception =
>>> operationerr
>>> i.e. the thing returned by sys.exc_info().
>> I've dropped a patch for CPython in the corresponding tracker ticket:
>> http://bugs.python.org/issue14098
>> The (trivial) implementation of the two functions is at the end of this file:
>> http://bugs.python.org/file24613/exc_info_capi.patch
>> Could you add them to PyPy?
> Anyone?
> Stefan

Hi Stefan.

A lot of people have been completely busy at pycon. As far as I know
they're trying to recover from jetlag/lots of conference. Give them a
bit of breath ;-)

More information about the pypy-dev mailing list