Commit ac0fde98 by Wenzel Jakob

don't throw an exception when python deallocates an object which still exists on the C++ side

parent 6d6fd099
...@@ -292,6 +292,9 @@ public: ...@@ -292,6 +292,9 @@ public:
PYBIND_TYPE_CASTER(void_type, "None"); PYBIND_TYPE_CASTER(void_type, "None");
}; };
template <> class type_caster<void> : public type_caster<void_type> {
};
template <> class type_caster<bool> { template <> class type_caster<bool> {
public: public:
bool load(PyObject *src, bool) { bool load(PyObject *src, bool) {
......
...@@ -883,6 +883,8 @@ public: ...@@ -883,6 +883,8 @@ public:
inline function get_overload(const void *this_ptr, const char *name) { inline function get_overload(const void *this_ptr, const char *name) {
handle py_object = detail::get_object_handle(this_ptr); handle py_object = detail::get_object_handle(this_ptr);
if (!py_object)
return function();
handle type = py_object.get_type(); handle type = py_object.get_type();
auto key = std::make_pair(type.ptr(), name); auto key = std::make_pair(type.ptr(), name);
......
...@@ -400,7 +400,7 @@ inline handle get_object_handle(const void *ptr) { ...@@ -400,7 +400,7 @@ inline handle get_object_handle(const void *ptr) {
auto instances = get_internals().registered_instances; auto instances = get_internals().registered_instances;
auto it = instances.find(ptr); auto it = instances.find(ptr);
if (it == instances.end()) if (it == instances.end())
throw std::runtime_error("Internal error: could not acquire Python handle of a C++ object"); return handle();
return it->second; return it->second;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment