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