18 void interleaved_error_already_set() {
21 throw py::error_already_set();
22 }
catch (
const py::error_already_set &) {
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 *");
45 #ifdef Py_GIL_DISABLED
46 PyUnstable_Module_SetGIL(
m, Py_MOD_GIL_NOT_USED);
51 PyLong_FromVoidPtr(
reinterpret_cast<void *
>(&interleaved_error_already_set)));