15 #if defined(PYPY_VERSION) 16 # error Embedding the interpreter is not supported with PyPy 19 #if PY_MAJOR_VERSION >= 3 20 # define PYBIND11_EMBEDDED_MODULE_IMPL(name) \ 21 extern "C" PyObject *pybind11_init_impl_##name(); \ 22 extern "C" PyObject *pybind11_init_impl_##name() { \ 23 return pybind11_init_wrapper_##name(); \ 26 # define PYBIND11_EMBEDDED_MODULE_IMPL(name) \ 27 extern "C" void pybind11_init_impl_##name(); \ 28 extern "C" void pybind11_init_impl_##name() { \ 29 pybind11_init_wrapper_##name(); \ 48 #define PYBIND11_EMBEDDED_MODULE(name, variable) \ 49 static void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &); \ 50 static PyObject PYBIND11_CONCAT(*pybind11_init_wrapper_, name)() { \ 51 auto m = pybind11::module(PYBIND11_TOSTRING(name)); \ 53 PYBIND11_CONCAT(pybind11_init_, name)(m); \ 55 } catch (pybind11::error_already_set &e) { \ 56 PyErr_SetString(PyExc_ImportError, e.what()); \ 58 } catch (const std::exception &e) { \ 59 PyErr_SetString(PyExc_ImportError, e.what()); \ 63 PYBIND11_EMBEDDED_MODULE_IMPL(name) \ 64 pybind11::detail::embedded_module PYBIND11_CONCAT(pybind11_module_, name) \ 65 (PYBIND11_TOSTRING(name), \ 66 PYBIND11_CONCAT(pybind11_init_impl_, name)); \ 67 void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable) 75 #if PY_MAJOR_VERSION >= 3 76 using init_t = PyObject *(*)();
78 using init_t = void (*)();
81 if (Py_IsInitialized())
82 pybind11_fail(
"Can't add new modules after the interpreter has been initialized");
84 auto result = PyImport_AppendInittab(name, init);
106 if (Py_IsInitialized())
109 Py_InitializeEx(init_signal_handlers ? 1 : 0);
151 handle builtins(PyEval_GetBuiltins());
159 if (builtins.contains(
id) && isinstance<capsule>(builtins[
id]))
160 internals_ptr_ptr =
capsule(builtins[
id]);
164 if (internals_ptr_ptr) {
165 delete *internals_ptr_ptr;
166 *internals_ptr_ptr =
nullptr;
void initialize_interpreter(bool init_signal_handlers=true)
embedded_module(const char *name, init_t init)
Q id(Eigen::AngleAxisd(0, Q_z_axis))
scoped_interpreter(bool init_signal_handlers=true)
void finalize_interpreter()
Tuple< Args..., T > append(Tuple< Args... > t, T a)
the deduction function for append_base that automatically generate the IndexRange ...
scoped_interpreter(scoped_interpreter &&other) noexcept
#define PYBIND11_NAMESPACE
PyExc_RuntimeError[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
scoped_interpreter & operator=(const scoped_interpreter &)=delete
Python 2.7/3.x compatible version of PyImport_AppendInittab and error checks.
#define PYBIND11_INTERNALS_ID
static module_ import(const char *name)
Import and return a module or throws error_already_set.
Annotation for function names.
internals **& get_internals_pp()
#define PYBIND11_NAMESPACE_END(name)
#define PYBIND11_NAMESPACE_BEGIN(name)