mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-12 09:17:42 +00:00
[smart_holder] Keep parent alive when returning raw pointers (#4609)
* Avoid dangling pointers. * Add test for const ptr * Fix test failures. * Fix ClangTidy * fix emplace_back
This commit is contained in:
@@ -715,7 +715,11 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
|
||||
|
||||
static handle cast(T *src, return_value_policy policy, handle parent) {
|
||||
if (policy == return_value_policy::_clif_automatic) {
|
||||
policy = return_value_policy::reference;
|
||||
if (parent) {
|
||||
policy = return_value_policy::reference_internal;
|
||||
} else {
|
||||
policy = return_value_policy::reference;
|
||||
}
|
||||
}
|
||||
return cast(const_cast<T const *>(src), policy, parent); // Mutbl2Const
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user