Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a396a88

Browse files
committed
Vladimir Marangozov: This fixes the line number in the string
representation of code objects when optimization is on (python -O). It was always reported as -1 instead of the real lineno.
1 parent fa9ef18 commit a396a88

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

Python/compile.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,11 @@ code_repr(co)
121121
{
122122
char buf[500];
123123
int lineno = -1;
124-
unsigned char *p;
125124
char *filename = "???";
126125
char *name = "???";
127126

128-
_PyCode_GETCODEPTR(co, &p);
129-
if (*p == SET_LINENO)
130-
lineno = (p[1] & 0xff) | ((p[2] & 0xff) << 8);
127+
if (co->co_firstlineno != 0)
128+
lineno = co->co_firstlineno;
131129
if (co->co_filename && PyString_Check(co->co_filename))
132130
filename = PyString_AsString(co->co_filename);
133131
if (co->co_name && PyString_Check(co->co_name))

0 commit comments

Comments
 (0)