mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue 5954, PyFrame_GetLineNumber:
Most uses of PyCode_Addr2Line (http://www.google.com/codesearch?q=PyCode_Addr2Line) are just trying to get the line number of a specified frame, but there's no way to do that directly. Forcing people to go through the code object makes them know more about the guts of the interpreter than they should need. The remaining uses of PyCode_Addr2Line seem to be getting the line from a traceback (for example, http://www.google.com/codesearch/p?hl=en#u_9_nDrchrw/pygame-1.7.1release/src/base.c&q=PyCode_Addr2Line), which is replaced by the tb_lineno field. So we may be able to deprecate PyCode_Addr2Line entirely for external use.
This commit is contained in:
parent
1aa4700234
commit
f7f858d141
8 changed files with 36 additions and 20 deletions
|
@ -60,17 +60,19 @@ frame_getlocals(PyFrameObject *f, void *closure)
|
|||
return f->f_locals;
|
||||
}
|
||||
|
||||
int
|
||||
PyFrame_GetLineNumber(PyFrameObject *f)
|
||||
{
|
||||
if (f->f_trace)
|
||||
return f->f_lineno;
|
||||
else
|
||||
return PyCode_Addr2Line(f->f_code, f->f_lasti);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
frame_getlineno(PyFrameObject *f, void *closure)
|
||||
{
|
||||
int lineno;
|
||||
|
||||
if (f->f_trace)
|
||||
lineno = f->f_lineno;
|
||||
else
|
||||
lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);
|
||||
|
||||
return PyInt_FromLong(lineno);
|
||||
return PyInt_FromLong(PyFrame_GetLineNumber(f));
|
||||
}
|
||||
|
||||
/* Setter for f_lineno - you can set f_lineno from within a trace function in
|
||||
|
@ -351,16 +353,14 @@ frame_gettrace(PyFrameObject *f, void *closure)
|
|||
static int
|
||||
frame_settrace(PyFrameObject *f, PyObject* v, void *closure)
|
||||
{
|
||||
PyObject* old_value;
|
||||
|
||||
/* We rely on f_lineno being accurate when f_trace is set. */
|
||||
f->f_lineno = PyFrame_GetLineNumber(f);
|
||||
|
||||
PyObject* old_value = f->f_trace;
|
||||
|
||||
old_value = f->f_trace;
|
||||
Py_XINCREF(v);
|
||||
f->f_trace = v;
|
||||
|
||||
if (v != NULL)
|
||||
f->f_lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);
|
||||
|
||||
Py_XDECREF(old_value);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue