Skip to content

Commit

Permalink
Merge pull request #144 from DARMA-tasking/143-virtual-serialization-…
Browse files Browse the repository at this point in the history
…templated-classes

143 fix virtual serialization of templated classes
  • Loading branch information
lifflander authored Oct 19, 2020
2 parents 418cba5 + 7c2f81d commit a91a0a3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/checkpoint/dispatch/reconstructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,15 @@ struct Reconstructor {

template <typename U = T>
static T* constructAllowFailImpl(void* buf, isNotConstructible<U>* = nullptr) {
checkpointAssert(
false,
"Checkpoint is wrongly trying to reconstruct an abstract base "
"class instance"
std::unique_ptr<char[]> msg = std::make_unique<char[]>(32768);
sprintf(
&msg[0],
"Checkpoint is failing to reconstruct a class %s, due to it being "
"abstract or the absence of a suitable constructor (default or tagged) "
"or reconstruct()",
typeid(T).name()
);
checkpointAssert(false, msg.get());
return nullptr;
}

Expand Down
6 changes: 4 additions & 2 deletions src/checkpoint/dispatch/vrt/serialize_instantiator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ struct InstantiateIfPossible<
ObjT,
SerializerT,
typename std::enable_if_t<
SerializableTraits<ObjT, SerializerT>::is_serializable
SerializableTraits<ObjT, SerializerT>::has_serialize_function or
SerializableTraits<ObjT, SerializerT>::is_bytecopyable
>
> {
static void registerIt() {
Expand All @@ -82,7 +83,8 @@ struct InstantiateIfPossible<
ObjT,
SerializerT,
typename std::enable_if_t<
not SerializableTraits<ObjT, SerializerT>::is_serializable
not (SerializableTraits<ObjT, SerializerT>::has_serialize_function or
SerializableTraits<ObjT, SerializerT>::is_bytecopyable)
>
> {
static void registerIt() {
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/test_virtual_serialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -612,4 +612,50 @@ INSTANTIATE_TYPED_TEST_CASE_P(
test_virtual_serialize_inst, TestVirtualSerialize, ConstructTypes,
);

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

// Test for virtual serialize with an abstract class

using TestVirtualSerializeTemplated = TestHarness;

struct HolderBase {
checkpoint_virtual_serialize_root()

virtual ~HolderBase() = default;

template <typename Serializer>
void serialize(Serializer& s) {}
};

template <typename ObjT>
struct HolderObjBase : HolderBase {
checkpoint_virtual_serialize_derived_from(HolderBase)

virtual ObjT* get() = 0;

template <typename Serializer>
void serialize(Serializer& s) {}
};

template <typename ObjT>
struct HolderBasic final : HolderObjBase<ObjT> {
checkpoint_virtual_serialize_derived_from(HolderObjBase<ObjT>)

ObjT* get() override { return obj_; }
ObjT* obj_ = nullptr;

template <typename Serializer>
void serialize(Serializer& s) {}
};

TEST_F(TestVirtualSerializeTemplated, test_virtual_serialize_templated) {
using TestType = std::unique_ptr<HolderBase>;
TestType ptr = std::make_unique<HolderBasic<int>>();

auto ret = checkpoint::serialize(ptr);
checkpoint::deserialize<TestType>(std::move(ret));
}

}}} // end namespace checkpoint::tests::unit

0 comments on commit a91a0a3

Please sign in to comment.