From cbbfffa9d44a2baffc8ce258377de26edbe9a208 Mon Sep 17 00:00:00 2001 From: Daniel Garcia-Sanchez Date: Mon, 27 Aug 2018 14:36:39 +0200 Subject: [PATCH] Remove the warnings of unused variables There are many warnings of unused variables in release mode because of Assert. Example: herr_t ret; ret = H5Pclose(plist); Assert(ret >= 0, ExcMessage("Error at H5Pclose")); In order to remove these warnings the declaration of variable ret has been moved from the functions to the class definition of HDF5Object. --- include/deal.II/base/hdf5.h | 26 +++++++++++++-- source/base/hdf5.cc | 66 ++++++++++++++++--------------------- source/base/hdf5.inst.in | 4 +-- 3 files changed, 54 insertions(+), 42 deletions(-) diff --git a/include/deal.II/base/hdf5.h b/include/deal.II/base/hdf5.h index 6a36845cfb..63ad9a62a7 100644 --- a/include/deal.II/base/hdf5.h +++ b/include/deal.II/base/hdf5.h @@ -249,7 +249,7 @@ namespace HDF5 */ template T - attr(const std::string attr_name) const; + attr(const std::string attr_name); /** * Writes an attribute. T can be float, double, std::complex, @@ -265,15 +265,35 @@ namespace HDF5 */ template void - write_attr(const std::string attr_name, const T value) const; + write_attr(const std::string attr_name, const T value); const std::string name; protected: + /** + * HDF5 identifier for the objects File, Group and Dataset + */ std::shared_ptr hdf5_reference; - // If true use mpi hdf5. If false use serial hdf5. + + /** + * If true use parallel HDF5, if false use serial HDF5. + */ const bool mpi; + + /** + * Returned value of the last HDF5 C library call. + * + * The HDF5 calls return a non-negative value if successful; otherwise they + * return a negative value. + * + * Calls such as + * [H5DWrite](https://support.hdfgroup.org/HDF5/doc/RM/RM_H5D.html#Dataset-Write) + * use this variable to store the returned value. Other calls such as + * [H5Pcreate](https://support.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-Create) + * don't use this variable to store the returned value. + */ + herr_t ret; }; /** diff --git a/source/base/hdf5.cc b/source/base/hdf5.cc index b7774d0974..8a856fe6d1 100644 --- a/source/base/hdf5.cc +++ b/source/base/hdf5.cc @@ -351,7 +351,7 @@ namespace HDF5 template T - HDF5Object::attr(const std::string attr_name) const + HDF5Object::attr(const std::string attr_name) { std::shared_ptr t_type = internal::get_hdf5_datatype(); T value; @@ -366,7 +366,7 @@ namespace HDF5 template <> bool - HDF5Object::attr(const std::string attr_name) const + HDF5Object::attr(const std::string attr_name) { // The enum field generated by h5py can be casted to int int int_value; @@ -381,7 +381,7 @@ namespace HDF5 template <> std::string - HDF5Object::attr(const std::string attr_name) const + HDF5Object::attr(const std::string attr_name) { // Reads a UTF8 variable string // @@ -395,10 +395,9 @@ namespace HDF5 // Todo: // - Use H5Dvlen_reclaim instead of free - char * string_out; - hid_t attr; - hid_t type; - herr_t ret; + char *string_out; + hid_t attr; + hid_t type; /* Create a datatype to refer to. */ type = H5Tcopy(H5T_C_S1); @@ -428,7 +427,7 @@ namespace HDF5 template void - HDF5Object::write_attr(const std::string attr_name, const T value) const + HDF5Object::write_attr(const std::string attr_name, const T value) { hid_t attr; hid_t aid; @@ -457,8 +456,7 @@ namespace HDF5 template <> void - HDF5Object::write_attr(const std::string attr_name, - const std::string value) const + HDF5Object::write_attr(const std::string attr_name, const std::string value) { // Writes a UTF8 variable string // @@ -469,10 +467,9 @@ namespace HDF5 // (char *). For this reason the std::string value has been copied to a C // string. - hid_t attr; - hid_t aid; - hid_t t_type; - herr_t ret; + hid_t attr; + hid_t aid; + hid_t t_type; // Reserve space for the string and the null terminator char *c_string_value = (char *)malloc(sizeof(char) * (value.size() + 1)); @@ -595,7 +592,6 @@ namespace HDF5 { std::shared_ptr t_type = internal::get_hdf5_datatype(); hid_t plist; - herr_t ret; Container data = internal::initialize_container(_dimensions); @@ -648,7 +644,6 @@ namespace HDF5 std::shared_ptr t_type = internal::get_hdf5_datatype(); hid_t plist; hid_t memory_dataspace; - herr_t ret; std::vector data_dimensions{ static_cast(coordinates.size() / _rank)}; @@ -714,7 +709,6 @@ namespace HDF5 std::shared_ptr t_type = internal::get_hdf5_datatype(); hid_t plist; hid_t memory_dataspace; - herr_t ret; // In this particular overload of read_hyperslab the data_dimensions are // the same as count @@ -779,9 +773,8 @@ namespace HDF5 std::shared_ptr t_type = internal::get_hdf5_datatype(); std::vector data_dimensions = {0}; - hid_t memory_dataspace; - hid_t plist; - herr_t ret; + hid_t memory_dataspace; + hid_t plist; memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL); Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); @@ -834,7 +827,6 @@ namespace HDF5 AssertDimension(_size, internal::get_container_size(data)); std::shared_ptr t_type = internal::get_hdf5_datatype(); hid_t plist; - herr_t ret; if (mpi) { @@ -877,9 +869,8 @@ namespace HDF5 std::shared_ptr t_type = internal::get_hdf5_datatype(); std::vector data_dimensions = {data.size()}; - hid_t memory_dataspace; - hid_t plist; - herr_t ret; + hid_t memory_dataspace; + hid_t plist; memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL); @@ -944,9 +935,8 @@ namespace HDF5 // the same as count std::vector data_dimensions = count; - hid_t memory_dataspace; - hid_t plist; - herr_t ret; + hid_t memory_dataspace; + hid_t plist; memory_dataspace = H5Screate_simple(data_dimensions.size(), data_dimensions.data(), NULL); @@ -1005,9 +995,8 @@ namespace HDF5 { std::shared_ptr t_type = internal::get_hdf5_datatype(); - hid_t memory_dataspace; - hid_t plist; - herr_t ret; + hid_t memory_dataspace; + hid_t plist; memory_dataspace = H5Screate_simple(data_dimensions.size(), data_dimensions.data(), NULL); @@ -1066,9 +1055,8 @@ namespace HDF5 std::shared_ptr t_type = internal::get_hdf5_datatype(); std::vector data_dimensions = {0}; - hid_t memory_dataspace; - hid_t plist; - herr_t ret; + hid_t memory_dataspace; + hid_t plist; memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL); H5Sselect_none(*dataspace); @@ -1143,8 +1131,12 @@ namespace HDF5 break; default: Assert(false, ExcInternalError()); + return std::string("Internal error"); break; } + // The function should not reach this line. + Assert(false, ExcInternalError()); + return std::string("Internal error"); } template <> @@ -1370,17 +1362,17 @@ namespace HDF5 // std::complex and std::complex in hdf5.inst template int - HDF5Object::attr(const std::string attr_name) const; + HDF5Object::attr(const std::string attr_name); template unsigned int - HDF5Object::attr(const std::string attr_name) const; + HDF5Object::attr(const std::string attr_name); // The specializations of HDF5Object::attr // and HDF5Object::attr have been defined above template void - HDF5Object::write_attr(const std::string attr_name, int value) const; + HDF5Object::write_attr(const std::string attr_name, int value); template void HDF5Object::write_attr(const std::string attr_name, - unsigned int value) const; + unsigned int value); template std::vector DataSet::read(); diff --git a/source/base/hdf5.inst.in b/source/base/hdf5.inst.in index 481b82391f..51b115f8b0 100644 --- a/source/base/hdf5.inst.in +++ b/source/base/hdf5.inst.in @@ -16,9 +16,9 @@ for (number : REAL_AND_COMPLEX_SCALARS) { - template number HDF5Object::attr(const std::string attr_name) const; + template number HDF5Object::attr(const std::string attr_name); template void HDF5Object::write_attr(const std::string attr_name, - number value) const; + number value); template std::vector DataSet::read(); template Vector DataSet::read(); -- 2.39.5