Skip to content

Commit 2e35470

Browse files
colesburyhenryiii
andauthored
fix: use manual padding of instance_map_shard (#5200)
* 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. * Add 'see #5200' * Update include/pybind11/detail/internals.h * Update include/pybind11/detail/internals.h --------- Co-authored-by: Henry Schreiner <[email protected]>
1 parent 895e657 commit 2e35470

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

include/pybind11/detail/internals.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,14 @@ struct override_hash {
148148

149149
using instance_map = std::unordered_multimap<const void *, instance *>;
150150

151-
// ignore: structure was padded due to alignment specifier
152-
PYBIND11_WARNING_PUSH
153-
PYBIND11_WARNING_DISABLE_MSVC(4324)
154-
155151
// Instance map shards are used to reduce mutex contention in free-threaded Python.
156-
struct alignas(64) instance_map_shard {
152+
struct instance_map_shard {
157153
std::mutex mutex;
158154
instance_map registered_instances;
155+
// alignas(64) would be better, but causes compile errors in macOS before 10.14 (see #5200)
156+
char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64];
159157
};
160158

161-
PYBIND11_WARNING_POP
162-
163159
/// Internal data structure used to track registered instances and types.
164160
/// Whenever binary incompatible changes are made to this structure,
165161
/// `PYBIND11_INTERNALS_VERSION` must be incremented.

0 commit comments

Comments
 (0)