From 3752a80cdb89f57e6f1430c525b081650a1c6864 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 26 Jun 2024 17:49:50 +0000 Subject: [PATCH] Use manual padding of instance_map_shard. The alignas(64) specifier requires aligned allocation, which is not available on macOS when targeting versions before 10.14. --- include/pybind11/detail/internals.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 92a851602d..a7514af19b 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -148,18 +148,14 @@ struct override_hash { using instance_map = std::unordered_multimap; -// ignore: structure was padded due to alignment specifier -PYBIND11_WARNING_PUSH -PYBIND11_WARNING_DISABLE_MSVC(4324) - // Instance map shards are used to reduce mutex contention in free-threaded Python. -struct alignas(64) instance_map_shard { +struct instance_map_shard { std::mutex mutex; instance_map registered_instances; + // alignas(64) would be better, but causes compile errors in macOS before 10.14 + char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64]; }; -PYBIND11_WARNING_POP - /// Internal data structure used to track registered instances and types. /// Whenever binary incompatible changes are made to this structure, /// `PYBIND11_INTERNALS_VERSION` must be incremented.