// construct the new C++ object and install the pointer
// in the Python object.
- Derived::construct(&instance->storage, (PyObject*)instance, x)->install(raw_result);
+ Holder *holder =Derived::construct(instance->storage.bytes, (PyObject*)instance, x);
+ holder->install(raw_result);
// Note the position of the internally-stored Holder,
// for the sake of destruction
- Py_SIZE(instance) = offsetof(instance_t, storage);
+ const size_t offset = reinterpret_cast<size_t>(holder) -
+ reinterpret_cast<size_t>(instance->storage.bytes) + offsetof(instance_t, storage);
+ Py_SET_SIZE(instance, offset);
// Release ownership of the python object
protect.cancel();
static inline Holder* construct(void* storage, PyObject* instance, reference_wrapper<T const> x)
{
- return new (storage) Holder(instance, x);
+ size_t allocated = objects::additional_instance_size<Holder>::value;
+ void* aligned_storage = ::boost::alignment::align(boost::python::detail::alignment_of<Holder>::value,
+ sizeof(Holder), storage, allocated);
+ return new (aligned_storage) Holder(instance, x);
}
};