Skip to content

Commit

Permalink
Use std::vector instead of variable-length arrays to avoid Windows bu…
Browse files Browse the repository at this point in the history
…ilt errors
  • Loading branch information
oruebel committed Dec 22, 2024
1 parent 9ed9bd3 commit f6b306b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/io/hdf5/HDF5IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,12 @@ AQNWB::IO::DataBlockGeneric HDF5IO::readDataset(

// Get the number of dimensions and their sizes
int rank = dataspace.getSimpleExtentNdims();
hsize_t dims[rank];
dataspace.getSimpleExtentDims(dims, nullptr);
// Use a dynamic array as Windows doesn't support variable length arrays
std::vector<hsize_t> dims(rank);
dataspace.getSimpleExtentDims(dims.data(), nullptr);

// Store the shape information
result.shape.assign(dims, dims + rank);
result.shape.assign(dims.begin(), dims.end());

// Calculate the total number of elements
size_t numElements = 1;
Expand All @@ -358,19 +359,22 @@ AQNWB::IO::DataBlockGeneric HDF5IO::readDataset(
// Create a memory dataspace for the slice
H5::DataSpace memspace;
if (!start.empty() && !count.empty()) {
hsize_t offset[rank];
hsize_t block_count[rank];
// Use std::vector to create dynamic arrays to ensure Windows built works
std::vector<hsize_t> offset(rank);
std::vector<hsize_t> block_count(rank);
for (int i = 0; i < rank; ++i) {
offset[i] = start[i];
block_count[i] = count[i];
}

dataspace.selectHyperslab(
H5S_SELECT_SET,
block_count,
offset,
block_count.data(),
offset.data(),
stride_hsize.empty() ? nullptr : stride_hsize.data(),
block_hsize.empty() ? nullptr : block_hsize.data());
memspace = H5::DataSpace(rank, block_count);

memspace = H5::DataSpace(rank, block_count.data());
} else {
memspace = H5::DataSpace(dataspace);
}
Expand Down

0 comments on commit f6b306b

Please sign in to comment.