New submission from Xavier de Gaye:

The last paragraph of Objects/lnotab_notes.txt explains that the f_lineno 
member of the PyFrameObject structure is needed to store the line number of the 
last "line" tracing event so that this value may be used as the line number of 
the "return" event instead of the (sometimes confusing) value computed from 
f_lasti.  The f_lineno getter must then return the value of f->f_lineno 
(instead of the value computed from f->f_lasti) when tracing is set. The 
current implementation translates "tracing is set" as "the local f_trace trace 
function is not NULL", this is wrong for the following reasons:

* AFAIK it is not documented anywhere that Python users implementing a trace 
function must delete the local f_trace functions of all the frames when setting 
the
  global trace function to None via sys.settrace(None) (issue 7238).

* Bdb.set_continue() in the bdb module of the std lib seems to know about this 
and attempts to do it, but fails to delete f_trace from the topmost frame, 
named botframe (sic) (issue 16482, issue 17697).

* It is not obvious how to delete the f_trace of all suspended generators when 
setting the global trace function to None (issue 17277).

* _PyTraceback_Add() in Python/traceback.c sets frame->f_lineno, obviously 
forgetting that it is useless since its f_trace is NULL.

This patch changes the semantics of f_lineno by stating that f_lineno is 
invalid when its value is -1. When tracing, the f_lineno of all the frames on 
the stack is valid. The f_lineno of a suspended generator is always invalid.

----------
components: Interpreter Core
files: f_lineno.patch
keywords: patch
messages: 246275
nosy: belopolsky, xdegaye
priority: normal
severity: normal
status: open
title: the f_lineno getter is broken
versions: Python 3.6
Added file: http://bugs.python.org/file39865/f_lineno.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24565>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to