HDF5: Add cleaner way of handling object destruction (explicit Close() for file and dataset, all destructors have HDF5 TRY blocks)
This commit is contained in:
+10
-8
@@ -327,6 +327,7 @@ HDF5Fapl::~HDF5Fapl() {
|
||||
H5E_BEGIN_TRY {
|
||||
H5Pclose(id);
|
||||
} H5E_END_TRY;
|
||||
id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -729,11 +730,9 @@ void HDF5File::Close() {
|
||||
if (H5Fflush(id, H5F_SCOPE_GLOBAL) < 0)
|
||||
throw JFJochException(JFJochExceptionCategory::HDF5, "Failed to flush HDF5 file");
|
||||
|
||||
hid_t tmp = id;
|
||||
id = -1;
|
||||
|
||||
if (H5Fclose(tmp) < 0)
|
||||
if (H5Fclose(id) < 0)
|
||||
throw JFJochException(JFJochExceptionCategory::HDF5, "Failed to close HDF5 file");
|
||||
id = -1;
|
||||
}
|
||||
|
||||
HDF5File::~HDF5File() {
|
||||
@@ -756,7 +755,10 @@ HDF5ReadOnlyFile::HDF5ReadOnlyFile(const std::string &filename) {
|
||||
}
|
||||
|
||||
HDF5ReadOnlyFile::~HDF5ReadOnlyFile() {
|
||||
if (id >= 0) H5Fclose(id);
|
||||
if (id >= 0) {
|
||||
H5E_BEGIN_TRY {H5Fclose(id); } H5E_END_TRY;
|
||||
id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
HDF5DataSet::HDF5DataSet(const HDF5Object &parent, const std::string &name, const HDF5DataType &data_type,
|
||||
@@ -845,10 +847,10 @@ std::string HDF5DataSet::ReadString() const {
|
||||
void HDF5DataSet::Close() {
|
||||
if (id < 0)
|
||||
return;
|
||||
hid_t tmp = id;
|
||||
id = -1;
|
||||
if (H5Dclose(tmp) < 0)
|
||||
|
||||
if (H5Dclose(id) < 0)
|
||||
throw JFJochException(JFJochExceptionCategory::HDF5, "Cannot close HDF5 dataset");
|
||||
id = -1;
|
||||
}
|
||||
|
||||
HDF5DataSet::~HDF5DataSet() {
|
||||
|
||||
Reference in New Issue
Block a user