Two minor platform-specific fixes. Using static_cast instead of reinterpret_cast.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-06-19 23:52:17 -07:00 committed by Ralf W. Grosse-Kunstleve
parent 993613d9bf
commit 223283295f
2 changed files with 5 additions and 5 deletions

View File

@ -92,12 +92,12 @@ to_cout("LOOOK guarded_delete ctor " + std::to_string(__LINE__) + " " + __FILE__
template <typename T> template <typename T>
inline void shd_ptr_reset(std::shared_ptr<void>& shd_ptr, void *raw_ptr, guarded_delete &&gdel) { inline void shd_ptr_reset(std::shared_ptr<void>& shd_ptr, void *raw_ptr, guarded_delete &&gdel) {
shd_ptr.reset(reinterpret_cast<T *>(raw_ptr), gdel); shd_ptr.reset(static_cast<T *>(raw_ptr), gdel);
} }
template <typename T, typename std::enable_if<std::is_destructible<T>::value, int>::type = 0> template <typename T, typename std::enable_if<std::is_destructible<T>::value, int>::type = 0>
inline void builtin_delete_if_destructible(void *raw_ptr) { inline void builtin_delete_if_destructible(void *raw_ptr) {
delete reinterpret_cast<T *>(raw_ptr); delete static_cast<T *>(raw_ptr);
} }
template <typename T, typename std::enable_if<!std::is_destructible<T>::value, int>::type = 0> template <typename T, typename std::enable_if<!std::is_destructible<T>::value, int>::type = 0>
@ -115,7 +115,7 @@ guarded_delete make_guarded_builtin_delete(bool armed_flag) {
template <typename T, typename D> template <typename T, typename D>
inline void custom_delete(void *raw_ptr) { inline void custom_delete(void *raw_ptr) {
D()(reinterpret_cast<T *>(raw_ptr)); D()(static_cast<T *>(raw_ptr));
} }
template <typename T, typename D> template <typename T, typename D>
@ -245,7 +245,7 @@ to_cout("LOOOK smart_holder from_raw_ptr_unowned " + std::to_string(__LINE__) +
template <typename T> template <typename T>
T *as_raw_ptr_unowned() const { T *as_raw_ptr_unowned() const {
to_cout("LOOOK smart_holder as_raw_ptr_unowned PTR" + std::to_string((unsigned long) vptr.get()) + " " + std::to_string(__LINE__) + " " + __FILE__); to_cout("LOOOK smart_holder as_raw_ptr_unowned " + std::to_string(__LINE__) + " " + __FILE__);
return static_cast<T *>(vptr.get()); return static_cast<T *>(vptr.get());
} }

View File

@ -112,7 +112,7 @@ struct RescuingDeleter {
explicit RescuingDeleter(PyWrapper *pyw) : pyw{pyw} {} explicit RescuingDeleter(PyWrapper *pyw) : pyw{pyw} {}
void operator()(ToBeWrapped *raw_ptr) { void operator()(ToBeWrapped *raw_ptr) {
if (pyw->self.get() != nullptr) { if (pyw->self.get() != nullptr) {
#if !defined(_MSC_VER) || _MSC_VER >= 1912 #if defined(__cpp_lib_enable_shared_from_this) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
assert(raw_ptr->weak_from_this().expired()); // CRITICAL assert(raw_ptr->weak_from_this().expired()); // CRITICAL
#endif #endif
pyw->wobj = std::shared_ptr<ToBeWrapped>(raw_ptr, *this); pyw->wobj = std::shared_ptr<ToBeWrapped>(raw_ptr, *this);