Skip to content

Commit

Permalink
HDF5: Fix String Vlen Attribute Reads (#1084)
Browse files Browse the repository at this point in the history
We inofficially try to also support HDF5 variable lengths strings in
reading, just to increase compatibility.

This was never working it seems.
  • Loading branch information
ax3l authored Aug 11, 2021
1 parent ad8b1b2 commit 1b29cb6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/IO/HDF5/HDF5IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,18 +1479,19 @@ HDF5IOHandlerImpl::readAttribute(Writable* writable,
{
if( H5Tis_variable_str(attr_type) )
{
char* c = nullptr;
// refs.:
// https://github.com/HDFGroup/hdf5/blob/hdf5-1_12_0/tools/src/h5dump/h5dump_xml.c
hsize_t size = H5Tget_size(attr_type); // not yet the actual string length
std::vector< char > vc(size); // byte buffer to vlen strings
status = H5Aread(attr_id,
attr_type,
c);
VERIFY(status == 0,
"[HDF5] Internal error: Failed to read attribute " + attr_name +
" at " + concrete_h5_file_position(writable));
a = Attribute(auxiliary::strip(std::string(c), {'\0'}));
status = H5Dvlen_reclaim(attr_type,
attr_space,
H5P_DEFAULT,
c);
vc.data());
auto c_str = *((char**)vc.data()); // get actual string out
a = Attribute(std::string(c_str));
// free dynamically allocated vlen memory from H5Aread
H5Dvlen_reclaim(attr_type, attr_space, H5P_DEFAULT, vc.data());
// 1.12+:
//H5Treclaim(attr_type, attr_space, H5P_DEFAULT, vc.data());
} else
{
hsize_t size = H5Tget_size(attr_type);
Expand Down

0 comments on commit 1b29cb6

Please sign in to comment.