diff options
author | Mark Shannon <mark@hotpy.org> | 2021-01-05 12:04:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-05 12:04:10 (GMT) |
commit | ee9f98d9f4b881ee15868a836a2b99271df1bc0e (patch) | |
tree | 5f5a6b4cc99c86d7ee99cf0c8287cf601abd99a7 /Objects | |
parent | e40e2a2cc94c554e7e245a8ca5a7432d31a95766 (diff) | |
download | cpython-ee9f98d9f4b881ee15868a836a2b99271df1bc0e.zip cpython-ee9f98d9f4b881ee15868a836a2b99271df1bc0e.tar.gz cpython-ee9f98d9f4b881ee15868a836a2b99271df1bc0e.tar.bz2 |
bpo-42823: Fix frame lineno when frame.f_trace is set (GH-24099)
* Add test for frame.f_lineno with/without tracing.
* Make sure that frame.f_lineno is correct regardless of whether frame.f_trace is set.
* Update importlib
* Add NEWS
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/codeobject.c | 3 | ||||
-rw-r--r-- | Objects/frameobject.c | 12 |
2 files changed, 7 insertions, 8 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 0b0b8f9..f7613e8 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1261,7 +1261,8 @@ PyLineTable_InitAddressRange(char *linetable, int firstlineno, PyCodeAddressRang range->lo_next = linetable; range->ar_start = -1; range->ar_end = 0; - range->ar_computed_line = range->ar_line = firstlineno; + range->ar_computed_line = firstlineno; + range->ar_line = -1; } int diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 787cd8b..4c5eaa2 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -44,7 +44,7 @@ int PyFrame_GetLineNumber(PyFrameObject *f) { assert(f != NULL); - if (f->f_trace) { + if (f->f_lineno != 0) { return f->f_lineno; } else { @@ -476,8 +476,8 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore start_block_stack = pop_block(start_block_stack); } - /* Finally set the new f_lineno and f_lasti and return OK. */ - f->f_lineno = new_lineno; + /* Finally set the new f_lasti and return OK. */ + f->f_lineno = 0; f->f_lasti = best_addr; return 0; } @@ -498,11 +498,9 @@ frame_gettrace(PyFrameObject *f, void *closure) static int frame_settrace(PyFrameObject *f, PyObject* v, void *closure) { - /* We rely on f_lineno being accurate when f_trace is set. */ - f->f_lineno = PyFrame_GetLineNumber(f); - - if (v == Py_None) + if (v == Py_None) { v = NULL; + } Py_XINCREF(v); Py_XSETREF(f->f_trace, v); |