summaryrefslogtreecommitdiffstats
path: root/Include
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 /Include
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 'Include')
-rw-r--r--Include/code.h3
-rw-r--r--Include/frameobject.h10
2 files changed, 11 insertions, 2 deletions
diff --git a/Include/code.h b/Include/code.h
index 0167ad4..cbf00d8 100644
--- a/Include/code.h
+++ b/Include/code.h
@@ -75,6 +75,9 @@ PyAPI_FUNC(PyCodeObject *) PyCode_New(
PyAPI_FUNC(PyCodeObject *)
PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno);
+/* Return the line number associated with the specified bytecode index
+ in this code object. If you just need the line number of a frame,
+ use PyFrame_GetLineNumber() instead. */
PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
/* for internal use only */
diff --git a/Include/frameobject.h b/Include/frameobject.h
index 297b66d..17e7679 100644
--- a/Include/frameobject.h
+++ b/Include/frameobject.h
@@ -38,8 +38,11 @@ typedef struct _frame {
PyThreadState *f_tstate;
int f_lasti; /* Last instruction if called */
- /* As of 2.3 f_lineno is only valid when tracing is active (i.e. when
- f_trace is set) -- at other times use PyCode_Addr2Line instead. */
+ /* Call PyFrame_GetLineNumber() instead of reading this field
+ directly. As of 2.3 f_lineno is only valid when tracing is
+ active (i.e. when f_trace is set). At other times we use
+ PyCode_Addr2Line to calculate the line from the current
+ bytecode index. */
int f_lineno; /* Current line number */
int f_iblock; /* index in f_blockstack */
PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
@@ -77,6 +80,9 @@ PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
+/* Return the line of code the frame is currently executing. */
+PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
+
#ifdef __cplusplus
}
#endif