mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-23 00:09:10 +00:00
stl.h: propagate return value policies to type-specific casters (#1455)
* stl.h: propagate return value policies to type-specific casters Return value policies for containers like those handled in in 'stl.h' are currently broken. The problem is that detail::return_value_policy_override<C>::policy() always returns 'move' when given a non-pointer/reference type, e.g. 'std::vector<...>'. This is sensible behavior for custom types that are exposed via 'py::class_<>', but it does not make sense for types that are handled by other type casters (STL containers, Eigen matrices, etc.). This commit changes the behavior so that detail::return_value_policy_override only becomes active when the type caster derives from type_caster_generic. Furthermore, the override logic is called recursively in STL type casters to enable key/value-specific behavior.
This commit is contained in:
@@ -2,6 +2,7 @@ import pytest
|
||||
|
||||
from pybind11_tests import stl as m
|
||||
from pybind11_tests import UserType
|
||||
from pybind11_tests import ConstructorStats
|
||||
|
||||
|
||||
def test_vector(doc):
|
||||
@@ -198,3 +199,12 @@ def test_missing_header_message():
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
cm.missing_header_return()
|
||||
assert expected_message in str(excinfo.value)
|
||||
|
||||
|
||||
def test_stl_ownership():
|
||||
cstats = ConstructorStats.get(m.Placeholder)
|
||||
assert cstats.alive() == 0
|
||||
r = m.test_stl_ownership()
|
||||
assert len(r) == 1
|
||||
del r
|
||||
assert cstats.alive() == 0
|
||||
|
||||
Reference in New Issue
Block a user