From 3752a80cdb89f57e6f1430c525b081650a1c6864 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 26 Jun 2024 17:49:50 +0000 Subject: [PATCH 1/4] 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. From 94f8b9e2d4bcdf8d9f105036c879c3290f7b9429 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 26 Jun 2024 18:19:20 +0000 Subject: [PATCH 2/4] Add 'see #5200' --- include/pybind11/detail/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index a7514af19b..e61c1687fc 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -152,7 +152,7 @@ using instance_map = std::unordered_multimap; 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 + // alignas(64) would be better, but causes compile errors in macOS before 10.14 (see #5200) char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64]; }; From 9c37d68a8010931787bbafdec5bf2734c06e439c Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 26 Jun 2024 14:53:41 -0400 Subject: [PATCH 3/4] Update include/pybind11/detail/internals.h --- include/pybind11/detail/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index e61c1687fc..3754ac05d6 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -153,7 +153,7 @@ 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 (see #5200) - char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64]; + PYBIND11_MAYBE_UNUSED char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64]; }; /// Internal data structure used to track registered instances and types. From 1c6fc5448314ebb1519054f6e8da8299d65c0ca1 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 26 Jun 2024 15:12:58 -0400 Subject: [PATCH 4/4] Update include/pybind11/detail/internals.h --- include/pybind11/detail/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 3754ac05d6..e61c1687fc 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -153,7 +153,7 @@ 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 (see #5200) - PYBIND11_MAYBE_UNUSED char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64]; + char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64]; }; /// Internal data structure used to track registered instances and types.