\rst Adds an object to the module using the given name. Throws if an object with the given name already exists. ``overwrite`` should almost always be false: attempting to overwrite objects that pybind11 has established will, in most cases, break things. \endrst */
| 1688 | has established will, in most cases, break things. |
| 1689 | \endrst */ |
| 1690 | PYBIND11_NOINLINE void add_object(const char *name, handle obj, bool overwrite = false) { |
| 1691 | if (!overwrite && hasattr(*this, name)) { |
| 1692 | pybind11_fail( |
| 1693 | "Error during initialization: multiple incompatible definitions with name \"" |
| 1694 | + std::string(name) + "\""); |
| 1695 | } |
| 1696 | |
| 1697 | PyModule_AddObject(ptr(), name, obj.inc_ref().ptr() /* steals a reference */); |
| 1698 | } |
| 1699 | |
| 1700 | // DEPRECATED (since PR #5688): Use PyModuleDef directly instead. |
| 1701 | using module_def = PyModuleDef; |
no test coverage detected