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

Internal Temporary Change #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions pybind11_abseil/status_caster.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ struct type_caster<absl::Status> : public type_caster_base<absl::Status> {
}
};

#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK) && \
defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS)
#if defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS)

// This code requires https://github.com/google/pybind11k
// IMPORTANT:
// KEEP
// type_caster<absl::Status>
Expand All @@ -141,7 +139,11 @@ struct func_wrapper<absl::Status, Args...> : func_wrapper_base {
gil_scoped_acquire acq;
try {
object py_result =
#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK)
hfunc.f.call_with_policies(rvpp, std::forward<Args>(args)...);
#else
hfunc.f(std::forward<Args>(args)...);
#endif
try {
return py_result.template cast<absl::Status>();
} catch (cast_error& e) {
Expand Down
7 changes: 5 additions & 2 deletions pybind11_abseil/statusor_caster.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ struct type_caster<absl::StatusOr<PayloadType>> {
}
};

#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK)
#if defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS)

// This code requires https://github.com/google/pybind11k
// IMPORTANT:
// KEEP
// type_caster<absl::StatusOr<PayloadType>>
Expand All @@ -144,7 +143,11 @@ struct func_wrapper<absl::StatusOr<PayloadType>, Args...> : func_wrapper_base {
gil_scoped_acquire acq;
try {
object py_result =
#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK)
hfunc.f.call_with_policies(rvpp, std::forward<Args>(args)...);
#else
hfunc.f(std::forward<Args>(args)...);
#endif
try {
auto cpp_result =
py_result.template cast<absl::StatusOr<PayloadType>>();
Expand Down
11 changes: 2 additions & 9 deletions pybind11_abseil/tests/status_testing_no_cpp_eh_pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ namespace status_testing_no_cpp_eh {
PYBIND11_MODULE(status_testing_no_cpp_eh_pybind, m) {
pybind11::google::ImportStatusModule();

m.attr("defined_PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS") =
#if defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS)
true;
#else
false;
#endif

m.def("CallCallbackWithStatusReturn", &CallCallbackWithStatusReturn);
m.def("CallCallbackWithStatusOrIntReturn",
&CallCallbackWithStatusOrIntReturn);
Expand All @@ -31,8 +24,8 @@ PYBIND11_MODULE(status_testing_no_cpp_eh_pybind, m) {
pybind11::return_value_policy::take_ownership);
m.def("GenerateErrorStatusNotOk", &GenerateErrorStatusNotOk);

m.attr("defined_PYBIND11_HAS_RETURN_VALUE_POLICY_PACK") =
#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK)
m.attr("defined_PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS") =
#if defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS)
true;
#else
false;
Expand Down
2 changes: 1 addition & 1 deletion pybind11_abseil/tests/status_testing_no_cpp_eh_test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def cb(arg):

if (
hasattr(self.tm, '__pyclif_codegen_mode__')
or self.tm.defined_PYBIND11_HAS_RETURN_VALUE_POLICY_PACK
or self.tm.defined_PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS
):
res = cc_fn(cb, 'exc')
self.assertEqual(res, "!obj.ok()@ValueError: Unknown arg: 'exc'")
Expand Down
Loading