boostorg / python

Boost.org python module
http://boostorg.github.io/python
Boost Software License 1.0
468 stars 201 forks source link

Alignment fixes #392

Open dlaugt opened 2 years ago

dlaugt commented 2 years ago

Fixed a crash on Solaris 11 with gcc 7.3.1 when a binding uses make_constructor () like:

def_class<integer_type> ("numeric")
  .def("__init__", make_constructor (&integer::from_tuple),
       "Initialize from a tuple")

The crash is caused from pull request #360. It works fine when I revert the changes of this pull request.

In make_constructor.hpp, the address of the structure pointer_holder should be aligned with the correct alignment value instead of the default value 1. Otherwise, it crashes in the placement new operator:

(new (memory) holder(std::move(x)))

Fix the calculation of the padding required to align the start of a data structure. The padding cannot be equal to the alignment. It is always smaller than the alignment. The formula is taken from wikipedia which is equivalent to @aristk 's suggestion at #384: https://en.wikipedia.org/wiki/Data_structure_alignment