summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2009-05-08 22:23:21 (GMT)
committerJeffrey Yasskin <jyasskin@gmail.com>2009-05-08 22:23:21 (GMT)
commitf7f858d1415514cb9a76a5b7da8ee6ccb774e6f4 (patch)
treec6bd7974442855ae64181f09fb6b2ccd2cc20b72 /Objects
parent1aa4700234aa0657ee8cb12cfd9b615fef9e0300 (diff)
downloadcpython-f7f858d1415514cb9a76a5b7da8ee6ccb774e6f4.zip
cpython-f7f858d1415514cb9a76a5b7da8ee6ccb774e6f4.tar.gz
cpython-f7f858d1415514cb9a76a5b7da8ee6ccb774e6f4.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/frameobject.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 4ac1ab0..7a9d40d 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -60,17 +60,19 @@ frame_getlocals(PyFrameObject *f, void *closure)
return f->f_locals;
}
-static PyObject *
-frame_getlineno(PyFrameObject *f, void *closure)
+int
+PyFrame_GetLineNumber(PyFrameObject *f)
{
- int lineno;
-
if (f->f_trace)
- lineno = f->f_lineno;
+ return f->f_lineno;
else
- lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);
+ return PyCode_Addr2Line(f->f_code, f->f_lasti);
+}
- return PyInt_FromLong(lineno);
+static PyObject *
+frame_getlineno(PyFrameObject *f, void *closure)
+{
+ 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)
{
- /* We rely on f_lineno being accurate when f_trace is set. */
+ PyObject* old_value;
- PyObject* old_value = f->f_trace;
+ /* We rely on f_lineno being accurate when f_trace is set. */
+ f->f_lineno = PyFrame_GetLineNumber(f);
+ 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;