From b032b4107103a0d9cbea5b50a9b925780fdedb8c Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 5 Aug 2024 22:37:57 -0700 Subject: [PATCH] Internal Temporary Change PiperOrigin-RevId: 659808209 --- pybind11_abseil/status_caster.h | 8 +++++--- pybind11_abseil/statusor_caster.h | 7 +++++-- .../tests/status_testing_no_cpp_eh_pybind.cc | 11 ++--------- .../tests/status_testing_no_cpp_eh_test_lib.py | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/pybind11_abseil/status_caster.h b/pybind11_abseil/status_caster.h index aeec92b..00655b1 100644 --- a/pybind11_abseil/status_caster.h +++ b/pybind11_abseil/status_caster.h @@ -120,10 +120,8 @@ struct type_caster : public type_caster_base { } }; -#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 @@ -141,7 +139,11 @@ struct func_wrapper : 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)...); +#else + hfunc.f(std::forward(args)...); +#endif try { return py_result.template cast(); } catch (cast_error& e) { diff --git a/pybind11_abseil/statusor_caster.h b/pybind11_abseil/statusor_caster.h index de763ae..2dc97ba 100644 --- a/pybind11_abseil/statusor_caster.h +++ b/pybind11_abseil/statusor_caster.h @@ -124,9 +124,8 @@ struct type_caster> { } }; -#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> @@ -144,7 +143,11 @@ struct func_wrapper, 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)...); +#else + hfunc.f(std::forward(args)...); +#endif try { auto cpp_result = py_result.template cast>(); diff --git a/pybind11_abseil/tests/status_testing_no_cpp_eh_pybind.cc b/pybind11_abseil/tests/status_testing_no_cpp_eh_pybind.cc index d6cec35..b441962 100644 --- a/pybind11_abseil/tests/status_testing_no_cpp_eh_pybind.cc +++ b/pybind11_abseil/tests/status_testing_no_cpp_eh_pybind.cc @@ -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); @@ -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; diff --git a/pybind11_abseil/tests/status_testing_no_cpp_eh_test_lib.py b/pybind11_abseil/tests/status_testing_no_cpp_eh_test_lib.py index 41b8254..af460f7 100644 --- a/pybind11_abseil/tests/status_testing_no_cpp_eh_test_lib.py +++ b/pybind11_abseil/tests/status_testing_no_cpp_eh_test_lib.py @@ -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'")