-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get the correct computed tb lineno #158
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2667,7 +2667,7 @@ void PyLib_RedirectStdOut(void) | |
|
||
|
||
static const int PYLIB_RECURSIVE_CUTOFF = 3; | ||
#define PyLib_TraceBack_LIMIT 1024 | ||
#define PyLib_TraceBack_LIMIT 1024 | ||
|
||
static PyObject *format_displayline(PyObject *filename, int lineno, PyObject *name) | ||
{ | ||
|
@@ -2730,6 +2730,13 @@ static int append_to_java_message(PyObject * pyObjUtf8, char **buf, int *bufLen | |
return 0; | ||
} | ||
|
||
static int get_traceback_lineno(PyTracebackObject *tb) { | ||
PyObject* po_lineno = PyObject_GetAttrString((PyObject*)tb, "tb_lineno"); | ||
int lineno = (int)PyLong_AsLong(po_lineno); | ||
JPy_DECREF(po_lineno); | ||
return lineno; | ||
} | ||
Comment on lines
+2733
to
+2738
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Took me a little bit to figure out what actually changed. python/cpython#111548 is a useful reference. I'm a bit surprised there's not a more official stable API around PyTracebackObject. I understand the need to wash through Does calling
it's seems to me that "lazily" means that it will be cached after first access? (If that is not the case, it seems like Assuming "yes", we could probably check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, and PyTracebackObject isn't part of the public stable API, so they are free to change the struct itself and how to use it. |
||
|
||
static int format_python_traceback(PyTracebackObject *tb, char **buf, int *bufLen) | ||
{ | ||
int err = 0; | ||
|
@@ -2752,9 +2759,10 @@ static int format_python_traceback(PyTracebackObject *tb, char **buf, int *bufLe | |
} | ||
while (tb != NULL && err == 0) { | ||
PyCodeObject* co = PyFrame_GetCode(tb->tb_frame); | ||
int tb_lineno = get_traceback_lineno(tb); | ||
if (last_file == NULL || | ||
co->co_filename != last_file || | ||
last_line == -1 || tb->tb_lineno != last_line || | ||
last_line == -1 || tb_lineno != last_line || | ||
last_name == NULL || co->co_name != last_name) { | ||
if (cnt > PYLIB_RECURSIVE_CUTOFF) { | ||
pyObjUtf8 = format_line_repeated(cnt); | ||
|
@@ -2765,15 +2773,15 @@ static int format_python_traceback(PyTracebackObject *tb, char **buf, int *bufLe | |
} | ||
} | ||
last_file = co->co_filename; | ||
last_line = tb->tb_lineno; | ||
last_line = tb_lineno; | ||
last_name = co->co_name; | ||
cnt = 0; | ||
} | ||
cnt++; | ||
if (err == 0 && cnt <= PYLIB_RECURSIVE_CUTOFF) { | ||
pyObjUtf8 = format_displayline( | ||
co->co_filename, | ||
tb->tb_lineno, | ||
tb_lineno, | ||
co->co_name); | ||
err = append_to_java_message(pyObjUtf8, buf, bufLen); | ||
if (err != 0) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to limit setuptools?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We reply on setuptools.command.test to run the test suite. See pypa/setuptools#4519 and a solution is out of scope for now. will create a ticket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#160 is filed.