| 40 | }; |
| 41 | |
| 42 | std::string FrameInfo::traceback() { |
| 43 | FrameInfoPtr cur = shared_from_this(); |
| 44 | std::list<FrameInfo*> frames; |
| 45 | while (cur) { |
| 46 | frames.push_front(cur.get()); |
| 47 | cur = cur->prev_frame; |
| 48 | } |
| 49 | std::string logs; |
| 50 | for (auto&& f : frames) { |
| 51 | auto code = py::handle((PyObject*)f->code_obj); |
| 52 | #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 10 |
| 53 | int lineno = PyCode_Addr2Line(f->code_obj, f->lineno); |
| 54 | #else |
| 55 | int lineno = f->lineno; |
| 56 | #endif |
| 57 | if (f->scope != "") |
| 58 | logs += "scope: <" + f->scope + ">\n"; |
| 59 | py::object filename = py::getattr(code, "co_filename"); |
| 60 | logs += py::str(filename); |
| 61 | logs += " , line "; |
| 62 | logs += std::to_string(lineno); |
| 63 | logs += ", in "; |
| 64 | logs += py::str(py::getattr(code, "co_name")); |
| 65 | logs += '\n'; |
| 66 | } |
| 67 | return logs; |
| 68 | } |
| 69 | |
| 70 | #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 6 |
| 71 | static Py_tss_t tss_key = Py_tss_NEEDS_INIT; |
no test coverage detected