Movatterモバイル変換
[0]ホーム
[Python-Dev] C-API functions for reading/writing tstate->exc_* ?
Stefan Behnelstefan_ml at behnel.de
Sun Feb 19 14:04:37 CET 2012
Hi,the Cython and PyPy projects are currently working on getting Cythonimplemented extensions to build and run in PyPy, interfacing at the C-APIlevel for now.One problem we encountered was that there is currently no "abstract" way toaccess tstate->exc_type and friends, i.e. the last exception that wascaught, aka. sys.exc_info(). Apparently, PyPy stores them at a frame level,whereas CPython makes them available in thread local storage as bare structfields. Even if PyPy put them there on request, any changes to these fieldswould pass unnoticed. And Cython needs to set them in order to properlyimplement the semantics of a try-except statement (and in some other placeswhere exception state is scoped).When compiling for PyPy, Cython therefore needs a way to tell PyPy aboutany changes. For the tstate->curexc_* fields, there are the two functionsPyErr_Fetch() and PyErr_Restore(). Could we have two similar "official"functions for the exc_* fields? Maybe PyErr_FetchLast() andPyErr_RestoreLast()?Note that Cython would not have a reason to actually use them in CPython,and it should be uncommon for non-Cython extension modules to care aboutthe exc_* fields at all. So these functions won't be of much use ifactually implemented in CPython (although I wouldn't mind doing that). Thequestion is just if we could have two officially named functions that PyPy(and maybe other Pythons) could implement in order to access the lastraised exception in a way that does not depend on implementation details.Stefan
More information about the Python-Devmailing list
[8]ページ先頭