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/Twine.h" 16 17 namespace mlir { 18 namespace python { 19 20 // Sets a python error, ready to be thrown to return control back to the 21 // python runtime. 22 // Correct usage: 23 // throw SetPyError(PyExc_ValueError, "Foobar'd"); 24 pybind11::error_already_set SetPyError(PyObject *excClass, 25 const llvm::Twine &message); 26 27 } // namespace python 28 } // namespace mlir 29 30 #endif // MLIR_BINDINGS_PYTHON_PYBINDUTILS_H 31