Skip to content

Commit

Permalink
Merge pull request #3881 from vicentebolea/recover-abi-compt
Browse files Browse the repository at this point in the history
bp5: make RecMap an static anon namespaced var
  • Loading branch information
vicentebolea authored Oct 31, 2023
2 parents 133ccc7 + ec30c44 commit b91aa01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
35 changes: 28 additions & 7 deletions source/adios2/toolkit/format/bp5/BP5Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,37 @@ namespace adios2
namespace format
{

namespace
{
// To keep ABI compatibility with ADIOS 2.9.0
static std::map<BP5Serializer *, BP5Serializer::RecMap> GlobalRecMap;
}

BP5Serializer::RecMap &BP5Serializer::GetRecMap(BP5Serializer *ptr)
{
auto it = GlobalRecMap.find(ptr);
if (it == GlobalRecMap.end())
{
it = GlobalRecMap.insert({ptr, {}}).first;
}
return it->second;
}

BP5Serializer::BP5Serializer() { Init(); }
BP5Serializer::~BP5Serializer()
{
if (!Info.RecMap.empty())
auto &rec_map = BP5Serializer::GetRecMap(this);
if (!rec_map.empty())
{
for (auto &rec : Info.RecMap)
for (auto &rec : rec_map)
{
if (rec.second.OperatorType)
free(rec.second.OperatorType);
}
Info.RecMap.clear();
rec_map.clear();
}
GlobalRecMap.erase(this);

if (Info.MetaFieldCount)
free_FMfield_list(Info.MetaFields);
if (Info.LocalFMContext)
Expand Down Expand Up @@ -79,8 +98,9 @@ void BP5Serializer::Init()
}
BP5Serializer::BP5WriterRec BP5Serializer::LookupWriterRec(void *Key)
{
auto it = Info.RecMap.find(Key);
if (it != Info.RecMap.end())
auto &rec_map = BP5Serializer::GetRecMap(this);
auto it = rec_map.find(Key);
if (it != rec_map.end())
{
return const_cast<BP5WriterRec>(&(it->second));
}
Expand Down Expand Up @@ -438,7 +458,8 @@ BP5Serializer::CreateWriterRec(void *Variable, const char *Name, DataType Type,
size_t ElemSize, size_t DimCount)
{
core::VariableBase *VB = static_cast<core::VariableBase *>(Variable);
auto obj = Info.RecMap.insert(std::make_pair(Variable, _BP5WriterRec()));
auto obj = BP5Serializer::GetRecMap(this).insert(
std::make_pair(Variable, _BP5WriterRec()));
BP5WriterRec Rec = &obj.first->second;
if (Type == DataType::String)
ElemSize = sizeof(char *);
Expand Down Expand Up @@ -1129,7 +1150,7 @@ BufferV *BP5Serializer::ReinitStepData(BufferV *DataBuffer,

void BP5Serializer::CollectFinalShapeValues()
{
for (auto it : Info.RecMap)
for (auto it : BP5Serializer::GetRecMap(this))
{
BP5WriterRec Rec = &it.second;
if (Rec->Shape == ShapeID::GlobalArray)
Expand Down
12 changes: 6 additions & 6 deletions source/adios2/toolkit/format/bp5/BP5Serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#pragma warning(disable : 4250)
#endif

#include <unordered_map>

namespace adios2
{
namespace format
Expand All @@ -42,9 +40,7 @@ class BP5Serializer : virtual public BP5Base
Buffer *AttributeEncodeBuffer;
BufferV *DataBuffer;

~TimestepInfo()
{
}
~TimestepInfo() {}
};

typedef struct _MetadataInfo
Expand Down Expand Up @@ -162,6 +158,7 @@ class BP5Serializer : virtual public BP5Base
struct FFSWriterMarshalBase
{
int RecCount = 0;
BP5WriterRec RecList = NULL;
FMContext LocalFMContext = {0};
int MetaFieldCount = 0;
FMFieldList MetaFields = NULL;
Expand All @@ -171,7 +168,6 @@ class BP5Serializer : virtual public BP5Base
FMFormat AttributeFormat = NULL;
void *AttributeData = NULL;
int AttributeSize = 0;
std::unordered_map<void *, _BP5WriterRec> RecMap;
};

FMFormat GenericAttributeFormat = NULL;
Expand Down Expand Up @@ -255,6 +251,10 @@ class BP5Serializer : virtual public BP5Base
size_t ElemCount;
void *Array;
} ArrayRec;

public:
using RecMap = std::unordered_map<void *, BP5Serializer::_BP5WriterRec>;
static RecMap &GetRecMap(BP5Serializer *ptr);
};

} // end namespace format
Expand Down

0 comments on commit b91aa01

Please sign in to comment.