1 //===- PybindUtils.h - Utilities for interop with pybind11 ------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef MLIR_BINDINGS_PYTHON_PYBINDUTILS_H 10 #define MLIR_BINDINGS_PYTHON_PYBINDUTILS_H 11 12 #include <pybind11/pybind11.h> 13 #include <pybind11/stl.h> 14 15 #include "llvm/ADT/Optional.h" 16 #include "llvm/ADT/Twine.h" 17 18 namespace pybind11 { 19 namespace detail { 20 template <typename T> 21 struct type_caster<llvm::Optional<T>> : optional_caster<llvm::Optional<T>> {}; 22 } // namespace detail 23 } // namespace pybind11 24 25 namespace mlir { 26 namespace python { 27 28 // Sets a python error, ready to be thrown to return control back to the 29 // python runtime. 30 // Correct usage: 31 // throw SetPyError(PyExc_ValueError, "Foobar'd"); 32 pybind11::error_already_set SetPyError(PyObject *excClass, 33 const llvm::Twine &message); 34 35 } // namespace python 36 } // namespace mlir 37 38 #endif // MLIR_BINDINGS_PYTHON_PYBINDUTILS_H 39