mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
adjusted module::add_object signature so that it accepts a py::handle
This commit is contained in:
parent
194d8b99b3
commit
aa1b316f6f
@ -771,13 +771,12 @@ public:
|
|||||||
//
|
//
|
||||||
// overwrite should almost always be false: attempting to overwrite objects that pybind11 has
|
// overwrite should almost always be false: attempting to overwrite objects that pybind11 has
|
||||||
// established will, in most cases, break things.
|
// established will, in most cases, break things.
|
||||||
PYBIND11_NOINLINE void add_object(const char *name, object &obj, bool overwrite = false) {
|
PYBIND11_NOINLINE void add_object(const char *name, handle obj, bool overwrite = false) {
|
||||||
if (!overwrite && hasattr(*this, name))
|
if (!overwrite && hasattr(*this, name))
|
||||||
pybind11_fail("Error during initialization: multiple incompatible definitions with name \"" +
|
pybind11_fail("Error during initialization: multiple incompatible definitions with name \"" +
|
||||||
std::string(name) + "\"");
|
std::string(name) + "\"");
|
||||||
|
|
||||||
obj.inc_ref(); // PyModule_AddObject() steals a reference
|
PyModule_AddObject(ptr(), name, obj.inc_ref().ptr() /* steals a reference */);
|
||||||
PyModule_AddObject(ptr(), name, obj.ptr());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user