Skip to content

Commit

Permalink
BUG: Fix HDF5 implicit copy crashes. (#924)
Browse files Browse the repository at this point in the history
Signed-off-by: Jared Duffey <jared.duffey@bluequartz.net>
  • Loading branch information
JDuffeyBQ committed Apr 23, 2024
1 parent 12c9140 commit 1d80265
Show file tree
Hide file tree
Showing 29 changed files with 481 additions and 230 deletions.
7 changes: 7 additions & 0 deletions cmake/Utility.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,19 @@ function(simplnx_enable_warnings)
set(SHADOW_WARNING "shadow-all")
endif()

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CLANG_WARNINGS
-Werror=implicit-exception-spec-mismatch # Wimplicit-exception-spec-mismatch: function previously declared with an explicit/implicit exception specification redeclared with an implicit/explicit exception specification
)
endif()

target_compile_options(${ARG_TARGET}
PRIVATE
# Warning to error
-Werror=parentheses # Wparentheses: Warn if parentheses are omitted in certain contexts, such as when there is an assignment in a context where a truth value is expected, or when operators are nested whose precedence people often get confused about
-Werror=return-type # Wreturn-type: Warn about any "return" statement with no return value in a function whose return type is not "void"
-Werror=${SHADOW_WARNING} # Wshadow: Warn whenever a local variable or type declaration shadows another variable, parameter, type, class member (in C++), or instance variable (in Objective-C) or whenever a built-in function is shadowed.
${CLANG_WARNINGS}
)

endif()
Expand Down
17 changes: 16 additions & 1 deletion src/simplnx/Utilities/Parsing/HDF5/IO/AttributeIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@ AttributeIO::AttributeIO(IdType objectId, const std::string& attrName)
HDF_ERROR_HANDLER_ON
}

AttributeIO::~AttributeIO()
AttributeIO::AttributeIO(AttributeIO&& other) noexcept
{
m_ObjectId = std::exchange(other.m_ObjectId, 0);
m_AttributeId = std::exchange(other.m_AttributeId, 0);
m_AttributeName = std::move(other.m_AttributeName);
}

AttributeIO& AttributeIO::operator=(AttributeIO&& other) noexcept
{
m_ObjectId = std::exchange(other.m_ObjectId, 0);
m_AttributeId = std::exchange(other.m_AttributeId, 0);
m_AttributeName = std::move(other.m_AttributeName);
return *this;
}

AttributeIO::~AttributeIO() noexcept
{
closeHdf5();
}
Expand Down
12 changes: 6 additions & 6 deletions src/simplnx/Utilities/Parsing/HDF5/IO/AttributeIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ class SIMPLNX_EXPORT AttributeIO
AttributeIO(IdType objectId, const std::string& attrName);

AttributeIO(const AttributeIO& other) = delete;
AttributeIO(AttributeIO&& other) noexcept = default;
AttributeIO(AttributeIO&& other) noexcept;

AttributeIO& operator=(const AttributeIO& other) = delete;
AttributeIO& operator=(AttributeIO&& other) noexcept;

/**
* @brief Releases the wrapped HDF5 attribute.
*/
virtual ~AttributeIO();
~AttributeIO() noexcept;

/**
* @brief Returns true if the AttributeIO has a valid target.
Expand Down Expand Up @@ -167,9 +170,6 @@ class SIMPLNX_EXPORT AttributeIO
template <typename T>
Result<> writeVector(const DimsVector& dims, const std::vector<T>& vector);

AttributeIO& operator=(const AttributeIO& other) = delete;
AttributeIO& operator=(AttributeIO&& other) noexcept = delete;

protected:
/**
* @brief Closes the HDF5 ID and resets it to 0.
Expand All @@ -186,7 +186,7 @@ class SIMPLNX_EXPORT AttributeIO
private:
IdType m_ObjectId = 0;
IdType m_AttributeId = 0;
const std::string m_AttributeName;
std::string m_AttributeName;
};

extern template SIMPLNX_EXPORT int8_t AttributeIO::readAsValue<int8_t>() const;
Expand Down
6 changes: 2 additions & 4 deletions src/simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

namespace nx::core::HDF5
{
DatasetIO::DatasetIO()
{
}
DatasetIO::DatasetIO() = default;

DatasetIO::DatasetIO(IdType parentId, const std::string& datasetName)
: ObjectIO(parentId)
Expand All @@ -29,7 +27,7 @@ DatasetIO::DatasetIO(DatasetIO&& other) noexcept
{
}

DatasetIO::~DatasetIO()
DatasetIO::~DatasetIO() noexcept
{
closeHdf5();
}
Expand Down
8 changes: 4 additions & 4 deletions src/simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ class SIMPLNX_EXPORT DatasetIO : public ObjectIO

DatasetIO(DatasetIO&& other) noexcept;

DatasetIO& operator=(const DatasetIO& rhs) = delete;
DatasetIO& operator=(DatasetIO&& rhs) noexcept;

/**
* @brief Releases the HDF5 dataset.
*/
virtual ~DatasetIO();
~DatasetIO() noexcept override;

/**
* @brief Returns true if the DatasetIO has a valid target. Otherwise,
Expand Down Expand Up @@ -260,9 +263,6 @@ class SIMPLNX_EXPORT DatasetIO : public ObjectIO
createOrOpenDataset<T>(dimensions, properties);
}

DatasetIO& operator=(const DatasetIO& rhs) = delete;
DatasetIO& operator=(DatasetIO&& rhs) noexcept;

protected:
/**
* @brief Closes the HDF5 ID and resets it to 0.
Expand Down
13 changes: 1 addition & 12 deletions src/simplnx/Utilities/Parsing/HDF5/IO/FileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ hid_t createOrOpenFile(const std::filesystem::path& filepath)
return H5Fcreate(filepath.string().c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
}

FileIO::FileIO()
: GroupIO()
{
}
FileIO::FileIO() = default;

FileIO::FileIO(const std::filesystem::path& filepath)
: GroupIO(0, createOrOpenFile(filepath))
Expand All @@ -130,14 +127,6 @@ FileIO::FileIO(IdType fileId)
{
}

FileIO::FileIO(FileIO&& rhs) noexcept
: GroupIO()
{
auto rhsId = rhs.getId();
setId(rhsId);
rhs.setId(-1);
}

FileIO::~FileIO() noexcept
{
closeHdf5();
Expand Down
10 changes: 5 additions & 5 deletions src/simplnx/Utilities/Parsing/HDF5/IO/FileIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ class SIMPLNX_EXPORT FileIO : public GroupIO
* @brief Move constructor.
* @param rhs
*/
FileIO(FileIO&& rhs) noexcept;
FileIO(FileIO&& rhs) noexcept = default;

FileIO& operator=(const FileIO& rhs) = delete;
FileIO& operator=(FileIO&& rhs) noexcept = default;

/**
* @brief Releases the HDF5 file ID.
*/
virtual ~FileIO() noexcept;
~FileIO() noexcept override;

/**
* @brief Returns the HDF5 file name. Returns an empty string if the file
Expand All @@ -81,9 +84,6 @@ class SIMPLNX_EXPORT FileIO : public GroupIO
*/
std::string getName() const override;

FileIO& operator=(const FileIO& rhs) = delete;
FileIO& operator=(FileIO&& rhs) noexcept = default;

protected:
/**
* @brief Closes the HDF5 ID and resets it to 0.
Expand Down
8 changes: 4 additions & 4 deletions src/simplnx/Utilities/Parsing/HDF5/IO/GroupIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ class SIMPLNX_EXPORT GroupIO : public ObjectIO
GroupIO(const GroupIO& other) = delete;
GroupIO(GroupIO&& other) noexcept = default;

GroupIO& operator=(const GroupIO& other) = delete;
GroupIO& operator=(GroupIO&& other) noexcept = default;

/**
* @brief Releases the wrapped HDF5 group.
*/
virtual ~GroupIO() noexcept;
~GroupIO() noexcept override;

/**
* @brief Attempts to open a nested HDF5 group with the specified name.
Expand Down Expand Up @@ -138,9 +141,6 @@ class SIMPLNX_EXPORT GroupIO : public ObjectIO
*/
bool isDataset(const std::string& childName) const;

GroupIO& operator=(const GroupIO& other) = delete;
GroupIO& operator=(GroupIO&& other) noexcept = default;

protected:
/**
* @brief Constructs a GroupWriter for use in derived classes. This
Expand Down
15 changes: 15 additions & 0 deletions src/simplnx/Utilities/Parsing/HDF5/IO/ObjectIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ ObjectIO::ObjectIO(IdType parentId, const std::string& targetName)
m_Id = H5Oopen(parentId, targetName.c_str(), H5P_DEFAULT);
}

ObjectIO::ObjectIO(ObjectIO&& other) noexcept
{
m_Id = std::exchange(other.m_Id, 0);
m_ParentId = std::exchange(other.m_ParentId, 0);
m_SharedParentPtr = std::move(other.m_SharedParentPtr);
}

ObjectIO& ObjectIO::operator=(ObjectIO&& other) noexcept
{
m_Id = std::exchange(other.m_Id, 0);
m_ParentId = std::exchange(other.m_ParentId, 0);
m_SharedParentPtr = std::move(other.m_SharedParentPtr);
return *this;
}

ObjectIO::~ObjectIO() noexcept
{
closeHdf5();
Expand Down
8 changes: 4 additions & 4 deletions src/simplnx/Utilities/Parsing/HDF5/IO/ObjectIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class SIMPLNX_EXPORT ObjectIO
ObjectIO(IdType parentId, const std::string& targetName);

ObjectIO(const ObjectIO& other) = delete;
ObjectIO(ObjectIO&& other) noexcept = default;
ObjectIO(ObjectIO&& other) noexcept;

ObjectIO& operator=(const ObjectIO& other) = delete;
ObjectIO& operator=(ObjectIO&& other) noexcept;

/**
* @brief Releases the wrapped HDF5 object.
Expand Down Expand Up @@ -131,9 +134,6 @@ class SIMPLNX_EXPORT ObjectIO
*/
AttributeIO createAttribute(const std::string& name);

ObjectIO& operator=(const ObjectIO& other) = delete;
ObjectIO& operator=(ObjectIO&& other) noexcept = default;

protected:
/**
* @brief Constructs an ObjectIO for use in derived classes. This
Expand Down
13 changes: 13 additions & 0 deletions src/simplnx/Utilities/Parsing/HDF5/Readers/AttributeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ AttributeReader::AttributeReader(IdType objectId, const std::string& attrName)
HDF_ERROR_HANDLER_ON
}

AttributeReader::AttributeReader(AttributeReader&& other) noexcept
{
m_ObjectId = std::exchange(other.m_ObjectId, 0);
m_AttributeId = std::exchange(other.m_AttributeId, 0);
}

AttributeReader& AttributeReader::operator=(AttributeReader&& other) noexcept
{
m_ObjectId = std::exchange(other.m_ObjectId, 0);
m_AttributeId = std::exchange(other.m_AttributeId, 0);
return *this;
}

AttributeReader::~AttributeReader() noexcept
{
closeHdf5();
Expand Down
10 changes: 5 additions & 5 deletions src/simplnx/Utilities/Parsing/HDF5/Readers/AttributeReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ class SIMPLNX_EXPORT AttributeReader
AttributeReader(IdType objectId, const std::string& attrName);

AttributeReader(const AttributeReader& other) = delete;
AttributeReader(AttributeReader&& other) noexcept = default;
AttributeReader(AttributeReader&& other) noexcept;

AttributeReader& operator=(const AttributeReader& other) = delete;
AttributeReader& operator=(AttributeReader&& other) noexcept;

/**
* @brief Releases the wrapped HDF5 attribute.
*/
virtual ~AttributeReader() noexcept;
~AttributeReader() noexcept;

/**
* @brief Returns true if the AttributeReader has a valid target.
Expand Down Expand Up @@ -149,9 +152,6 @@ class SIMPLNX_EXPORT AttributeReader
*/
std::string readAsString() const;

AttributeReader& operator=(const AttributeReader& other) = delete;
AttributeReader& operator=(AttributeReader&& other) noexcept = default;

protected:
/**
* @brief Closes the HDF5 ID and resets it to 0.
Expand Down
6 changes: 2 additions & 4 deletions src/simplnx/Utilities/Parsing/HDF5/Readers/DatasetReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@

namespace nx::core::HDF5
{
DatasetReader::DatasetReader()
{
}
DatasetReader::DatasetReader() = default;

DatasetReader::DatasetReader(IdType parentId, const std::string& dataName)
: ObjectReader(parentId, H5Dopen(parentId, dataName.c_str(), H5P_DEFAULT))
{
}

DatasetReader::~DatasetReader()
DatasetReader::~DatasetReader() noexcept
{
closeHdf5();
}
Expand Down
8 changes: 4 additions & 4 deletions src/simplnx/Utilities/Parsing/HDF5/Readers/DatasetReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ class SIMPLNX_EXPORT DatasetReader : public ObjectReader
DatasetReader(const DatasetReader& other) = delete;
DatasetReader(DatasetReader&& other) noexcept = default;

DatasetReader& operator=(const DatasetReader& other) = delete;
DatasetReader& operator=(DatasetReader&& other) noexcept = default;

/**
* @brief Releases the HDF5 dataset.
*/
virtual ~DatasetReader();
~DatasetReader() noexcept override;

/**
* @brief Returns the dataspace's HDF5 ID. Returns 0 if the attribute is
Expand Down Expand Up @@ -125,9 +128,6 @@ class SIMPLNX_EXPORT DatasetReader : public ObjectReader

std::string getFilterName() const;

DatasetReader& operator=(const DatasetReader& other) = delete;
DatasetReader& operator=(DatasetReader&& other) noexcept = default;

protected:
/**
* @brief Closes the HDF5 ID and resets it to 0.
Expand Down
8 changes: 4 additions & 4 deletions src/simplnx/Utilities/Parsing/HDF5/Readers/FileReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ class SIMPLNX_EXPORT FileReader : public GroupReader
FileReader(const FileReader& other) = delete;
FileReader(FileReader&& other) noexcept = default;

FileReader& operator=(const FileReader& other) = delete;
FileReader& operator=(FileReader&& other) noexcept = default;

/**
* @brief Releases the HDF5 file ID.
*/
virtual ~FileReader() noexcept;
~FileReader() noexcept override;

/**
* @brief Returns the HDF5 file name. Returns an empty string if the file
Expand All @@ -41,9 +44,6 @@ class SIMPLNX_EXPORT FileReader : public GroupReader
*/
std::string getName() const override;

FileReader& operator=(const FileReader& other) = delete;
FileReader& operator=(FileReader&& other) noexcept = default;

protected:
/**
* @brief Closes the HDF5 ID and resets it to 0.
Expand Down
8 changes: 4 additions & 4 deletions src/simplnx/Utilities/Parsing/HDF5/Readers/GroupReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ class SIMPLNX_EXPORT GroupReader : public ObjectReader
GroupReader(const GroupReader& other) = delete;
GroupReader(GroupReader&& other) noexcept = default;

GroupReader& operator=(const GroupReader& other) = delete;
GroupReader& operator=(GroupReader&& other) noexcept = default;

/**
* @brief Releases the wrapped HDF5 group.
*/
virtual ~GroupReader() noexcept;
~GroupReader() noexcept override;

/**
* @brief Attempts to open a nested HDF5 group with the specified name.
Expand Down Expand Up @@ -90,9 +93,6 @@ class SIMPLNX_EXPORT GroupReader : public ObjectReader
*/
bool isDataset(const std::string& childName) const;

GroupReader& operator=(const GroupReader& other) = delete;
GroupReader& operator=(GroupReader&& other) noexcept = default;

protected:
/**
* @brief Closes the HDF5 ID and resets it to 0.
Expand Down

0 comments on commit 1d80265

Please sign in to comment.