mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
bpo-45355: Use sizeof(_Py_CODEUNIT) instead of literal 2 for the size of the code unit (GH-28711)
This commit is contained in:
parent
4f6e0680d0
commit
60b9e040c9
5 changed files with 15 additions and 15 deletions
|
@ -302,7 +302,7 @@ static void
|
||||||
tracemalloc_get_frame(InterpreterFrame *pyframe, frame_t *frame)
|
tracemalloc_get_frame(InterpreterFrame *pyframe, frame_t *frame)
|
||||||
{
|
{
|
||||||
frame->filename = unknown_filename;
|
frame->filename = unknown_filename;
|
||||||
int lineno = PyCode_Addr2Line(pyframe->f_code, pyframe->f_lasti*2);
|
int lineno = PyCode_Addr2Line(pyframe->f_code, pyframe->f_lasti*sizeof(_Py_CODEUNIT));
|
||||||
if (lineno < 0) {
|
if (lineno < 0) {
|
||||||
lineno = 0;
|
lineno = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ PyFrame_GetLineNumber(PyFrameObject *f)
|
||||||
return f->f_lineno;
|
return f->f_lineno;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return PyCode_Addr2Line(f->f_frame->f_code, f->f_frame->f_lasti*2);
|
return PyCode_Addr2Line(f->f_frame->f_code, f->f_frame->f_lasti*sizeof(_Py_CODEUNIT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ frame_getlasti(PyFrameObject *f, void *closure)
|
||||||
if (f->f_frame->f_lasti < 0) {
|
if (f->f_frame->f_lasti < 0) {
|
||||||
return PyLong_FromLong(-1);
|
return PyLong_FromLong(-1);
|
||||||
}
|
}
|
||||||
return PyLong_FromLong(f->f_frame->f_lasti*2);
|
return PyLong_FromLong(f->f_frame->f_lasti*sizeof(_Py_CODEUNIT));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -1284,7 +1284,7 @@ compute_cr_origin(int origin_depth)
|
||||||
PyCodeObject *code = frame->f_code;
|
PyCodeObject *code = frame->f_code;
|
||||||
PyObject *frameinfo = Py_BuildValue("OiO",
|
PyObject *frameinfo = Py_BuildValue("OiO",
|
||||||
code->co_filename,
|
code->co_filename,
|
||||||
PyCode_Addr2Line(frame->f_code, frame->f_lasti*2),
|
PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT)),
|
||||||
code->co_name);
|
code->co_name);
|
||||||
if (!frameinfo) {
|
if (!frameinfo) {
|
||||||
Py_DECREF(cr_origin);
|
Py_DECREF(cr_origin);
|
||||||
|
|
|
@ -4815,7 +4815,7 @@ check_eval_breaker:
|
||||||
#endif
|
#endif
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"XXX lineno: %d, opcode: %d\n",
|
"XXX lineno: %d, opcode: %d\n",
|
||||||
PyCode_Addr2Line(frame->f_code, frame->f_lasti*2),
|
PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT)),
|
||||||
opcode);
|
opcode);
|
||||||
_PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode");
|
_PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode");
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -5996,7 +5996,7 @@ call_trace(Py_tracefunc func, PyObject *obj,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
initialize_trace_info(&tstate->trace_info, frame);
|
initialize_trace_info(&tstate->trace_info, frame);
|
||||||
f->f_lineno = _PyCode_CheckLineNumber(frame->f_lasti*2, &tstate->trace_info.bounds);
|
f->f_lineno = _PyCode_CheckLineNumber(frame->f_lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds);
|
||||||
}
|
}
|
||||||
result = func(obj, f, what, arg);
|
result = func(obj, f, what, arg);
|
||||||
f->f_lineno = 0;
|
f->f_lineno = 0;
|
||||||
|
@ -6035,8 +6035,8 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
|
||||||
then call the trace function if we're tracing source lines.
|
then call the trace function if we're tracing source lines.
|
||||||
*/
|
*/
|
||||||
initialize_trace_info(&tstate->trace_info, frame);
|
initialize_trace_info(&tstate->trace_info, frame);
|
||||||
int lastline = _PyCode_CheckLineNumber(instr_prev*2, &tstate->trace_info.bounds);
|
int lastline = _PyCode_CheckLineNumber(instr_prev*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds);
|
||||||
int line = _PyCode_CheckLineNumber(frame->f_lasti*2, &tstate->trace_info.bounds);
|
int line = _PyCode_CheckLineNumber(frame->f_lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds);
|
||||||
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
|
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -6978,7 +6978,7 @@ dtrace_function_entry(InterpreterFrame *frame)
|
||||||
PyCodeObject *code = frame->f_code;
|
PyCodeObject *code = frame->f_code;
|
||||||
filename = PyUnicode_AsUTF8(code->co_filename);
|
filename = PyUnicode_AsUTF8(code->co_filename);
|
||||||
funcname = PyUnicode_AsUTF8(code->co_name);
|
funcname = PyUnicode_AsUTF8(code->co_name);
|
||||||
lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti*2);
|
lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT));
|
||||||
|
|
||||||
PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno);
|
PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno);
|
||||||
}
|
}
|
||||||
|
@ -6993,7 +6993,7 @@ dtrace_function_return(InterpreterFrame *frame)
|
||||||
PyCodeObject *code = frame->f_code;
|
PyCodeObject *code = frame->f_code;
|
||||||
filename = PyUnicode_AsUTF8(code->co_filename);
|
filename = PyUnicode_AsUTF8(code->co_filename);
|
||||||
funcname = PyUnicode_AsUTF8(code->co_name);
|
funcname = PyUnicode_AsUTF8(code->co_name);
|
||||||
lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti*2);
|
lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT));
|
||||||
|
|
||||||
PyDTrace_FUNCTION_RETURN(filename, funcname, lineno);
|
PyDTrace_FUNCTION_RETURN(filename, funcname, lineno);
|
||||||
}
|
}
|
||||||
|
@ -7010,12 +7010,12 @@ maybe_dtrace_line(InterpreterFrame *frame,
|
||||||
instruction window, reset the window.
|
instruction window, reset the window.
|
||||||
*/
|
*/
|
||||||
initialize_trace_info(trace_info, frame);
|
initialize_trace_info(trace_info, frame);
|
||||||
int lastline = _PyCode_CheckLineNumber(instr_prev*2, &trace_info->bounds);
|
int lastline = _PyCode_CheckLineNumber(instr_prev*sizeof(_Py_CODEUNIT), &trace_info->bounds);
|
||||||
int line = _PyCode_CheckLineNumber(frame->f_lasti*2, &trace_info->bounds);
|
int line = _PyCode_CheckLineNumber(frame->f_lasti*sizeof(_Py_CODEUNIT), &trace_info->bounds);
|
||||||
if (line != -1) {
|
if (line != -1) {
|
||||||
/* Trace backward edges or first instruction of a new line */
|
/* Trace backward edges or first instruction of a new line */
|
||||||
if (frame->f_lasti < instr_prev ||
|
if (frame->f_lasti < instr_prev ||
|
||||||
(line != lastline && frame->f_lasti*2 == trace_info->bounds.ar_start))
|
(line != lastline && frame->f_lasti*sizeof(_Py_CODEUNIT) == trace_info->bounds.ar_start))
|
||||||
{
|
{
|
||||||
co_filename = PyUnicode_AsUTF8(frame->f_code->co_filename);
|
co_filename = PyUnicode_AsUTF8(frame->f_code->co_filename);
|
||||||
if (!co_filename) {
|
if (!co_filename) {
|
||||||
|
|
|
@ -240,7 +240,7 @@ _PyTraceBack_FromFrame(PyObject *tb_next, PyFrameObject *frame)
|
||||||
assert(tb_next == NULL || PyTraceBack_Check(tb_next));
|
assert(tb_next == NULL || PyTraceBack_Check(tb_next));
|
||||||
assert(frame != NULL);
|
assert(frame != NULL);
|
||||||
|
|
||||||
return tb_create_raw((PyTracebackObject *)tb_next, frame, frame->f_frame->f_lasti*2,
|
return tb_create_raw((PyTracebackObject *)tb_next, frame, frame->f_frame->f_lasti*sizeof(_Py_CODEUNIT),
|
||||||
PyFrame_GetLineNumber(frame));
|
PyFrame_GetLineNumber(frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1047,7 +1047,7 @@ dump_frame(int fd, InterpreterFrame *frame)
|
||||||
PUTS(fd, "???");
|
PUTS(fd, "???");
|
||||||
}
|
}
|
||||||
|
|
||||||
int lineno = PyCode_Addr2Line(code, frame->f_lasti*2);
|
int lineno = PyCode_Addr2Line(code, frame->f_lasti*sizeof(_Py_CODEUNIT));
|
||||||
PUTS(fd, ", line ");
|
PUTS(fd, ", line ");
|
||||||
if (lineno >= 0) {
|
if (lineno >= 0) {
|
||||||
_Py_DumpDecimal(fd, (size_t)lineno);
|
_Py_DumpDecimal(fd, (size_t)lineno);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue