Skip to content

Commit

Permalink
fix: use manual padding of instance_map_shard (#5200)
Browse files Browse the repository at this point in the history
* 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 <HenrySchreinerIII@gmail.com>
  • Loading branch information
colesbury and henryiii authored Jun 26, 2024
1 parent 895e657 commit 2e35470
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions include/pybind11/detail/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,14 @@ struct override_hash {

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

// 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 (see #5200)
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.
Expand Down

0 comments on commit 2e35470

Please sign in to comment.