diff options
author | Brandt Bucher <brandtbucher@microsoft.com> | 2022-04-07 19:31:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-07 19:31:01 (GMT) |
commit | ef6a482b0285870c45f39c9b17ed827362b334ae (patch) | |
tree | a32a27a4d209b974d9f4d92e7e997dc3ff771409 /Include | |
parent | 87eec70d97b250f820325b4f1b4f781b443b5180 (diff) | |
download | cpython-ef6a482b0285870c45f39c9b17ed827362b334ae.zip cpython-ef6a482b0285870c45f39c9b17ed827362b334ae.tar.gz cpython-ef6a482b0285870c45f39c9b17ed827362b334ae.tar.bz2 |
bpo-47177: Replace `f_lasti` with `prev_instr` (GH-32208)
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_frame.h | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 211831a..49bdc63 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -39,11 +39,6 @@ enum _frameowner { FRAME_OWNED_BY_FRAME_OBJECT = 2 }; -/* - frame->f_lasti refers to the index of the last instruction, - unless it's -1 in which case next_instr should be first_instr. -*/ - typedef struct _PyInterpreterFrame { PyFunctionObject *f_func; /* Strong reference */ PyObject *f_globals; /* Borrowed reference */ @@ -52,13 +47,20 @@ typedef struct _PyInterpreterFrame { PyCodeObject *f_code; /* Strong reference */ PyFrameObject *frame_obj; /* Strong reference, may be NULL */ struct _PyInterpreterFrame *previous; - int f_lasti; /* Last instruction if called */ + // NOTE: This is not necessarily the last instruction started in the given + // frame. Rather, it is the code unit *prior to* the *next* instruction. For + // example, it may be an inline CACHE entry, an instruction we just jumped + // over, or (in the case of a newly-created frame) a totally invalid value: + _Py_CODEUNIT *prev_instr; int stacktop; /* Offset of TOS from localsplus */ bool is_entry; // Whether this is the "root" frame for the current _PyCFrame. char owner; PyObject *localsplus[1]; } _PyInterpreterFrame; +#define _PyInterpreterFrame_LASTI(IF) \ + ((int)((IF)->prev_instr - _PyCode_CODE((IF)->f_code))) + static inline PyObject **_PyFrame_Stackbase(_PyInterpreterFrame *f) { return f->localsplus + f->f_code->co_nlocalsplus; } @@ -97,7 +99,7 @@ _PyFrame_InitializeSpecials( frame->f_locals = Py_XNewRef(locals); frame->stacktop = nlocalsplus; frame->frame_obj = NULL; - frame->f_lasti = -1; + frame->prev_instr = _PyCode_CODE(frame->f_code) - 1; frame->is_entry = false; frame->owner = FRAME_OWNED_BY_THREAD; } @@ -186,6 +188,7 @@ void _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame *frame); _PyInterpreterFrame * _PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func); +int _PyInterpreterFrame_GetLine(_PyInterpreterFrame *frame); static inline PyGenObject *_PyFrame_GetGenerator(_PyInterpreterFrame *frame) |