From aa1b316f6f3e8f5acb18c79584589203508f9a88 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Thu, 30 Mar 2017 11:59:32 +0200 Subject: [PATCH] adjusted module::add_object signature so that it accepts a py::handle --- include/pybind11/pybind11.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 5976a36d8..36a12e95a 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -771,13 +771,12 @@ public: // // overwrite should almost always be false: attempting to overwrite objects that pybind11 has // 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)) pybind11_fail("Error during initialization: multiple incompatible definitions with name \"" + std::string(name) + "\""); - obj.inc_ref(); // PyModule_AddObject() steals a reference - PyModule_AddObject(ptr(), name, obj.ptr()); + PyModule_AddObject(ptr(), name, obj.inc_ref().ptr() /* steals a reference */); } };