| 157 | } |
| 158 | |
| 159 | inline object get_python_state_dict() { |
| 160 | object state_dict; |
| 161 | #if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON) |
| 162 | state_dict = reinterpret_borrow<object>(PyEval_GetBuiltins()); |
| 163 | #else |
| 164 | auto *istate = get_interpreter_state_unchecked(); |
| 165 | if (istate) { |
| 166 | state_dict = reinterpret_borrow<object>(PyInterpreterState_GetDict(istate)); |
| 167 | } |
| 168 | #endif |
| 169 | if (!state_dict) { |
| 170 | raise_from(PyExc_SystemError, "pybind11::detail::get_python_state_dict() FAILED"); |
| 171 | throw error_already_set(); |
| 172 | } |
| 173 | return state_dict; |
| 174 | } |
| 175 | |
| 176 | // Python loads modules by default with dlopen with the RTLD_LOCAL flag; under libc++ and possibly |
| 177 | // other STLs, this means `typeid(A)` from one module won't equal `typeid(A)` from another module |