Skip to content

Commit

Permalink
Check error code of ?get_cset.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Nov 22, 2023
1 parent f27e94a commit a202568
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/highfive/bits/H5ReadWrite_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,18 @@ inline void enforce_ascii_hack(const DataType& dst, const DataType& src) {
// TEMP. CHANGE: Ensure that the character set is properly configured to prevent
// converter issues on HDF5 <=v1.12.0 when loading ASCII strings first.
// See https://github.com/HDFGroup/hdf5/issues/544 for further information.
if (H5Tget_cset(src.getId()) == H5T_CSET_ASCII) {
H5Tset_cset(dst.getId(), H5T_CSET_ASCII);
if(detail::h5t_get_class(dst.getId()) == H5T_STRING && detail::h5t_get_class(dst.getId()) == H5T_STRING) {
if (detail::h5t_get_cset(src.getId()) == H5T_CSET_ASCII) {
detail::h5t_set_cset(dst.getId(), H5T_CSET_ASCII);
}
}

}

template <>
struct string_type_checker<void> {
inline static DataType getDataType(const DataType& element_type, const DataType& dtype) {
if (H5Tget_class(element_type.getId()) == H5T_STRING) {
if (detail::h5t_get_class(element_type.getId()) == H5T_STRING) {
enforce_ascii_hack(element_type, dtype);
}
return element_type;
Expand Down
9 changes: 9 additions & 0 deletions include/highfive/bits/h5t_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,14 @@ inline void h5t_set_strpad(hid_t hid, H5T_str_t strpad) {
}
}

H5T_class_t h5t_get_class(hid_t type_id) {
H5T_class_t class_id = H5Tget_class(type_id);
if (class_id == H5T_NO_CLASS) {
throw DataTypeException("Failed to get class of type");
}

return class_id;
}

} // namespace detail
} // namespace HighFive

0 comments on commit a202568

Please sign in to comment.