summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-04-07 19:31:01 (GMT)
committerGitHub <noreply@github.com>2022-04-07 19:31:01 (GMT)
commitef6a482b0285870c45f39c9b17ed827362b334ae (patch)
treea32a27a4d209b974d9f4d92e7e997dc3ff771409 /Objects
parent87eec70d97b250f820325b4f1b4f781b443b5180 (diff)
downloadcpython-ef6a482b0285870c45f39c9b17ed827362b334ae.zip
cpython-ef6a482b0285870c45f39c9b17ed827362b334ae.tar.gz
cpython-ef6a482b0285870c45f39c9b17ed827362b334ae.tar.bz2
bpo-47177: Replace `f_lasti` with `prev_instr` (GH-32208)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/frameobject.c35
-rw-r--r--Objects/genobject.c19
-rw-r--r--Objects/typeobject.c2
3 files changed, 27 insertions, 29 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 6842e62..07b6107 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -39,7 +39,7 @@ PyFrame_GetLineNumber(PyFrameObject *f)
return f->f_lineno;
}
else {
- return PyCode_Addr2Line(f->f_frame->f_code, f->f_frame->f_lasti*sizeof(_Py_CODEUNIT));
+ return _PyInterpreterFrame_GetLine(f->f_frame);
}
}
@@ -58,10 +58,11 @@ frame_getlineno(PyFrameObject *f, void *closure)
static PyObject *
frame_getlasti(PyFrameObject *f, void *closure)
{
- if (f->f_frame->f_lasti < 0) {
+ int lasti = _PyInterpreterFrame_LASTI(f->f_frame);
+ if (lasti < 0) {
return PyLong_FromLong(-1);
}
- return PyLong_FromLong(f->f_frame->f_lasti*sizeof(_Py_CODEUNIT));
+ return PyLong_FromLong(lasti * sizeof(_Py_CODEUNIT));
}
static PyObject *
@@ -419,12 +420,11 @@ _PyFrame_GetState(PyFrameObject *frame)
}
case FRAME_OWNED_BY_THREAD:
{
- if (frame->f_frame->f_lasti < 0) {
+ if (_PyInterpreterFrame_LASTI(frame->f_frame) < 0) {
return FRAME_CREATED;
}
- uint8_t *code = (uint8_t *)frame->f_frame->f_code->co_code_adaptive;
- int opcode = code[frame->f_frame->f_lasti*sizeof(_Py_CODEUNIT)];
- switch(_PyOpcode_Deopt[opcode]) {
+ switch (_PyOpcode_Deopt[_Py_OPCODE(*frame->f_frame->prev_instr)])
+ {
case COPY_FREE_VARS:
case MAKE_CELL:
case RETURN_GENERATOR:
@@ -555,7 +555,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore
int64_t best_stack = OVERFLOWED;
int best_addr = -1;
- int64_t start_stack = stacks[f->f_frame->f_lasti];
+ int64_t start_stack = stacks[_PyInterpreterFrame_LASTI(f->f_frame)];
int err = -1;
const char *msg = "cannot find bytecode for specified line";
for (int i = 0; i < len; i++) {
@@ -598,7 +598,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore
}
/* Finally set the new lasti and return OK. */
f->f_lineno = 0;
- f->f_frame->f_lasti = best_addr;
+ f->f_frame->prev_instr = _PyCode_CODE(f->f_frame->f_code) + best_addr;
return 0;
}
@@ -880,10 +880,11 @@ _PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg)
// This only works when opcode is a non-quickened form:
assert(_PyOpcode_Deopt[opcode] == opcode);
int check_oparg = 0;
- for (int i = 0; i < frame->f_lasti; i++) {
- _Py_CODEUNIT instruction = _PyCode_CODE(frame->f_code)[i];
- int check_opcode = _PyOpcode_Deopt[_Py_OPCODE(instruction)];
- check_oparg |= _Py_OPARG(instruction);
+ for (_Py_CODEUNIT *instruction = _PyCode_CODE(frame->f_code);
+ instruction < frame->prev_instr; instruction++)
+ {
+ int check_opcode = _PyOpcode_Deopt[_Py_OPCODE(*instruction)];
+ check_oparg |= _Py_OPARG(*instruction);
if (check_opcode == opcode && check_oparg == oparg) {
return 1;
}
@@ -893,7 +894,7 @@ _PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg)
else {
check_oparg = 0;
}
- i += _PyOpcode_Caches[check_opcode];
+ instruction += _PyOpcode_Caches[check_opcode];
}
return 0;
}
@@ -914,8 +915,8 @@ _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) {
fast = _PyFrame_GetLocalsArray(frame);
// COPY_FREE_VARS has no quickened forms, so no need to use _PyOpcode_Deopt
// here:
- if (frame->f_lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS)
- {
+ int lasti = _PyInterpreterFrame_LASTI(frame);
+ if (lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS) {
/* Free vars have not been initialized -- Do that */
PyCodeObject *co = frame->f_code;
PyObject *closure = frame->f_func->func_closure;
@@ -926,7 +927,7 @@ _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) {
frame->localsplus[offset + i] = o;
}
// COPY_FREE_VARS doesn't have inline CACHEs, either:
- frame->f_lasti = 0;
+ frame->prev_instr = _PyCode_CODE(frame->f_code);
}
for (int i = 0; i < co->co_nlocalsplus; i++) {
_PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i);
diff --git a/Objects/genobject.c b/Objects/genobject.c
index cdb2a0f..e58118b 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -352,14 +352,14 @@ _PyGen_yf(PyGenObject *gen)
if (gen->gi_frame_state < FRAME_CLEARED) {
_PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe;
- if (frame->f_lasti < 1) {
+ if (gen->gi_frame_state == FRAME_CREATED) {
/* Return immediately if the frame didn't start yet. SEND
always come after LOAD_CONST: a code object should not start
with SEND */
assert(_Py_OPCODE(_PyCode_CODE(gen->gi_code)[0]) != SEND);
return NULL;
}
- _Py_CODEUNIT next = _PyCode_CODE(gen->gi_code)[frame->f_lasti + 1];
+ _Py_CODEUNIT next = frame->prev_instr[1];
if (_PyOpcode_Deopt[_Py_OPCODE(next)] != RESUME || _Py_OPARG(next) < 2)
{
/* Not in a yield from */
@@ -490,13 +490,11 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
// XXX: Performing this jump ourselves is awkward and problematic.
// See https://github.com/python/cpython/pull/31968.
/* Termination repetition of SEND loop */
- assert(frame->f_lasti >= 0);
- _Py_CODEUNIT *code = _PyCode_CODE(gen->gi_code);
+ assert(_PyInterpreterFrame_LASTI(frame) >= 0);
/* Backup to SEND */
- frame->f_lasti--;
- assert(_Py_OPCODE(code[frame->f_lasti]) == SEND);
- int jump = _Py_OPARG(code[frame->f_lasti]);
- frame->f_lasti += jump;
+ assert(_Py_OPCODE(frame->prev_instr[-1]) == SEND);
+ int jump = _Py_OPARG(frame->prev_instr[-1]);
+ frame->prev_instr += jump - 1;
if (_PyGen_FetchStopIterationValue(&val) == 0) {
ret = gen_send(gen, val);
Py_DECREF(val);
@@ -1344,9 +1342,8 @@ compute_cr_origin(int origin_depth, _PyInterpreterFrame *current_frame)
frame = current_frame;
for (int i = 0; i < frame_count; ++i) {
PyCodeObject *code = frame->f_code;
- PyObject *frameinfo = Py_BuildValue("OiO",
- code->co_filename,
- PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT)),
+ int line = _PyInterpreterFrame_GetLine(frame);
+ PyObject *frameinfo = Py_BuildValue("OiO", code->co_filename, line,
code->co_name);
if (!frameinfo) {
Py_DECREF(cr_origin);
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 53e4f07..64c4bbb 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -8980,7 +8980,7 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyCodeObject *co,
if (firstarg != NULL && (_PyLocals_GetKind(co->co_localspluskinds, 0) & CO_FAST_CELL)) {
// "firstarg" is a cell here unless (very unlikely) super()
// was called from the C-API before the first MAKE_CELL op.
- if (cframe->f_lasti >= 0) {
+ if (_PyInterpreterFrame_LASTI(cframe) >= 0) {
// MAKE_CELL and COPY_FREE_VARS have no quickened forms, so no need
// to use _PyOpcode_Deopt here:
assert(_Py_OPCODE(_PyCode_CODE(co)[0]) == MAKE_CELL ||