6#ifndef OPM_EMBED_MODULE
7#define OPM_EMBED_MODULE
10#include <pybind11/embed.h>
12#if (PYBIND11_VERSION_MAJOR > 2 || (PYBIND11_VERSION_MAJOR == 2 && PYBIND11_VERSION_MINOR >= 6))
13#define PYBIND11_INSTANCE_DEF(name) static pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name)
14#define PYBIND11_INSTANCE_MODULE(name) pybind11::module_::create_extension_module(PYBIND11_TOSTRING(name), \
16 &PYBIND11_CONCAT(pybind11_module_def_, name))
18#define PYBIND11_INSTANCE_DEF(name)
19#define PYBIND11_INSTANCE_MODULE(name) pybind11::module(PYBIND11_TOSTRING(name))
22#define OPM_EMBEDDED_MODULE(name, variable) \
23 PYBIND11_INSTANCE_DEF(name); \
24 static void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &); \
25 static PyObject PYBIND11_CONCAT(*pybind11_init_wrapper_, name)() { \
26 auto m = PYBIND11_INSTANCE_MODULE(name); \
28 PYBIND11_CONCAT(pybind11_init_, name)(m); \
30 } catch (pybind11::error_already_set &e) { \
31 PyErr_SetString(PyExc_ImportError, e.what()); \
33 } catch (const std::exception &e) { \
34 PyErr_SetString(PyExc_ImportError, e.what()); \
38 PYBIND11_EMBEDDED_MODULE_IMPL(name) \
39 Opm::embed::python_module name(PYBIND11_TOSTRING(name), \
40 PYBIND11_CONCAT(pybind11_init_impl_, name)); \
41 void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable)
48#if PY_MAJOR_VERSION >= 3
49 using init_t = PyObject *(*)();
51 using init_t = void (*)();
53 python_module(
const char *name, init_t init) {
55 auto result = PyImport_AppendInittab(name, init);
57 pybind11::pybind11_fail(
"Insufficient memory to add a new module");
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30