Skip to content

Commit e64ae68

Browse files
rwgkcopybara-github
authored andcommitted
Enable type_caster_std_function_specializations with or without return_value_policy_pack feature.
This is for pybind/pybind11#5289 applied to smart_holder. PiperOrigin-RevId: 659808208
1 parent 8ccb4c7 commit e64ae68

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

pybind11_abseil/status_caster.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,8 @@ struct type_caster<absl::Status> : public type_caster_base<absl::Status> {
120120
}
121121
};
122122

123-
#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK) && \
124-
defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS)
123+
#if defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS)
125124

126-
// This code requires https://github.com/google/pybind11k
127125
// IMPORTANT:
128126
// KEEP
129127
// type_caster<absl::Status>
@@ -141,7 +139,11 @@ struct func_wrapper<absl::Status, Args...> : func_wrapper_base {
141139
gil_scoped_acquire acq;
142140
try {
143141
object py_result =
142+
#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK)
144143
hfunc.f.call_with_policies(rvpp, std::forward<Args>(args)...);
144+
#else
145+
hfunc.f(std::forward<Args>(args)...);
146+
#endif
145147
try {
146148
return py_result.template cast<absl::Status>();
147149
} catch (cast_error& e) {

pybind11_abseil/statusor_caster.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ struct type_caster<absl::StatusOr<PayloadType>> {
124124
}
125125
};
126126

127-
#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK)
127+
#if defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS)
128128

129-
// This code requires https://github.com/google/pybind11k
130129
// IMPORTANT:
131130
// KEEP
132131
// type_caster<absl::StatusOr<PayloadType>>
@@ -144,7 +143,11 @@ struct func_wrapper<absl::StatusOr<PayloadType>, Args...> : func_wrapper_base {
144143
gil_scoped_acquire acq;
145144
try {
146145
object py_result =
146+
#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK)
147147
hfunc.f.call_with_policies(rvpp, std::forward<Args>(args)...);
148+
#else
149+
hfunc.f(std::forward<Args>(args)...);
150+
#endif
148151
try {
149152
auto cpp_result =
150153
py_result.template cast<absl::StatusOr<PayloadType>>();

pybind11_abseil/tests/status_testing_no_cpp_eh_pybind.cc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ namespace status_testing_no_cpp_eh {
1616
PYBIND11_MODULE(status_testing_no_cpp_eh_pybind, m) {
1717
pybind11::google::ImportStatusModule();
1818

19-
m.attr("defined_PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS") =
20-
#if defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS)
21-
true;
22-
#else
23-
false;
24-
#endif
25-
2619
m.def("CallCallbackWithStatusReturn", &CallCallbackWithStatusReturn);
2720
m.def("CallCallbackWithStatusOrIntReturn",
2821
&CallCallbackWithStatusOrIntReturn);
@@ -31,8 +24,8 @@ PYBIND11_MODULE(status_testing_no_cpp_eh_pybind, m) {
3124
pybind11::return_value_policy::take_ownership);
3225
m.def("GenerateErrorStatusNotOk", &GenerateErrorStatusNotOk);
3326

34-
m.attr("defined_PYBIND11_HAS_RETURN_VALUE_POLICY_PACK") =
35-
#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK)
27+
m.attr("defined_PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS") =
28+
#if defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS)
3629
true;
3730
#else
3831
false;

pybind11_abseil/tests/status_testing_no_cpp_eh_test_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def cb(arg):
185185

186186
if (
187187
hasattr(self.tm, '__pyclif_codegen_mode__')
188-
or self.tm.defined_PYBIND11_HAS_RETURN_VALUE_POLICY_PACK
188+
or self.tm.defined_PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS
189189
):
190190
res = cc_fn(cb, 'exc')
191191
self.assertEqual(res, "!obj.ok()@ValueError: Unknown arg: 'exc'")

0 commit comments

Comments
 (0)