-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[master] Debugging test_cross_module_exception_translator issue #4054
Conversation
e7abc0d
to
6b6b3eb
Compare
…py, so that it is imported by pytest before test_exceptions.py
The one failing job is a notorious flake (test_iostream). Everything else passes after renaming test_namespace_visibility.py to test_exc_namespace_visibility.py, so that it is imported by pytest before test_exceptions.py. This smells like a bug in |
* Add test_namespace_visibility To probe environment/toolchain/platform-specific behavior under the exact same conditions as normal tests. (An earlier version of this code was used to inform PR #4043.) * Disable flake8 in ubench/holder_comparison_*.py, to suppress new & useless diagnostics. * Disable namespace_visibility_1s.cpp (tosee if that resolves the MSVC and CUDA `test_cross_module_exception_translator` failures). * Turn off flake8 completely for ubench (the Strip unnecessary `# noqa`s action un-helpfully removed the added noqa). * Disable test_namespace_visibility completely. Just keep the two .cpp files, only setting the module docstring and doing nothing else. * Rename test_namespace_visibility.py to test_exc_namespace_visibility.py, so that it is imported by pytest before test_exceptions.py * Add `set_property(SOURCE namespace_visibility_1s.cpp PROPERTY LANGUAGE CUDA)` * Add reference to PR #4054 * Complete the documentation (comments in test_exc_namespace_visibility.py). * Rename namespace_visibility.h to namespace_visibility.inl, as suggested by @charlesbeattie
JIC this is useful for debugging later, the jobs that failed with https://github.com/pybind/pybind11/actions/runs/2638676503 (logs_21304.zip) were:
|
Another data point that may or may not be useful when debugging the import order issue: Under PR #4069, with diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h
index aea1987b..39531114 100644
--- a/include/pybind11/detail/common.h
+++ b/include/pybind11/detail/common.h
@@ -25,8 +25,10 @@
// on the main `pybind11` namespace.
#if !defined(PYBIND11_NAMESPACE)
# ifdef __GNUG__
-# define PYBIND11_NAMESPACE pybind11 __attribute__((visibility("hidden")))
+# define PYBIND11_NS_VISIBILITY(...) __VA_ARGS__ __attribute__((visibility("hidden")))
+# define PYBIND11_NAMESPACE PYBIND11_NS_VISIBILITY(pybind11)
# else
+# define PYBIND11_NS_VISIBILITY(...) __VA_ARGS__
# define PYBIND11_NAMESPACE pybind11
# endif
#endif
diff --git a/tests/test_exceptions.cpp b/tests/test_exceptions.cpp
index 3ec999d1..25f48f78 100644
--- a/tests/test_exceptions.cpp
+++ b/tests/test_exceptions.cpp
@@ -15,6 +15,8 @@
#include <stdexcept>
#include <utility>
+PYBIND11_NAMESPACE_BEGIN(PYBIND11_NS_VISIBILITY(pybind11_tests))
+
// A type that should be raised as an exception in Python
class MyException : public std::exception {
public:
@@ -110,7 +112,11 @@ std::string error_already_set_what(const py::object &exc_type, const py::object
return py::error_already_set().what();
}
+PYBIND11_NAMESPACE_END(pybind11_tests)
+
TEST_SUBMODULE(exceptions, m) {
+ using namespace pybind11_tests;
+
m.def("throw_std_exception",
[]() { throw std::runtime_error("This exception was intentionally thrown."); });
diff --git a/tests/test_exceptions.h b/tests/test_exceptions.h
index 03684b89..adad7c6c 100644
--- a/tests/test_exceptions.h
+++ b/tests/test_exceptions.h
@@ -5,9 +5,13 @@
// shared exceptions for cross_module_tests
+PYBIND11_NAMESPACE_BEGIN(PYBIND11_NS_VISIBILITY(pybind11_tests))
+
class PYBIND11_EXPORT_EXCEPTION shared_exception : public pybind11::builtin_exception {
public:
using builtin_exception::builtin_exception;
explicit shared_exception() : shared_exception("") {}
void set_error() const override { PyErr_SetString(PyExc_RuntimeError, what()); }
};
+
+PYBIND11_NAMESPACE_END(pybind11_tests) |
…e_visibility.py" This reverts commit c5ad26c. Observation summarized here: pybind#4054 (comment) > ... the list of jobs that fail is still exactly like (... before)
Re-testing with smart_holder @ commit 6df8693 (which includes #4098): https://github.com/rwgk/pybind11/tree/sh_rename_test_exc_namespace_visibility The
|
… work around the same issue as described under PR pybind#4054.
Description
This PR was used to debug this failure (as encountered originally under PR #4050).
https://github.com/pybind/pybind11/runs/7245374556?check_suite_focus=true
After a lot of trial-and-error, it turns out that renaming test_namespace_visibility.py to test_exc_namespace_visibility.py, so that it is imported by pytest before test_exceptions.py, "fixes" the failure.
This smells like a bug in
register_exception_translator
, and a really evil one if it is true. But I'll run with the workaround for now and will leave further debugging for another day.The idea for the workaround was based on the observation that test_class_sh_module_local.py has been working without a problem for many months, and the guess (still unproven) that the exception translator registry is somehow being reset when a new
PYBIND11_MODULE
is imported.Suggested changelog entry: