diff options
Diffstat (limited to 'Objects/frameobject.c')
-rw-r--r-- | Objects/frameobject.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c index e29c647..8bb0f9c 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -98,7 +98,8 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno) if (!f->f_trace) { PyErr_Format(PyExc_ValueError, - "f_lineno can only be set by a trace function"); + "f_lineno can only be set by a" + " line trace function"); return -1; } @@ -122,20 +123,26 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno) new_lineno); return -1; } - - /* Find the bytecode offset for the start of the given line, or the - * first code-owning line after it. */ - PyBytes_AsStringAndSize(f->f_code->co_lnotab, &lnotab, &lnotab_len); - addr = 0; - line = f->f_code->co_firstlineno; - new_lasti = -1; - for (offset = 0; offset < lnotab_len; offset += 2) { - addr += lnotab[offset]; - line += lnotab[offset+1]; - if (line >= new_lineno) { - new_lasti = addr; - new_lineno = line; - break; + else if (new_lineno == f->f_code->co_firstlineno) { + new_lasti = 0; + new_lineno = f->f_code->co_firstlineno; + } + else { + /* Find the bytecode offset for the start of the given + * line, or the first code-owning line after it. */ + PyBytes_AsStringAndSize(f->f_code->co_lnotab, + &lnotab, &lnotab_len); + addr = 0; + line = f->f_code->co_firstlineno; + new_lasti = -1; + for (offset = 0; offset < lnotab_len; offset += 2) { + addr += lnotab[offset]; + line += lnotab[offset+1]; + if (line >= new_lineno) { + new_lasti = addr; + new_lineno = line; + break; + } } } |