diff --git a/pybind11_abseil/status_caster.h b/pybind11_abseil/status_caster.h index e5baf2d..aeec92b 100644 --- a/pybind11_abseil/status_caster.h +++ b/pybind11_abseil/status_caster.h @@ -120,7 +120,8 @@ struct type_caster : public type_caster_base { } }; -#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK) +#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK) && \ + defined(PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS) // This code requires https://github.com/google/pybind11k // IMPORTANT: diff --git a/pybind11_abseil/tests/BUILD b/pybind11_abseil/tests/BUILD index 02d32d4..affc5c9 100644 --- a/pybind11_abseil/tests/BUILD +++ b/pybind11_abseil/tests/BUILD @@ -54,6 +54,15 @@ py_library( deps = [requirement("absl_py")], ) +py_test( + name = "status_testing_no_cpp_eh_test", + srcs = ["status_testing_no_cpp_eh_test.py"], + data = [":status_testing_no_cpp_eh_pybind.so"], + python_version = "PY3", + srcs_version = "PY3", + deps = [":status_testing_no_cpp_eh_test_lib"], +) + pybind_extension( name = "absl_example", srcs = ["absl_example.cc"], diff --git a/pybind11_abseil/tests/CMakeLists.txt b/pybind11_abseil/tests/CMakeLists.txt index a423c30..1204321 100644 --- a/pybind11_abseil/tests/CMakeLists.txt +++ b/pybind11_abseil/tests/CMakeLists.txt @@ -95,3 +95,5 @@ add_test( ${CMAKE_COMMAND} -E env PYTHONPATH=$PYTHONPATH:${CMAKE_BINARY_DIR} ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/status_example_test.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + +# OMITTED (help appreciated): status_testing_no_cpp_eh_test 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 27be2cf..d6cec35 100644 --- a/pybind11_abseil/tests/status_testing_no_cpp_eh_pybind.cc +++ b/pybind11_abseil/tests/status_testing_no_cpp_eh_pybind.cc @@ -16,6 +16,13 @@ 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); @@ -24,7 +31,7 @@ PYBIND11_MODULE(status_testing_no_cpp_eh_pybind, m) { pybind11::return_value_policy::take_ownership); m.def("GenerateErrorStatusNotOk", &GenerateErrorStatusNotOk); - m.attr("PYBIND11_HAS_RETURN_VALUE_POLICY_PACK") = + m.attr("defined_PYBIND11_HAS_RETURN_VALUE_POLICY_PACK") = #if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK) true; #else diff --git a/pybind11_abseil/tests/status_testing_no_cpp_eh_test.py b/pybind11_abseil/tests/status_testing_no_cpp_eh_test.py index fd78a5c..ed875bf 100644 --- a/pybind11_abseil/tests/status_testing_no_cpp_eh_test.py +++ b/pybind11_abseil/tests/status_testing_no_cpp_eh_test.py @@ -3,6 +3,13 @@ from pybind11_abseil.tests import status_testing_no_cpp_eh_pybind from pybind11_abseil.tests import status_testing_no_cpp_eh_test_lib as test_lib +_HAS_FUN_SPEC = ( + status_testing_no_cpp_eh_pybind.defined_PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS +) +_FUN_SPEC_NDEF = ( + 'PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS is not defined.' +) + class _TestModuleMixin: @@ -10,14 +17,17 @@ def getTestModule(self): # pylint: disable=invalid-name return status_testing_no_cpp_eh_pybind +@absltest.skipIf(not _HAS_FUN_SPEC, _FUN_SPEC_NDEF) class StatusReturnTest(test_lib.StatusReturnTest, _TestModuleMixin): pass +@absltest.skipIf(not _HAS_FUN_SPEC, _FUN_SPEC_NDEF) class StatusOrReturnTest(test_lib.StatusOrReturnTest, _TestModuleMixin): pass +@absltest.skipIf(not _HAS_FUN_SPEC, _FUN_SPEC_NDEF) class StatusOrPyObjectPtrTest( test_lib.StatusOrPyObjectPtrTest, _TestModuleMixin ): 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 5f9e7cd..41b8254 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.PYBIND11_HAS_RETURN_VALUE_POLICY_PACK + or self.tm.defined_PYBIND11_HAS_RETURN_VALUE_POLICY_PACK ): res = cc_fn(cb, 'exc') self.assertEqual(res, "!obj.ok()@ValueError: Unknown arg: 'exc'")