Skip to content

Commit

Permalink
Fix segfault when asking for BlocksInfo for a variable name that does…
Browse files Browse the repository at this point in the history
… not exist. Return value is now empty dictionary. Also fix handling 1D arrays made from LocalValues. Now this code works for examples/basics/values/valuesWrite.cpp ProcessID:

    with adios2.Stream("values.bp", 'rra') as f:
        e = f.engine
        bi = e.blocks_info("ProcessID", 0)
        print(f"Blocks info = {bi}")
  • Loading branch information
pnorbert authored and vicentebolea committed Feb 28, 2024
1 parent f4ac309 commit 37bd41a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions bindings/Python/py11Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,18 @@ std::vector<std::map<std::string, std::string>> Engine::BlocksInfo(std::string &
const size_t step) const
{
std::vector<std::map<std::string, std::string>> rv;
auto &varMap = m_Engine->m_IO.GetVariables();
auto itVariable = varMap.find(var_name);
if (itVariable == varMap.end())
{
return rv;
}

// Grab the specified variable object and get its type string
adios2::DataType var_type = m_Engine->GetIO().InquireVariableType(var_name);

MinVarInfo *minBlocksInfo = nullptr;
auto itVariable = m_Engine->m_IO.GetVariables().find(var_name);

auto Variable = itVariable->second.get();
minBlocksInfo = m_Engine->MinBlocksInfo(*Variable, 0);
if (minBlocksInfo)
Expand All @@ -293,7 +299,8 @@ std::vector<std::map<std::string, std::string>> Engine::BlocksInfo(std::string &
{
start_ss << ",";
}
start_ss << info.Start[i];
start_ss << (minBlocksInfo->WasLocalValue ? reinterpret_cast<size_t>(info.Start)
: info.Start[i]);
}
}
info_map["Start"] = start_ss.str();
Expand All @@ -310,7 +317,8 @@ std::vector<std::map<std::string, std::string>> Engine::BlocksInfo(std::string &
{
count_ss << ",";
}
count_ss << info.Count[i];
count_ss << (minBlocksInfo->WasLocalValue ? reinterpret_cast<size_t>(info.Count)
: info.Count[i]);
}
}
info_map["Count"] = count_ss.str();
Expand Down

0 comments on commit 37bd41a

Please sign in to comment.