Merge pull request #1088 from smharper/mem_errors

More fixes to make Valgrind happy
This commit is contained in:
Paul Romano 2018-10-09 06:59:17 -05:00 committed by GitHub
commit 2afb1249b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 9 deletions

View file

@ -162,13 +162,13 @@ void read_attribute(hid_t obj_id, const char* name, xt::xarray<T>& arr)
std::size_t size = 1;
for (const auto x : shape)
size *= x;
T* buffer = new T[size];
std::vector<T> buffer(size);
// Read data from attribute
read_attr(obj_id, name, H5TypeMap<T>::type_id, buffer);
read_attr(obj_id, name, H5TypeMap<T>::type_id, buffer.data());
// Adapt array into xarray
arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape);
arr = xt::adapt(buffer, shape);
}
// overload for std::string
@ -244,13 +244,13 @@ void read_dataset(hid_t dset, xt::xarray<T>& arr, bool indep=false)
std::size_t size = 1;
for (const auto x : shape)
size *= x;
T* buffer = new T[size];
std::vector<T> buffer(size);
// Read data from attribute
read_dataset(dset, nullptr, H5TypeMap<T>::type_id, buffer, indep);
read_dataset(dset, nullptr, H5TypeMap<T>::type_id, buffer.data(), indep);
// Adapt into xarray
arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape);
arr = xt::adapt(buffer, shape);
}
template <typename T>
@ -273,13 +273,13 @@ void read_dataset_as_shape(hid_t obj_id, const char* name,
std::size_t size = 1;
for (const auto x : arr.shape())
size *= x;
T* buffer = new T[size];
std::vector<T> buffer(size);
// Read data from attribute
read_dataset(dset, nullptr, H5TypeMap<T>::type_id, buffer, indep);
read_dataset(dset, nullptr, H5TypeMap<T>::type_id, buffer.data(), indep);
// Adapt into xarray
arr = xt::adapt(buffer, size, xt::acquire_ownership(), arr.shape());
arr = xt::adapt(buffer, arr.shape());
close_dataset(dset);
}

View file

@ -14,6 +14,7 @@ template<class It, class T>
typename std::iterator_traits<It>::difference_type
lower_bound_index(It first, It last, const T& value)
{
if (*first == value) return 0;
It index = std::lower_bound(first, last, value) - 1;
return (index == last) ? -1 : index - first;
}

View file

@ -675,6 +675,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_double_c(obj_id, c_loc(name_), buffer_, indep_)
else
@ -698,6 +699,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_double_c(obj_id, c_loc(name_), buffer, indep_)
else
@ -720,6 +722,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_double_c(obj_id, c_loc(name_), buffer, indep_)
else
@ -742,6 +745,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_double_c(obj_id, c_loc(name_), buffer, indep_)
else
@ -764,6 +768,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_double_c(obj_id, c_loc(name_), buffer, indep_)
else
@ -888,6 +893,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_int_c(obj_id, c_loc(name_), buffer_, indep_)
else
@ -911,6 +917,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_int_c(obj_id, c_loc(name_), buffer, indep_)
else
@ -933,6 +940,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_int_c(obj_id, c_loc(name_), buffer, indep_)
else
@ -955,6 +963,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_int_c(obj_id, c_loc(name_), buffer, indep_)
else
@ -977,6 +986,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_int_c(obj_id, c_loc(name_), buffer, indep_)
else
@ -1025,6 +1035,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_llong_c(obj_id, c_loc(name_), buffer_, indep_)
else
@ -1425,6 +1436,7 @@ contains
! If 'name' argument is passed, obj_id is interpreted to be a group and
! 'name' is the name of the dataset we should read from
if (present(name)) then
allocate(name_(len_trim(name) + 1))
name_ = to_c_string(name)
call read_complex_c(obj_id, c_loc(name_), buffer, indep_)
else