Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add case return_value_policy::_clif_automatic in type_caster_base.h #30087

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/pybind11/detail/type_caster_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ class type_caster_generic {
wrapper->owned = false;
break;

case return_value_policy::_clif_automatic:
case return_value_policy::copy:
if (copy_constructor) {
valueptr = copy_constructor(src);
Expand Down
9 changes: 9 additions & 0 deletions tests/test_copy_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ TEST_SUBMODULE(copy_move_policies, m) {

// Make sure that cast from pytype rvalue to other pytype works
m.def("get_pytype_rvalue_castissue", [](double i) { return py::float_(i).cast<py::int_>(); });

// Mimic situation generated by PyCLIF-pybind11.
// Requires `case return_value_policy::_clif_automatic` in `type_caster_base`.
struct PyCastUsingClifAutomaticTestType {};
py::class_<PyCastUsingClifAutomaticTestType>(m, "PyCastUsingClifAutomaticTestType");
m.def("py_cast_using_clif_automatic", []() {
PyCastUsingClifAutomaticTestType cpp_obj;
return py::cast(cpp_obj, py::return_value_policy::_clif_automatic);
});
}

/*
Expand Down
5 changes: 5 additions & 0 deletions tests/test_copy_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,8 @@ def test_pytype_rvalue_cast():

value = m.get_pytype_rvalue_castissue(1.0)
assert value == 1


def test_py_cast_using_clif_automatic():
obj = m.py_cast_using_clif_automatic()
assert obj.__class__.__name__ == "PyCastUsingClifAutomaticTestType"