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. */
| 1533 | exists, and otherwise will create a new module object. |
| 1534 | */ |
| 1535 | inline 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. |
nothing calls this directly
no test coverage detected