Skip to content

Commit 48c7be4

Browse files
committed
Undoing previous accidental commit. Sorry I forgot to git branch.
1 parent 5621ab8 commit 48c7be4

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

include/pybind11/detail/type_caster_base.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,46 @@ PYBIND11_NOINLINE std::string error_string() {
493493
PyException_SetTraceback(scope.value, scope.trace);
494494
}
495495

496+
#if !defined(PYPY_VERSION)
497+
if (scope.trace) {
498+
auto *trace = (PyTracebackObject *) scope.trace;
499+
500+
/* Get the deepest trace possible */
501+
while (trace->tb_next) {
502+
trace = trace->tb_next;
503+
}
504+
505+
PyFrameObject *frame = trace->tb_frame;
506+
Py_XINCREF(frame);
507+
errorString += "\n\nAt:\n";
508+
while (frame) {
509+
# if PY_VERSION_HEX >= 0x030900B1
510+
PyCodeObject *f_code = PyFrame_GetCode(frame);
511+
# else
512+
PyCodeObject *f_code = frame->f_code;
513+
Py_INCREF(f_code);
514+
# endif
515+
int lineno = PyFrame_GetLineNumber(frame);
516+
errorString += " ";
517+
errorString += handle(f_code->co_filename).cast<std::string>();
518+
errorString += '(';
519+
errorString += std::to_string(lineno);
520+
errorString += "): ";
521+
errorString += handle(f_code->co_name).cast<std::string>();
522+
errorString += '\n';
523+
Py_DECREF(f_code);
524+
# if PY_VERSION_HEX >= 0x030900B1
525+
auto *b_frame = PyFrame_GetBack(frame);
526+
# else
527+
auto *b_frame = frame->f_back;
528+
Py_XINCREF(b_frame);
529+
# endif
530+
Py_DECREF(frame);
531+
frame = b_frame;
532+
}
533+
}
534+
#endif
535+
496536
return errorString;
497537
}
498538

0 commit comments

Comments
 (0)