| 88 | /// \return A new Python reference, or NULL if an exception occurred |
| 89 | template <typename T, typename PyWrapper = PyObject* (*)(T)> |
| 90 | PyObject* WrapResult(Result<T> result, PyWrapper&& py_wrapper) { |
| 91 | static_assert(std::is_same_v<PyObject*, decltype(py_wrapper(std::declval<T>()))>, |
| 92 | "PyWrapper argument to WrapResult should return a PyObject* " |
| 93 | "when called with a T*"); |
| 94 | Status st = result.status(); |
| 95 | if (st.ok()) { |
| 96 | PyObject* py_value = py_wrapper(result.MoveValueUnsafe()); |
| 97 | st = CheckPyError(); |
| 98 | if (st.ok()) { |
| 99 | return py_value; |
| 100 | } |
| 101 | Py_XDECREF(py_value); // should be null, but who knows |
| 102 | } |
| 103 | // Status is an error, convert it to an exception. |
| 104 | return internal::convert_status(st); |
| 105 | } |
| 106 | |
| 107 | // A RAII-style helper that ensures the GIL is acquired inside a lexical block. |
| 108 | class ARROW_PYTHON_EXPORT PyAcquireGIL { |
no test coverage detected