Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ if(openPMD_BUILD_TESTING)
list(APPEND ${out_list}
test/Files_SerialIO/close_and_reopen_test.cpp
test/Files_SerialIO/filebased_write_test.cpp
test/Files_SerialIO/issue_1744_unique_ptrs_at_close_time.cpp
)
elseif(${test_name} STREQUAL "ParallelIO" AND openPMD_HAVE_MPI)
list(APPEND ${out_list}
Expand Down
17 changes: 10 additions & 7 deletions src/IO/ADIOS/ADIOS2File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,18 @@ void ADIOS2File::finalize()
{
return;
}
if (!m_uniquePtrPuts.empty())
{
throw error::Internal(
"[ADIOS2 backend] Orphaned unique-ptr put operations found "
"when closing file.");
}
// if write accessing, ensure that the engine is opened
if (!m_engine && writeOnly(m_mode))
// and that all datasets are written
// (attributes and unique_ptr datasets are written upon closing a step
// or a file which users might never do)
bool needToWrite = !m_uniquePtrPuts.empty();
if ((needToWrite || !m_engine) && writeOnly(m_mode))
{
getEngine();
for (auto &entry : m_uniquePtrPuts)
{
entry.run(*this);
}
}
if (m_engine)
{
Expand All @@ -250,6 +252,7 @@ void ADIOS2File::finalize()
m_ADIOS.RemoveIO(m_IOName);
}
}
m_uniquePtrPuts.clear();
finalized = true;
}

Expand Down
4 changes: 4 additions & 0 deletions test/Files_SerialIO/SerialIOTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ namespace close_and_reopen_test
{
auto close_and_reopen_test() -> void;
}
namespace issue_1744_unique_ptrs_at_close_time
{
auto issue_1744_unique_ptrs_at_close_time() -> void;
}
33 changes: 33 additions & 0 deletions test/Files_SerialIO/issue_1744_unique_ptrs_at_close_time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "SerialIOTests.hpp"

#include "openPMD/Dataset.hpp"
#include "openPMD/openPMD.hpp"

#include <memory>
#include <numeric>

// clang-format off
/*
* Tests regression introduced with #1743:
* terminate called after throwing an instance of 'openPMD::error::Internal'
* what(): Internal error: [ADIOS2 backend] Orphaned unique-ptr put operations found when closing file.
* This is a bug. Please report at ' https://github.com/openPMD/openPMD-api/issues'.
*/
// clang-format on

namespace issue_1744_unique_ptrs_at_close_time
{
auto issue_1744_unique_ptrs_at_close_time() -> void
{
openPMD::Series write(
"../samples/issue_1744_unique_ptrs_at_close_time.bp4",
openPMD::Access::CREATE,
R"({"iteration_encoding": "group_based"})");
std::unique_ptr<int[]> data_unique(new int[10]);
std::iota(data_unique.get(), data_unique.get() + 10, 0);
auto E_x = write.snapshots()[0].meshes["E"]["x"];
E_x.resetDataset({openPMD::Datatype::INT, {10}});
E_x.storeChunk(std::move(data_unique), {0}, {10});
write.close();
}
} // namespace issue_1744_unique_ptrs_at_close_time
8 changes: 8 additions & 0 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,14 @@
}
}

TEST_CASE("issue_1744_unique_ptrs_at_close_time", "[serial]")

Check notice

Code scanning / CodeQL

Unused static function Note test

Static function C_A_T_C_H_T_E_S_T_16 is unreachable (
autoRegistrar17
must be removed at the same time)
{
#if openPMD_HAVE_ADIOS2
issue_1744_unique_ptrs_at_close_time::
issue_1744_unique_ptrs_at_close_time();
#endif
}

#if openPMD_HAVE_ADIOS2
TEST_CASE("close_and_reopen_test", "[serial]")
{
Expand Down
Loading