mirror of
https://github.com/python/cpython.git
synced 2025-09-01 06:28:36 +00:00
bpo-47177: Replace f_lasti
with prev_instr
(GH-32208)
This commit is contained in:
parent
87eec70d97
commit
ef6a482b02
10 changed files with 90 additions and 75 deletions
|
@ -58,12 +58,10 @@ static int prtrace(PyThreadState *, PyObject *, const char *);
|
|||
static void lltrace_instruction(_PyInterpreterFrame *frame, int opcode, int oparg)
|
||||
{
|
||||
if (HAS_ARG(opcode)) {
|
||||
printf("%d: %d, %d\n",
|
||||
frame->f_lasti, opcode, oparg);
|
||||
printf("%d: %d, %d\n", _PyInterpreterFrame_LASTI(frame), opcode, oparg);
|
||||
}
|
||||
else {
|
||||
printf("%d: %d\n",
|
||||
frame->f_lasti, opcode);
|
||||
printf("%d: %d\n", _PyInterpreterFrame_LASTI(frame), opcode);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1249,14 +1247,13 @@ eval_frame_handle_pending(PyThreadState *tstate)
|
|||
#ifdef Py_STATS
|
||||
#define INSTRUCTION_START(op) \
|
||||
do { \
|
||||
frame->f_lasti = INSTR_OFFSET(); \
|
||||
next_instr++; \
|
||||
frame->prev_instr = next_instr++; \
|
||||
OPCODE_EXE_INC(op); \
|
||||
_py_stats.opcode_stats[lastopcode].pair_count[op]++; \
|
||||
lastopcode = op; \
|
||||
} while (0)
|
||||
#else
|
||||
#define INSTRUCTION_START(op) frame->f_lasti = INSTR_OFFSET(); next_instr++
|
||||
#define INSTRUCTION_START(op) (frame->prev_instr = next_instr++)
|
||||
#endif
|
||||
|
||||
#if USE_COMPUTED_GOTOS
|
||||
|
@ -1646,9 +1643,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
|
|||
consts = co->co_consts; \
|
||||
first_instr = _PyCode_CODE(co); \
|
||||
} \
|
||||
assert(frame->f_lasti >= -1); \
|
||||
assert(_PyInterpreterFrame_LASTI(frame) >= -1); \
|
||||
/* Jump back to the last instruction executed... */ \
|
||||
next_instr = first_instr + frame->f_lasti + 1; \
|
||||
next_instr = frame->prev_instr + 1; \
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame); \
|
||||
/* Set stackdepth to -1. \
|
||||
Update when returning or calling trace function. \
|
||||
|
@ -2204,7 +2201,8 @@ handle_eval_breaker:
|
|||
new_frame->localsplus[i] = NULL;
|
||||
}
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
frame->f_lasti += INLINE_CACHE_ENTRIES_BINARY_SUBSCR;
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
|
||||
frame->prev_instr = next_instr - 1;
|
||||
new_frame->previous = frame;
|
||||
frame = cframe.current_frame = new_frame;
|
||||
CALL_STAT_INC(inlined_py_calls);
|
||||
|
@ -2605,7 +2603,7 @@ handle_eval_breaker:
|
|||
if (oparg) {
|
||||
PyObject *lasti = PEEK(oparg + 1);
|
||||
if (PyLong_Check(lasti)) {
|
||||
frame->f_lasti = PyLong_AsLong(lasti);
|
||||
frame->prev_instr = first_instr + PyLong_AsLong(lasti);
|
||||
assert(!_PyErr_Occurred(tstate));
|
||||
}
|
||||
else {
|
||||
|
@ -4603,7 +4601,8 @@ handle_eval_breaker:
|
|||
goto error;
|
||||
}
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
frame->f_lasti += INLINE_CACHE_ENTRIES_CALL;
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
frame->prev_instr = next_instr - 1;
|
||||
new_frame->previous = frame;
|
||||
cframe.current_frame = frame = new_frame;
|
||||
CALL_STAT_INC(inlined_py_calls);
|
||||
|
@ -4708,7 +4707,8 @@ handle_eval_breaker:
|
|||
}
|
||||
STACK_SHRINK(2-is_meth);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
frame->f_lasti += INLINE_CACHE_ENTRIES_CALL;
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
frame->prev_instr = next_instr - 1;
|
||||
new_frame->previous = frame;
|
||||
frame = cframe.current_frame = new_frame;
|
||||
goto start_frame;
|
||||
|
@ -4748,7 +4748,8 @@ handle_eval_breaker:
|
|||
}
|
||||
STACK_SHRINK(2-is_meth);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
frame->f_lasti += INLINE_CACHE_ENTRIES_CALL;
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||
frame->prev_instr = next_instr - 1;
|
||||
new_frame->previous = frame;
|
||||
frame = cframe.current_frame = new_frame;
|
||||
goto start_frame;
|
||||
|
@ -5435,8 +5436,8 @@ handle_eval_breaker:
|
|||
#endif
|
||||
{
|
||||
if (tstate->tracing == 0) {
|
||||
int instr_prev = frame->f_lasti;
|
||||
frame->f_lasti = INSTR_OFFSET();
|
||||
int instr_prev = _PyInterpreterFrame_LASTI(frame);
|
||||
frame->prev_instr = next_instr;
|
||||
TRACING_NEXTOPARG();
|
||||
switch(opcode) {
|
||||
case COPY_FREE_VARS:
|
||||
|
@ -5474,7 +5475,7 @@ handle_eval_breaker:
|
|||
goto error;
|
||||
}
|
||||
/* Reload possibly changed frame fields */
|
||||
JUMPTO(frame->f_lasti);
|
||||
next_instr = frame->prev_instr;
|
||||
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
frame->stacktop = -1;
|
||||
|
@ -5491,10 +5492,8 @@ handle_eval_breaker:
|
|||
#else
|
||||
default:
|
||||
#endif
|
||||
fprintf(stderr,
|
||||
"XXX lineno: %d, opcode: %d\n",
|
||||
PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT)),
|
||||
opcode);
|
||||
fprintf(stderr, "XXX lineno: %d, opcode: %d\n",
|
||||
_PyInterpreterFrame_GetLine(frame), opcode);
|
||||
_PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode");
|
||||
goto error;
|
||||
|
||||
|
@ -5598,7 +5597,8 @@ exception_unwind:
|
|||
}
|
||||
PyObject *exc, *val, *tb;
|
||||
if (lasti) {
|
||||
PyObject *lasti = PyLong_FromLong(frame->f_lasti);
|
||||
int frame_lasti = _PyInterpreterFrame_LASTI(frame);
|
||||
PyObject *lasti = PyLong_FromLong(frame_lasti);
|
||||
if (lasti == NULL) {
|
||||
goto exception_unwind;
|
||||
}
|
||||
|
@ -6690,9 +6690,10 @@ call_trace(Py_tracefunc func, PyObject *obj,
|
|||
int old_what = tstate->tracing_what;
|
||||
tstate->tracing_what = what;
|
||||
PyThreadState_EnterTracing(tstate);
|
||||
assert(frame->f_lasti >= 0);
|
||||
assert(_PyInterpreterFrame_LASTI(frame) >= 0);
|
||||
initialize_trace_info(&tstate->trace_info, frame);
|
||||
f->f_lineno = _PyCode_CheckLineNumber(frame->f_lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds);
|
||||
int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT);
|
||||
f->f_lineno = _PyCode_CheckLineNumber(addr, &tstate->trace_info.bounds);
|
||||
result = func(obj, f, what, arg);
|
||||
f->f_lineno = 0;
|
||||
PyThreadState_LeaveTracing(tstate);
|
||||
|
@ -6742,7 +6743,8 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
|
|||
else {
|
||||
lastline = _PyCode_CheckLineNumber(instr_prev*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds);
|
||||
}
|
||||
int line = _PyCode_CheckLineNumber(frame->f_lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds);
|
||||
int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT);
|
||||
int line = _PyCode_CheckLineNumber(addr, &tstate->trace_info.bounds);
|
||||
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
|
||||
if (f == NULL) {
|
||||
return -1;
|
||||
|
@ -6750,10 +6752,10 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
|
|||
if (line != -1 && f->f_trace_lines) {
|
||||
/* Trace backward edges (except in 'yield from') or if line number has changed */
|
||||
int trace = line != lastline ||
|
||||
(frame->f_lasti < instr_prev &&
|
||||
// SEND has no quickened forms, so no need to use _PyOpcode_Deopt
|
||||
// here:
|
||||
_Py_OPCODE(_PyCode_CODE(frame->f_code)[frame->f_lasti]) != SEND);
|
||||
(_PyInterpreterFrame_LASTI(frame) < instr_prev &&
|
||||
// SEND has no quickened forms, so no need to use _PyOpcode_Deopt
|
||||
// here:
|
||||
_Py_OPCODE(*frame->prev_instr) != SEND);
|
||||
if (trace) {
|
||||
result = call_trace(func, obj, tstate, frame, PyTrace_LINE, Py_None);
|
||||
}
|
||||
|
@ -7685,7 +7687,7 @@ dtrace_function_entry(_PyInterpreterFrame *frame)
|
|||
PyCodeObject *code = frame->f_code;
|
||||
filename = PyUnicode_AsUTF8(code->co_filename);
|
||||
funcname = PyUnicode_AsUTF8(code->co_name);
|
||||
lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT));
|
||||
lineno = _PyInterpreterFrame_GetLine(frame);
|
||||
|
||||
PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno);
|
||||
}
|
||||
|
@ -7700,7 +7702,7 @@ dtrace_function_return(_PyInterpreterFrame *frame)
|
|||
PyCodeObject *code = frame->f_code;
|
||||
filename = PyUnicode_AsUTF8(code->co_filename);
|
||||
funcname = PyUnicode_AsUTF8(code->co_name);
|
||||
lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT));
|
||||
lineno = _PyInterpreterFrame_GetLine(frame);
|
||||
|
||||
PyDTrace_FUNCTION_RETURN(filename, funcname, lineno);
|
||||
}
|
||||
|
@ -7718,11 +7720,12 @@ maybe_dtrace_line(_PyInterpreterFrame *frame,
|
|||
*/
|
||||
initialize_trace_info(trace_info, frame);
|
||||
int lastline = _PyCode_CheckLineNumber(instr_prev*sizeof(_Py_CODEUNIT), &trace_info->bounds);
|
||||
int line = _PyCode_CheckLineNumber(frame->f_lasti*sizeof(_Py_CODEUNIT), &trace_info->bounds);
|
||||
int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT);
|
||||
int line = _PyCode_CheckLineNumber(addr, &trace_info->bounds);
|
||||
if (line != -1) {
|
||||
/* Trace backward edges or first instruction of a new line */
|
||||
if (frame->f_lasti < instr_prev ||
|
||||
(line != lastline && frame->f_lasti*sizeof(_Py_CODEUNIT) == (unsigned int)trace_info->bounds.ar_start))
|
||||
if (_PyInterpreterFrame_LASTI(frame) < instr_prev ||
|
||||
(line != lastline && addr == trace_info->bounds.ar_start))
|
||||
{
|
||||
co_filename = PyUnicode_AsUTF8(frame->f_code->co_filename);
|
||||
if (!co_filename) {
|
||||
|
|
|
@ -127,3 +127,10 @@ _PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func)
|
|||
_PyFrame_InitializeSpecials(new_frame, func, NULL, code->co_nlocalsplus);
|
||||
return new_frame;
|
||||
}
|
||||
|
||||
int
|
||||
_PyInterpreterFrame_GetLine(_PyInterpreterFrame *frame)
|
||||
{
|
||||
int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT);
|
||||
return PyCode_Addr2Line(frame->f_code, addr);
|
||||
}
|
||||
|
|
|
@ -238,8 +238,8 @@ _PyTraceBack_FromFrame(PyObject *tb_next, PyFrameObject *frame)
|
|||
{
|
||||
assert(tb_next == NULL || PyTraceBack_Check(tb_next));
|
||||
assert(frame != NULL);
|
||||
|
||||
return tb_create_raw((PyTracebackObject *)tb_next, frame, frame->f_frame->f_lasti*sizeof(_Py_CODEUNIT),
|
||||
int addr = _PyInterpreterFrame_LASTI(frame->f_frame) * sizeof(_Py_CODEUNIT);
|
||||
return tb_create_raw((PyTracebackObject *)tb_next, frame, addr,
|
||||
PyFrame_GetLineNumber(frame));
|
||||
}
|
||||
|
||||
|
@ -1180,7 +1180,7 @@ dump_frame(int fd, _PyInterpreterFrame *frame)
|
|||
PUTS(fd, "???");
|
||||
}
|
||||
|
||||
int lineno = PyCode_Addr2Line(code, frame->f_lasti*sizeof(_Py_CODEUNIT));
|
||||
int lineno = _PyInterpreterFrame_GetLine(frame);
|
||||
PUTS(fd, ", line ");
|
||||
if (lineno >= 0) {
|
||||
_Py_DumpDecimal(fd, (size_t)lineno);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue