Skip to content

Commit 6d3a0fc

Browse files
authored
Add return value policy _clif_automatic (#4343)
1 parent fcdb9ba commit 6d3a0fc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

include/pybind11/detail/common.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,16 @@ enum class return_value_policy : uint8_t {
478478
but the purpose of _return_as_bytes is certain to be orthogonal, because
479479
C++ strings are always copied to Python `bytes` or `str`.
480480
NOTE: This policy is NOT available on master. */
481-
_return_as_bytes
481+
_return_as_bytes,
482+
483+
/** This policy should only be used by PyCLIF to automatically select a
484+
return value policy. Legacy PyCLIF automatically decides object lifetime
485+
management based on their properties:
486+
https://github.com/google/clif/tree/main/clif/python#pointers-references-and-object-ownership
487+
With this policy, the return value policy selection is consistent with
488+
legacy PyCLIF.
489+
NOTE: This policy is NOT available on master. */
490+
_clif_automatic
482491
};
483492

484493
PYBIND11_NAMESPACE_BEGIN(detail)

include/pybind11/detail/smart_holder_type_casters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
795795
break;
796796
case return_value_policy::reference_internal:
797797
case return_value_policy::_return_as_bytes:
798+
case return_value_policy::_clif_automatic:
798799
break;
799800
}
800801
if (!src) {

0 commit comments

Comments
 (0)