Merge pull request #1777 from KLayout/bugfix/issue-1771

Bugfix/issue 1771
This commit is contained in:
Matthias Köfferlein 2024-07-06 14:49:45 +02:00 committed by GitHub
commit 02506495c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -64,10 +64,15 @@ void check_error ()
if (exc_traceback) {
PyTracebackObject *traceback = (PyTracebackObject*) exc_traceback.get ();
for (PyTracebackObject *t = traceback; t; t = t->tb_next) {
int lineno = t->tb_lineno;
#if PY_VERSION_HEX >= 0x030B0000
backtrace.push_back (tl::BacktraceElement (python2c<std::string> (PyFrame_GetCode(t->tb_frame)->co_filename), t->tb_lineno));
// since version 3.11.7, lineno may be -1 and indicates that the frame has to be inspected
if (lineno < 0) {
lineno = PyFrame_GetLineNumber(t->tb_frame);
}
backtrace.push_back (tl::BacktraceElement (python2c<std::string> (PyFrame_GetCode(t->tb_frame)->co_filename), lineno));
#else
backtrace.push_back (tl::BacktraceElement (python2c<std::string> (t->tb_frame->f_code->co_filename), t->tb_lineno));
backtrace.push_back (tl::BacktraceElement (python2c<std::string> (t->tb_frame->f_code->co_filename), lineno));
#endif
}
std::reverse (backtrace.begin (), backtrace.end ());

View File

@ -177,6 +177,17 @@ END
macro.run
assert_equal(context.value, "x42")
begin
pya.eval_string("\n1/0")
rescue => ex
puts "Got exception (expected): " + ex.to_s
assert_equal(ex.to_s.index("ZeroDivisionError") != nil, true)
assert_equal(ex.to_s.index("division by zero") != nil, true)
# bug #1771
assert_equal(ex.to_s.index("(eval)") != nil, true)
assert_equal(ex.to_s.index(":2") != nil, true)
end
end
end