Skip to content

Commit

Permalink
Merge pull request #57 from aldanor/feature/is-threadsafe+fix-travis
Browse files Browse the repository at this point in the history
Add is_library_threadsafe(), fix Travis
  • Loading branch information
aldanor committed Aug 16, 2019
2 parents f37341f + e49f828 commit e7a28a7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -96,7 +96,7 @@ before_install:
hash -r;
conda config --set always_yes yes --set changeps1 no;
conda info -a;
conda create -q -n testenv hdf5=${H5_CONDA};
conda create -q -n testenv -c anaconda hdf5=${H5_CONDA};
export HDF5_DIR="$HOME/miniconda/envs/testenv";
export RUSTFLAGS="-C link-args=-Wl,-rpath,$HOME/miniconda/envs/testenv/lib";
fi
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
- `File::access_plist()` or `File::fapl()` to get file access plist.
- `File::create_plist()` or `File::fcpl()` to get file creation plist.
- Added high-level wrappers for dataset access H5P API (`plist::DatasetAccess`).
- Added `hdf5::is_library_threadsafe()` function.

### Changed

Expand Down Expand Up @@ -38,7 +39,8 @@
as a result `error-chain` dependency has been dropped.
- `hdf5::Error` is now convertible from `ndarray::ShapeError`;
`hdf5::ResultExt` trait has been removed.

- Renamed `hdf5::hdf5_version()` to `hdf5::library_version()`.

### Fixed

- Replaced deprecated `std::mem::uninitialized` with `std::mem::MaybeUninit`.
Expand Down
10 changes: 4 additions & 6 deletions src/hl/file.rs
Expand Up @@ -353,7 +353,6 @@ impl FileBuilder {

#[cfg(test)]
pub mod tests {
use crate::hdf5_version;
use crate::internal_prelude::*;
use std::fs;
use std::io::{Read, Write};
Expand Down Expand Up @@ -445,11 +444,10 @@ pub mod tests {
assert!(file.size() > 0);
let orig_size = fs::metadata(file.filename()).unwrap().len();
assert!(file.size() > orig_size);
if hdf5_version() >= (1, 10, 0) {
assert_ne!(orig_size, 0);
} else {
assert_eq!(orig_size, 0);
}
#[cfg(hdf5_1_10_0)]
assert_ne!(orig_size, 0);
#[cfg(not(hdf5_1_10_0))]
assert_eq!(orig_size, 0);
assert!(file.flush().is_ok());
assert!(file.size() > 0);
let new_size = fs::metadata(file.filename()).unwrap().len();
Expand Down
23 changes: 19 additions & 4 deletions src/lib.rs
Expand Up @@ -114,7 +114,7 @@ mod internal_prelude {
pub mod test;

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

/// Returns true if the HDF5 library is threadsafe.
pub fn is_library_threadsafe() -> bool {
#[cfg(hdf5_1_8_16)]
{
use self::internal_prelude::hbool_t;
use hdf5_sys::h5::H5is_library_threadsafe;
let mut ts: hbool_t = 0;
h5call!(H5is_library_threadsafe(&mut ts)).map(|_| ts > 0).unwrap_or(false)
}
#[cfg(not(hdf5_1_8_16))]
{
cfg!(h5_have_threadsafe)
}
}

#[cfg(test)]
pub mod tests {
use super::hdf5_version;
use crate::library_version;

#[test]
pub fn test_hdf5_version() {
assert!(hdf5_version() >= (1, 8, 4));
pub fn test_library_version() {
assert!(library_version() >= (1, 8, 4));
}
}

0 comments on commit e7a28a7

Please sign in to comment.