| 150 | // The GIL is acquired, and the current thread's error status is preserved. |
| 151 | template <typename Function> |
| 152 | auto SafeCallIntoPython(Function&& func) -> decltype(func()) { |
| 153 | PyAcquireGIL lock; |
| 154 | PyObject* exc_type; |
| 155 | PyObject* exc_value; |
| 156 | PyObject* exc_traceback; |
| 157 | PyErr_Fetch(&exc_type, &exc_value, &exc_traceback); |
| 158 | auto maybe_status = std::forward<Function>(func)(); |
| 159 | // If the return Status is a "Python error", the current Python error status |
| 160 | // describes the error and shouldn't be clobbered. |
| 161 | if (!IsPyError(::arrow::ToStatus(maybe_status)) && exc_type != NULLPTR) { |
| 162 | PyErr_Restore(exc_type, exc_value, exc_traceback); |
| 163 | } |
| 164 | return maybe_status; |
| 165 | } |
| 166 | |
| 167 | template <typename Function> |
| 168 | auto SafeCallIntoPythonVoid(Function&& func) -> decltype(func()) { |
no test coverage detected