mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-12 01:10:34 +00:00
Throw an exception when attempting to load an incompatible holder
Instead of a segfault. Fixes #751. This covers the case of loading a custom holder from a default-holder instance. Attempting to load one custom holder from a different custom holder (i.e. not `std::unique_ptr`) yields undefined behavior, just as #588 established for inheritance.
This commit is contained in:
@@ -919,6 +919,9 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
if (typeinfo->default_holder)
|
||||
throw cast_error("Unable to load a custom holder type from a default-holder instance");
|
||||
|
||||
if (typeinfo->simple_type) { /* Case 1: no multiple inheritance etc. involved */
|
||||
/* Check if we can safely perform a reinterpret-style cast */
|
||||
if (PyType_IsSubtype(tobj, typeinfo->type))
|
||||
|
||||
Reference in New Issue
Block a user