From 42dd0e1f84c1aa4c0b4331bf0a99dea8c0cbe5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Thu, 25 Feb 2021 13:38:40 +0100 Subject: [PATCH] #1258: improve footprinting of CallbackUnion --- src/vt/pipe/callback/cb_union/cb_raw.h | 31 ++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/vt/pipe/callback/cb_union/cb_raw.h b/src/vt/pipe/callback/cb_union/cb_raw.h index 912f505211..810d157388 100644 --- a/src/vt/pipe/callback/cb_union/cb_raw.h +++ b/src/vt/pipe/callback/cb_union/cb_raw.h @@ -219,40 +219,43 @@ struct GeneralCallback { template void serialize(SerializerT& s) { - using EnumDataType = typename std::underlying_type::type; - EnumDataType val = static_cast(active_); - s | val; - s.skip(active_); + s | active_; - active_ = static_cast(val); - s.skip(u_); // only serialize actual content of the union + // serialize actual content of the union and account for leftovers and + // padding bytes when footprinting + auto ser = [&](auto& cb){ + s | cb; + s.addBytes(sizeof(this->u_) - sizeof(cb)); + }; + s.skip(u_); switch (active_) { case CallbackEnum::AnonCB: - s | u_.anon_cb_; + ser(u_.anon_cb_); break; case CallbackEnum::SendMsgCB: - s | u_.send_msg_cb_; + ser(u_.send_msg_cb_); break; case CallbackEnum::SendColMsgCB: - s | u_.send_col_msg_cb_; + ser(u_.send_col_msg_cb_); break; case CallbackEnum::BcastMsgCB: - s | u_.bcast_msg_cb_; + ser(u_.bcast_msg_cb_); break; case CallbackEnum::BcastColMsgCB: - s | u_.bcast_col_msg_cb_; + ser(u_.bcast_col_msg_cb_); break; case CallbackEnum::BcastColDirCB: - s | u_.bcast_col_dir_cb_; + ser(u_.bcast_col_dir_cb_); break; case CallbackEnum::BcastObjGrpCB: - s | u_.bcast_obj_cb_; + ser(u_.bcast_obj_cb_); break; case CallbackEnum::SendObjGrpCB: - s | u_.send_obj_cb_; + ser(u_.send_obj_cb_); break; case CallbackEnum::NoCB: // Serializing empty callback! + s.addBytes(sizeof(u_) - sizeof(active_)); break; default: vtAssert(0, "Should be unreachable");