| 50 | }; |
| 51 | |
| 52 | struct TraceKeyWrapper { |
| 53 | int key; |
| 54 | std::string scope; |
| 55 | py::object orig_func; |
| 56 | TraceKeyWrapper(int key, PyObject* func, std::string scope = "") |
| 57 | : key{key}, scope{std::move(scope)} { |
| 58 | if (func != NULL) { |
| 59 | orig_func = py::reinterpret_steal<py::object>(func); |
| 60 | } |
| 61 | } |
| 62 | static constexpr auto tp_name = pybind11::detail::_("TraceKeyWrapper"); |
| 63 | using wrap_t = pyext17::wrap<TraceKeyWrapper>; |
| 64 | friend wrap_t; |
| 65 | |
| 66 | inline static TraceKeyWrapper* cast(PyObject* obj) { |
| 67 | return reinterpret_cast<wrap_t*>(obj)->inst(); |
| 68 | } |
| 69 | inline static TraceKeyWrapper* try_cast(PyObject* obj) { |
| 70 | if (obj == NULL || !wrap_t::type().isinstance(obj)) |
| 71 | return nullptr; |
| 72 | return cast(obj); |
| 73 | } |
| 74 | |
| 75 | template <typename... Args> |
| 76 | static PyObject* make(Args&&... args) { |
| 77 | return wrap_t::cnew(std::forward<Args>(args)...); |
| 78 | } |
| 79 | |
| 80 | PyObject* tp_call(PyObject* args, PyObject* kwargs) { |
| 81 | if (orig_func.ptr() != nullptr) { |
| 82 | return PyObject_Call(orig_func.ptr(), args, kwargs); |
| 83 | } |
| 84 | Py_RETURN_NONE; |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | FrameInfoPtr get_frameinfo_from_pyframe(PyFrameObject* frame); |
| 89 | void record_py_backtrace(); |