[Python-Dev] C-API functions for reading/writing tstate->exc_* ?

Stefan Behnel stefan_ml at behnel.de
Sun Feb 19 22:10:50 CET 2012


Nick Coghlan, 19.02.2012 15:31:
> On Mon, Feb 20, 2012 at 12:18 AM, Paul Moore wrote:
>> Of course, you could always go through the Python API, getting the sys
>> module, extracting the relevant functions and calling them using the
>> abstract API. That's what I'd recommend if this were purely a CPython
>> question. But I assume that (for some reason) that's not appropriate
>> for PyPy.
> 
> I had the same thought, but it actually only works cleanly for the
> "fetch" half of the equation. You'd have to muck around with actually
> raising an exception to handle *setting* those fields, which is
> *really* relying on implementation details). That said, it may be
> worth further exploring the idea of invoking appropriate snippets of
> Python code to get the desired effect.

Actually, we currently inline the straight C code for this in CPython for
performance reasons, so, no, going through Python code isn't going to be a
good idea.


> My other question would be whether there's an existing *private* C API
> with the desired behaviour that could be made public, or if this would
> be a genuinely new addition to the API.

I'm not aware of any. The code in CPython (especially in ceval.c) always
uses direct field access.

Stefan



More information about the Python-Dev mailing list