Skip to content

Commit 9d4f1d7

Browse files
committed
Use return_value_policy::reference for virtual method calls only
1 parent 5583036 commit 9d4f1d7

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

include/pybind11/pybind11.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2243,7 +2243,7 @@ template <class T> function get_override(const T *this_ptr, const char *name) {
22432243
pybind11::gil_scoped_acquire gil; \
22442244
pybind11::function override = pybind11::get_override(static_cast<const cname *>(this), name); \
22452245
if (override) { \
2246-
auto o = override(__VA_ARGS__); \
2246+
auto o = override.operator()<py::return_value_policy::reference>(__VA_ARGS__); \
22472247
if (pybind11::detail::cast_is_temporary_value_reference<ret_type>::value) { \
22482248
static pybind11::detail::override_caster_t<ret_type> caster; \
22492249
return pybind11::detail::cast_ref<ret_type>(std::move(o), caster); \

include/pybind11/pytypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ class object_api : public pyobject_tag {
105105
function will throw a `cast_error` exception. When the Python function
106106
call fails, a `error_already_set` exception is thrown.
107107
\endrst */
108-
template <return_value_policy policy = return_value_policy::reference, typename... Args>
108+
template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args>
109109
object operator()(Args &&...args) const;
110-
template <return_value_policy policy = return_value_policy::reference, typename... Args>
110+
template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args>
111111
PYBIND11_DEPRECATED("call(...) was deprecated in favor of operator()(...)")
112112
object call(Args&&... args) const;
113113

0 commit comments

Comments
 (0)