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.
This commit is contained in:
Ralf W. Grosse-Kunstleve
2025-12-19 21:56:14 -08:00
parent ac02a3208d
commit ddb6dd4c73

View File

@@ -11,13 +11,17 @@
#if defined(Py_GIL_DISABLED) || defined(PYBIND11_HAS_SUBINTERPRETER_SUPPORT)
# include <atomic>
#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