Skip to content

Commit e7a28a7

Browse files
authored
Merge pull request #57 from aldanor/feature/is-threadsafe+fix-travis
Add is_library_threadsafe(), fix Travis
2 parents f37341f + e49f828 commit e7a28a7

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ before_install:
9696
hash -r;
9797
conda config --set always_yes yes --set changeps1 no;
9898
conda info -a;
99-
conda create -q -n testenv hdf5=${H5_CONDA};
99+
conda create -q -n testenv -c anaconda hdf5=${H5_CONDA};
100100
export HDF5_DIR="$HOME/miniconda/envs/testenv";
101101
export RUSTFLAGS="-C link-args=-Wl,-rpath,$HOME/miniconda/envs/testenv/lib";
102102
fi

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- `File::access_plist()` or `File::fapl()` to get file access plist.
99
- `File::create_plist()` or `File::fcpl()` to get file creation plist.
1010
- Added high-level wrappers for dataset access H5P API (`plist::DatasetAccess`).
11+
- Added `hdf5::is_library_threadsafe()` function.
1112

1213
### Changed
1314

@@ -38,7 +39,8 @@
3839
as a result `error-chain` dependency has been dropped.
3940
- `hdf5::Error` is now convertible from `ndarray::ShapeError`;
4041
`hdf5::ResultExt` trait has been removed.
41-
42+
- Renamed `hdf5::hdf5_version()` to `hdf5::library_version()`.
43+
4244
### Fixed
4345

4446
- Replaced deprecated `std::mem::uninitialized` with `std::mem::MaybeUninit`.

src/hl/file.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ impl FileBuilder {
353353

354354
#[cfg(test)]
355355
pub mod tests {
356-
use crate::hdf5_version;
357356
use crate::internal_prelude::*;
358357
use std::fs;
359358
use std::io::{Read, Write};
@@ -445,11 +444,10 @@ pub mod tests {
445444
assert!(file.size() > 0);
446445
let orig_size = fs::metadata(file.filename()).unwrap().len();
447446
assert!(file.size() > orig_size);
448-
if hdf5_version() >= (1, 10, 0) {
449-
assert_ne!(orig_size, 0);
450-
} else {
451-
assert_eq!(orig_size, 0);
452-
}
447+
#[cfg(hdf5_1_10_0)]
448+
assert_ne!(orig_size, 0);
449+
#[cfg(not(hdf5_1_10_0))]
450+
assert_eq!(orig_size, 0);
453451
assert!(file.flush().is_ok());
454452
assert!(file.size() > 0);
455453
let new_size = fs::metadata(file.filename()).unwrap().len();

src/lib.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ mod internal_prelude {
114114
pub mod test;
115115

116116
/// Returns the runtime version of the HDF5 library.
117-
pub fn hdf5_version() -> (u8, u8, u8) {
117+
pub fn library_version() -> (u8, u8, u8) {
118118
use self::internal_prelude::c_uint;
119119
use hdf5_sys::h5::H5get_libversion;
120120
let mut v: (c_uint, c_uint, c_uint) = (0, 0, 0);
@@ -123,12 +123,27 @@ pub fn hdf5_version() -> (u8, u8, u8) {
123123
.unwrap_or((0, 0, 0))
124124
}
125125

126+
/// Returns true if the HDF5 library is threadsafe.
127+
pub fn is_library_threadsafe() -> bool {
128+
#[cfg(hdf5_1_8_16)]
129+
{
130+
use self::internal_prelude::hbool_t;
131+
use hdf5_sys::h5::H5is_library_threadsafe;
132+
let mut ts: hbool_t = 0;
133+
h5call!(H5is_library_threadsafe(&mut ts)).map(|_| ts > 0).unwrap_or(false)
134+
}
135+
#[cfg(not(hdf5_1_8_16))]
136+
{
137+
cfg!(h5_have_threadsafe)
138+
}
139+
}
140+
126141
#[cfg(test)]
127142
pub mod tests {
128-
use super::hdf5_version;
143+
use crate::library_version;
129144

130145
#[test]
131-
pub fn test_hdf5_version() {
132-
assert!(hdf5_version() >= (1, 8, 4));
146+
pub fn test_library_version() {
147+
assert!(library_version() >= (1, 8, 4));
133148
}
134149
}

0 commit comments

Comments
 (0)