[Python-Dev] PyEval_GetFrame() revisited

Armin Rigo arigo@tunes.org
Sat, 15 Mar 2003 23:33:03 -0800 (PST)


Hello Christian,

On Fri, Mar 14, 2003 at 07:05:05PM +0100, Christian Tismer wrote:
> > where the PyEval_GetGLobals is used instead of
> >               tstate->frame->f_globals
> Ah!!
> Can it be that PyEval_GetFrame() is just indended
> to signal to an extension like Psyco that it needs
> to quickly invent a frame now?

Yes, indeed.  This was a very limited hack so that the frame would get the
correct locals even in the presence of Psyco.  Now I realize that it may have
been pointless anyway, if this dummy frame is never really used but for
tracebacks.

Maybe an API to manipulate tstate->frame could be useful and really
lightweight.  Alternatively, we could consider what pyexpat does as a general
pattern and have an API for it, e.g.:

PyFrame_Push(PyFrameObject* f) ->
    pushes 'f' on the frame stack, assert()ing that f->f_back is tstate->frame
    or pushes a new placeholder frame if 'f' is NULL.
    This also calls the profile and trace hooks.

PyFrame_Pop() ->
    pops the frame, calling profile and trace hooks,
    and recording a traceback if PyErr_Occurred().

and maybe a PyFrame_FromC() function that creates a placeholder with
controllable parameters as in pyexpat.c:getcode().


A bientôt,

Armin.