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

This commit is contained in:
Wenzel Jakob 2015-10-01 18:37:26 +02:00
parent 6d6fd099db
commit ac0fde988a
3 changed files with 6 additions and 1 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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;
} }