summaryrefslogtreecommitdiffstats
path: root/Objects/frameobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/frameobject.c')
-rw-r--r--Objects/frameobject.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 07b7ef3..36538b1 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -41,12 +41,20 @@ int
PyFrame_GetLineNumber(PyFrameObject *f)
{
assert(f != NULL);
- if (f->f_lineno != 0) {
- return f->f_lineno;
+ if (f->f_lineno == -1) {
+ // We should calculate it once. If we can't get the line number,
+ // set f->f_lineno to 0.
+ f->f_lineno = PyUnstable_InterpreterFrame_GetLine(f->f_frame);
+ if (f->f_lineno < 0) {
+ f->f_lineno = 0;
+ return -1;
+ }
}
- else {
- return PyUnstable_InterpreterFrame_GetLine(f->f_frame);
+
+ if (f->f_lineno > 0) {
+ return f->f_lineno;
}
+ return PyUnstable_InterpreterFrame_GetLine(f->f_frame);
}
static PyObject *