From 661dfd87252aa904a0cb1edb970f23076fd02523 Mon Sep 17 00:00:00 2001 From: cyy Date: Mon, 30 Sep 2024 13:28:37 +0800 Subject: [PATCH 1/4] Export libc++ exceptions --- include/pybind11/detail/common.h | 18 ++++++++++-------- tests/test_exceptions.py | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index fa47199221..ee66719e42 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -164,14 +164,6 @@ # endif #endif -#if !defined(PYBIND11_EXPORT_EXCEPTION) -# if defined(__apple_build_version__) -# define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT -# else -# define PYBIND11_EXPORT_EXCEPTION -# endif -#endif - // For CUDA, GCC7, GCC8: // PYBIND11_NOINLINE_FORCED is incompatible with `-Wattributes -Werror`. // When defining PYBIND11_NOINLINE_FORCED, it is best to also use `-Wno-attributes`. @@ -329,6 +321,16 @@ PYBIND11_WARNING_POP # endif #endif +// For libc++, the exceptions should be exported, +// otherwise, the exception translation would be incorrect. +#if !defined(PYBIND11_EXPORT_EXCEPTION) +# if defined(__apple_build_version__) || defined(_LIBCPP_EXCEPTION) +# define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT +# else +# define PYBIND11_EXPORT_EXCEPTION +# endif +#endif + // Must be after including or one of the other headers specified by the standard #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L # define PYBIND11_HAS_U8STRING diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 21449d58ce..b611c3d3e4 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -76,7 +76,7 @@ def test_cross_module_exceptions(msg): # TODO: FIXME @pytest.mark.xfail( - "env.MACOS and (env.PYPY or pybind11_tests.compiler_info.startswith('Homebrew Clang')) or sys.platform.startswith('emscripten')", + "(env.MACOS and env.PYPY) or sys.platform.startswith('emscripten')", raises=RuntimeError, reason="See Issue #2847, PR #2999, PR #4324", ) From b3c2fb58c467305297c8d7641b926382d2876637 Mon Sep 17 00:00:00 2001 From: cyy Date: Thu, 10 Oct 2024 14:00:02 +0800 Subject: [PATCH 2/4] Remove emscripten limit --- tests/test_exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index b611c3d3e4..47214a7029 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -76,7 +76,7 @@ def test_cross_module_exceptions(msg): # TODO: FIXME @pytest.mark.xfail( - "(env.MACOS and env.PYPY) or sys.platform.startswith('emscripten')", + "env.MACOS and env.PYPY", raises=RuntimeError, reason="See Issue #2847, PR #2999, PR #4324", ) From f1133fe33f11520990da3894de4a0548c718c141 Mon Sep 17 00:00:00 2001 From: cyy Date: Fri, 11 Oct 2024 00:04:01 +0800 Subject: [PATCH 3/4] Remove __apple_build_version__ condition from PYBIND11_EXPORT_EXCEPTION --- include/pybind11/detail/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index ee66719e42..bcd37dced8 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -324,7 +324,7 @@ PYBIND11_WARNING_POP // For libc++, the exceptions should be exported, // otherwise, the exception translation would be incorrect. #if !defined(PYBIND11_EXPORT_EXCEPTION) -# if defined(__apple_build_version__) || defined(_LIBCPP_EXCEPTION) +# if defined(_LIBCPP_EXCEPTION) # define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT # else # define PYBIND11_EXPORT_EXCEPTION From 101a786ad29dee0f7b6792435d3c23bccf3f8191 Mon Sep 17 00:00:00 2001 From: cyy Date: Fri, 11 Oct 2024 00:05:04 +0800 Subject: [PATCH 4/4] Add a comment --- include/pybind11/detail/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index bcd37dced8..c974d89959 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -323,6 +323,7 @@ PYBIND11_WARNING_POP // For libc++, the exceptions should be exported, // otherwise, the exception translation would be incorrect. +// IMPORTANT: This code block must stay BELOW the #include above (see PR #5390). #if !defined(PYBIND11_EXPORT_EXCEPTION) # if defined(_LIBCPP_EXCEPTION) # define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT