[Python-checkins] python/dist/src/Python compile.c,2.300,2.301
arigo at users.sourceforge.net
arigo at users.sourceforge.net
Mon Mar 22 12:52:56 EST 2004
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13591
Modified Files:
compile.c
Log Message:
Fix for line events in the case:
def f(a):
if a:
print 5
else:
pass
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.300
retrieving revision 2.301
diff -C2 -d -r2.300 -r2.301
*** compile.c 21 Mar 2004 15:12:00 -0000 2.300
--- compile.c 22 Mar 2004 17:52:53 -0000 2.301
***************
*** 630,634 ****
int c_firstlineno;
PyObject *c_lnotab; /* Table mapping address to line number */
! int c_last_addr, c_last_line, c_lnotab_next;
char *c_private; /* for private name mangling */
int c_tmpname; /* temporary local name counter */
--- 630,637 ----
int c_firstlineno;
PyObject *c_lnotab; /* Table mapping address to line number */
! int c_last_addr; /* last op addr seen and recorded in lnotab */
! int c_last_line; /* last line seen and recorded in lnotab */
! int c_lnotab_next; /* current length of lnotab */
! int c_lnotab_last; /* start of last lnotab record added */
char *c_private; /* for private name mangling */
int c_tmpname; /* temporary local name counter */
***************
*** 849,852 ****
--- 852,856 ----
c->c_last_line = 0;
c->c_lnotab_next = 0;
+ c->c_lnotab_last = 0;
c->c_tmpname = 0;
c->c_nested = 0;
***************
*** 965,968 ****
--- 969,973 ----
int incr_addr = c->c_nexti - c->c_last_addr;
int incr_line = lineno - c->c_last_line;
+ c->c_lnotab_last = c->c_lnotab_next;
while (incr_addr > 255) {
com_add_lnotab(c, 255, 0);
***************
*** 982,985 ****
--- 987,1011 ----
static void
+ com_strip_lnotab(struct compiling *c)
+ {
+ /* strip the last lnotab entry if no opcode were emitted.
+ * This prevents a line number to be generated on a final
+ * pass, like in the following example:
+ *
+ * if a:
+ * print 5
+ * else:
+ * pass
+ *
+ * Without the fix, a line trace event would be generated
+ * on the pass even if a is true (because of the implicit
+ * return).
+ */
+ if (c->c_nexti == c->c_last_addr && c->c_lnotab_last > 0) {
+ c->c_lnotab_next = c->c_lnotab_last;
+ }
+ }
+
+ static void
com_addoparg(struct compiling *c, int op, int arg)
{
***************
*** 4168,4171 ****
--- 4194,4198 ----
com_node(c, CHILD(n, 4));
c->c_infunction = 0;
+ com_strip_lnotab(c);
com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None));
com_push(c, 1);
***************
*** 4219,4222 ****
--- 4246,4250 ----
(void) com_addconst(c, Py_None);
com_node(c, ch);
+ com_strip_lnotab(c);
com_addbyte(c, LOAD_LOCALS);
com_push(c, 1);
***************
*** 4238,4241 ****
--- 4266,4270 ----
if (TYPE(n) != NEWLINE)
com_node(c, n);
+ com_strip_lnotab(c);
com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None));
com_push(c, 1);
***************
*** 4247,4250 ****
--- 4276,4280 ----
case file_input: /* A whole file, or built-in function exec() */
com_file_input(c, n);
+ com_strip_lnotab(c);
com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None));
com_push(c, 1);
More information about the Python-checkins
mailing list