Skip to content

Commit

Permalink
Check error code of ?get_cset. (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc authored Nov 24, 2023
1 parent 90f8fd6 commit acf0fea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions include/highfive/bits/H5ReadWrite_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ inline void enforce_ascii_hack(const DataType& dst, const DataType& src) {
// converter issues on HDF5 <=v1.12.0 when loading ASCII strings first.
// See https://github.com/HDFGroup/hdf5/issues/544 for further information.

bool is_dst_string = H5Tget_class(dst.getId()) == H5T_STRING;
bool is_src_string = H5Tget_class(src.getId()) == H5T_STRING;
bool is_dst_string = detail::h5t_get_class(dst.getId()) == H5T_STRING;
bool is_src_string = detail::h5t_get_class(src.getId()) == H5T_STRING;

if (is_dst_string && is_src_string) {
if (H5Tget_cset(src.getId()) == H5T_CSET_ASCII) {
H5Tset_cset(dst.getId(), H5T_CSET_ASCII);
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) {
}
}

inline 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 acf0fea

Please sign in to comment.