18 void interleaved_error_already_set() {
19 PyErr_SetString(PyExc_RuntimeError,
"1st error.");
21 throw py::error_already_set();
22 }
catch (
const py::error_already_set &) {
24 PyErr_SetString(PyExc_RuntimeError,
"2nd error.");
28 if (PyErr_Occurred()) {
29 throw py::error_already_set();
33 constexpr
char kModuleName[] =
"cross_module_interleaved_error_already_set";
35 struct PyModuleDef moduledef = {
36 PyModuleDef_HEAD_INIT, kModuleName,
nullptr, 0,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr};
41 PyObject *
m = PyModule_Create(&moduledef);
43 static_assert(
sizeof(&interleaved_error_already_set) ==
sizeof(
void *),
44 "Function pointer must have the same size as void *");
48 PyLong_FromVoidPtr(reinterpret_cast<void *>(&interleaved_error_already_set)));
PYBIND11_EXPORT PyObject * PyInit_cross_module_interleaved_error_already_set()