From c9619e3e3d094b253df8f3cbd31a116418270728 Mon Sep 17 00:00:00 2001 From: Mindaugas Vinkelis Date: Mon, 5 Aug 2019 18:24:29 +0300 Subject: [PATCH] macOS compilation fix and polymorphic handler deleter fix --- CHANGELOG.md | 6 ++++++ include/bitsery/ext/utils/pointer_utils.h | 10 +++++----- include/bitsery/ext/utils/polymorphism_utils.h | 5 ++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 337dae0..da947fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## future release... + +### Bug fixes +* fixed polymorphic handler deleter in `PolymorphicContext`, now it is captured by value and doesn't depend on lifetime of `PolymorphicContext` instance. +* fixed compilation errors in `ext/utils/pointer_utils.h` on macOS. + # [5.0.0](https://github.com/fraillt/bitsery/compare/v4.6.1...v5.0.0) (2019-07-09) This version reduces library complexity by removing redundant features and changing existing ones. diff --git a/include/bitsery/ext/utils/pointer_utils.h b/include/bitsery/ext/utils/pointer_utils.h index 77cfd16..f6f90da 100644 --- a/include/bitsery/ext/utils/pointer_utils.h +++ b/include/bitsery/ext/utils/pointer_utils.h @@ -153,7 +153,7 @@ namespace bitsery { public: explicit PointerLinkingContextSerialization(MemResourceBase* memResource = nullptr) : _currId{0}, - _ptrMap{StdPolyAlloc>{memResource}} {} + _ptrMap{StdPolyAlloc>{memResource}} {} PointerLinkingContextSerialization(const PointerLinkingContextSerialization&) = delete; @@ -190,7 +190,7 @@ namespace bitsery { size_t _currId; std::unordered_map, std::equal_to, - StdPolyAlloc> + StdPolyAlloc> > _ptrMap; }; @@ -198,7 +198,7 @@ namespace bitsery { public: explicit PointerLinkingContextDeserialization(MemResourceBase* memResource = nullptr) : _memResource{memResource}, - _idMap{StdPolyAlloc>{memResource}} {} + _idMap{StdPolyAlloc>{memResource}} {} PointerLinkingContextDeserialization(const PointerLinkingContextDeserialization&) = delete; @@ -244,7 +244,7 @@ namespace bitsery { MemResourceBase* _memResource; std::unordered_map, std::equal_to, - StdPolyAlloc>> _idMap; + StdPolyAlloc>> _idMap; }; } @@ -257,7 +257,7 @@ namespace bitsery { :pointer_utils::PointerLinkingContextSerialization(memResource), pointer_utils::PointerLinkingContextDeserialization(memResource) {}; - bool isValid() { + bool isValid() const { return isPointerSerializationValid() && isPointerDeserializationValid(); } }; diff --git a/include/bitsery/ext/utils/polymorphism_utils.h b/include/bitsery/ext/utils/polymorphism_utils.h index 21d0e65..6678230 100644 --- a/include/bitsery/ext/utils/polymorphism_utils.h +++ b/include/bitsery/ext/utils/polymorphism_utils.h @@ -144,11 +144,10 @@ namespace bitsery { BaseToDerivedKey key{RTTI::template get(), RTTI::template get()}; pointer_utils::StdPolyAlloc alloc{_memResource}; auto ptr = alloc.allocate(1); - std::shared_ptr handler(new (ptr)THandler{}, [this](THandler* data) { + std::shared_ptr handler(new (ptr)THandler{}, [alloc](THandler* data) mutable { data->~THandler(); - pointer_utils::StdPolyAlloc alloc{_memResource}; alloc.deallocate(data, 1); - }, pointer_utils::StdPolyAlloc(_memResource)); + }, alloc); if (_baseToDerivedMap .emplace(key, std::move(handler)) .second) {