From ddb6dd4c73cc84b82373ba6c2e851dbecd19ad62 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 19 Dec 2025 21:56:14 -0800 Subject: [PATCH] Move atomic_bool alias into pybind11::detail namespace The `using atomic_bool = ...` declaration was at global scope, polluting the global namespace. Move it into pybind11::detail to avoid potential conflicts with user code. --- include/pybind11/gil_safe_call_once.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/pybind11/gil_safe_call_once.h b/include/pybind11/gil_safe_call_once.h index 2268ca3ac..ffd147ad0 100644 --- a/include/pybind11/gil_safe_call_once.h +++ b/include/pybind11/gil_safe_call_once.h @@ -11,13 +11,17 @@ #if defined(Py_GIL_DISABLED) || defined(PYBIND11_HAS_SUBINTERPRETER_SUPPORT) # include +#endif +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) + +namespace detail { +#if defined(Py_GIL_DISABLED) || defined(PYBIND11_HAS_SUBINTERPRETER_SUPPORT) using atomic_bool = std::atomic_bool; #else using atomic_bool = bool; #endif - -PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +} // namespace detail // Use the `gil_safe_call_once_and_store` class below instead of the naive // @@ -108,7 +112,7 @@ private: // The `is_initialized_`-`storage_` pair is very similar to `std::optional`, // but the latter does not have the triviality properties of former, // therefore `std::optional` is not a viable alternative here. - atomic_bool is_initialized_{false}; + detail::atomic_bool is_initialized_{false}; }; #else // Subinterpreter support is enabled. @@ -265,7 +269,7 @@ private: T *last_storage_ptr_ = nullptr; // This flag is true if the value has been initialized by any interpreter (may not be the // current one). - atomic_bool is_initialized_by_atleast_one_interpreter_{false}; + detail::atomic_bool is_initialized_by_atleast_one_interpreter_{false}; }; #endif