Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDF5: Fix String Vlen Attribute Reads #1084

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
HDF5: Fix String Vlen Attribute Reads
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 committed Aug 10, 2021
commit ce1d8b2731ff4a75de634e92fb3efe891ac4b0c5
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