Return a borrowed reference to the named module if it has been successfully initialized within this interpreter before. nullptr if it has not been successfully initialized. */
| 1504 | interpreter before. nullptr if it has not been successfully initialized. |
| 1505 | */ |
| 1506 | inline PyObject *get_cached_module(pybind11::str const &nameobj) { |
| 1507 | dict state = detail::get_python_state_dict(); |
| 1508 | if (!state.contains("__pybind11_module_cache")) { |
| 1509 | return nullptr; |
| 1510 | } |
| 1511 | dict cache = state["__pybind11_module_cache"]; |
| 1512 | if (!cache.contains(nameobj)) { |
| 1513 | return nullptr; |
| 1514 | } |
| 1515 | return cache[nameobj].ptr(); |
| 1516 | } |
| 1517 | |
| 1518 | /* |
| 1519 | Add successfully initialized a module object to the internal cache. |
no test coverage detected