MCPcopy Create free account
hub / github.com/pybind/pybind11 / cached_create_module

Function cached_create_module

include/pybind11/pybind11.h:1535–1551  ·  view source on GitHub ↗

A Py_mod_create slot function which will return the previously created module from the cache if one exists, and otherwise will create a new module object. */

Source from the content-addressed store, hash-verified

1533exists, and otherwise will create a new module object.
1534*/
1535inline PyObject *cached_create_module(PyObject *spec, PyModuleDef *) {
1536 (void) &cache_completed_module; // silence unused-function warnings, it is used in a macro
1537
1538 auto nameobj = getattr(reinterpret_borrow<object>(spec), "name", none());
1539 if (nameobj.is_none()) {
1540 set_error(PyExc_ImportError, "module spec is missing a name");
1541 return nullptr;
1542 }
1543
1544 auto *mod = get_cached_module(nameobj);
1545 if (mod) {
1546 Py_INCREF(mod);
1547 } else {
1548 mod = PyModule_NewObject(nameobj.ptr());
1549 }
1550 return mod;
1551}
1552
1553/// Must be a POD type, and must hold enough entries for all of the possible slots PLUS ONE for
1554/// the sentinel (0) end slot.

Callers

nothing calls this directly

Calls 5

getattrFunction · 0.85
noneClass · 0.85
get_cached_moduleFunction · 0.85
ptrMethod · 0.80
set_errorFunction · 0.70

Tested by

no test coverage detected