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 <HenrySchreinerIII@gmail.com>
This commit is contained in:
Sam Gross 2024-06-26 15:46:46 -04:00 committed by GitHub
parent 895e657220
commit 2e35470cff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 7 deletions

View File

@ -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.