mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
only use over-aligned new/delete if needed
This commit is contained in:
parent
5c11b1c871
commit
1423623205
@ -3,6 +3,7 @@ image:
|
|||||||
- Visual Studio 2017
|
- Visual Studio 2017
|
||||||
- Visual Studio 2015
|
- Visual Studio 2015
|
||||||
test: off
|
test: off
|
||||||
|
skip_branch_with_pr: true
|
||||||
build:
|
build:
|
||||||
parallel: true
|
parallel: true
|
||||||
platform:
|
platform:
|
||||||
|
@ -574,12 +574,13 @@ public:
|
|||||||
if (type->operator_new) {
|
if (type->operator_new) {
|
||||||
vptr = type->operator_new(type->type_size);
|
vptr = type->operator_new(type->type_size);
|
||||||
} else {
|
} else {
|
||||||
#if !defined(PYBIND11_CPP17)
|
#if defined(PYBIND11_CPP17)
|
||||||
vptr = ::operator new(type->type_size);
|
if (type->type_align > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
|
||||||
#else
|
vptr = ::operator new(type->type_size,
|
||||||
vptr = ::operator new(type->type_size,
|
(std::align_val_t) type->type_align);
|
||||||
(std::align_val_t) type->type_align);
|
else
|
||||||
#endif
|
#endif
|
||||||
|
vptr = ::operator new(type->type_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = vptr;
|
value = vptr;
|
||||||
|
@ -988,11 +988,21 @@ template <typename T> struct has_operator_delete_size<T, void_t<decltype(static_
|
|||||||
: std::true_type { };
|
: std::true_type { };
|
||||||
/// Call class-specific delete if it exists or global otherwise. Can also be an overload set.
|
/// Call class-specific delete if it exists or global otherwise. Can also be an overload set.
|
||||||
template <typename T, enable_if_t<has_operator_delete<T>::value, int> = 0>
|
template <typename T, enable_if_t<has_operator_delete<T>::value, int> = 0>
|
||||||
void call_operator_delete(T *p, size_t) { T::operator delete(p); }
|
void call_operator_delete(T *p, size_t, size_t) { T::operator delete(p); }
|
||||||
template <typename T, enable_if_t<!has_operator_delete<T>::value && has_operator_delete_size<T>::value, int> = 0>
|
template <typename T, enable_if_t<!has_operator_delete<T>::value && has_operator_delete_size<T>::value, int> = 0>
|
||||||
void call_operator_delete(T *p, size_t s) { T::operator delete(p, s); }
|
void call_operator_delete(T *p, size_t s, size_t) { T::operator delete(p, s); }
|
||||||
|
|
||||||
inline void call_operator_delete(void *p, size_t) { ::operator delete(p); }
|
inline void call_operator_delete(void *p, size_t s, size_t a) {
|
||||||
|
(void)s; (void)a;
|
||||||
|
#if defined(PYBIND11_CPP17)
|
||||||
|
if (a > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
|
||||||
|
::operator delete(p, s, std::align_val_t(a));
|
||||||
|
else
|
||||||
|
::operator delete(p, s);
|
||||||
|
#else
|
||||||
|
::operator delete(p);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
NAMESPACE_END(detail)
|
NAMESPACE_END(detail)
|
||||||
|
|
||||||
@ -1331,7 +1341,10 @@ private:
|
|||||||
v_h.set_holder_constructed(false);
|
v_h.set_holder_constructed(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
detail::call_operator_delete(v_h.value_ptr<type>(), v_h.type->type_size);
|
detail::call_operator_delete(v_h.value_ptr<type>(),
|
||||||
|
v_h.type->type_size,
|
||||||
|
v_h.type->type_align
|
||||||
|
);
|
||||||
}
|
}
|
||||||
v_h.value_ptr() = nullptr;
|
v_h.value_ptr() = nullptr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user