Skip to content

Use H5Pisa_class to circumvent bug #219

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

Merged
merged 2 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
with feature `have-parallel` instead of `have-direct`.
- Fixed a missing symbol when building `hdf5-src` with `libz-sys`.
- Fixed a bug where errors were only silenced on the main thread.
- Fixed a memory leak when opening datasets.

## 0.8.1

Expand Down
31 changes: 29 additions & 2 deletions src/hl/plist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::ptr::{self, addr_of_mut};
use std::str::FromStr;

use hdf5_sys::h5p::{
H5Pcopy, H5Pequal, H5Pexist, H5Pget_class, H5Pget_class_name, H5Pget_nprops, H5Piterate,
H5Pset_vlen_mem_manager,
H5Pcopy, H5Pequal, H5Pexist, H5Pget_class, H5Pget_class_name, H5Pget_nprops, H5Pisa_class,
H5Piterate, H5Pset_vlen_mem_manager,
};

use crate::internal_prelude::*;
Expand Down Expand Up @@ -208,6 +208,33 @@ impl PropertyList {
PropertyListClass::from_str(&name)
})
}

pub fn is_class(&self, class: PropertyListClass) -> bool {
use crate::globals::*;
h5lock!({
let class = match class {
PropertyListClass::FileCreate => *H5P_FILE_CREATE,
PropertyListClass::AttributeCreate => *H5P_ATTRIBUTE_CREATE,
PropertyListClass::DatasetAccess => *H5P_DATASET_ACCESS,
PropertyListClass::DatasetCreate => *H5P_DATASET_CREATE,
PropertyListClass::DataTransfer => *H5P_DATASET_XFER,
PropertyListClass::DatatypeAccess => *H5P_DATATYPE_ACCESS,
PropertyListClass::DatatypeCreate => *H5P_DATATYPE_CREATE,
PropertyListClass::FileAccess => *H5P_FILE_ACCESS,
PropertyListClass::FileMount => *H5P_FILE_MOUNT,
PropertyListClass::GroupAccess => *H5P_GROUP_ACCESS,
PropertyListClass::GroupCreate => *H5P_GROUP_CREATE,
PropertyListClass::LinkAccess => *H5P_LINK_ACCESS,
PropertyListClass::LinkCreate => *H5P_LINK_CREATE,
PropertyListClass::ObjectCopy => *H5P_OBJECT_COPY,
PropertyListClass::ObjectCreate => *H5P_OBJECT_CREATE,
PropertyListClass::StringCreate => *H5P_STRING_CREATE,
};
let tri = H5Pisa_class(self.id(), class);

tri == 1
})
}
}

/// Set the memory manager for variable length items to
Expand Down
9 changes: 5 additions & 4 deletions src/hl/plist/dataset_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ impl ObjectClass for DatasetAccess {
}

fn validate(&self) -> Result<()> {
let class = self.class()?;
if class != PropertyListClass::DatasetAccess {
fail!("expected dataset access property list, got {:?}", class);
}
ensure!(
self.is_class(PropertyListClass::DatasetAccess),
"expected dataset access property list, got {:?}",
self.class()
);
Ok(())
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/hl/plist/dataset_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ impl ObjectClass for DatasetCreate {
}

fn validate(&self) -> Result<()> {
let class = self.class()?;
if class != PropertyListClass::DatasetCreate {
fail!("expected dataset creation property list, got {:?}", class);
}
ensure!(
self.is_class(PropertyListClass::DatasetCreate),
"expected dataset creation property list, got {:?}",
self.class()
);
Ok(())
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/hl/plist/file_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ impl ObjectClass for FileAccess {
}

fn validate(&self) -> Result<()> {
let class = self.class()?;
if class != PropertyListClass::FileAccess {
fail!("expected file access property list, got {:?}", class);
}
ensure!(
self.is_class(PropertyListClass::FileAccess),
"expected file access property list, got {:?}",
self.class()
);
Ok(())
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/hl/plist/file_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ impl ObjectClass for FileCreate {
}

fn validate(&self) -> Result<()> {
let class = self.class()?;
if class != PropertyListClass::FileCreate {
fail!("expected file create property list, got {:?}", class);
}
ensure!(
self.is_class(PropertyListClass::FileCreate),
"expected file create property list, got {:?}",
self.class()
);
Ok(())
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/hl/plist/link_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ impl ObjectClass for LinkCreate {
}

fn validate(&self) -> Result<()> {
let class = self.class()?;
if class != PropertyListClass::LinkCreate {
fail!("expected link create property list, got {:?}", class);
}
ensure!(
self.is_class(PropertyListClass::LinkCreate),
"expected link create property list, got {:?}",
self.class()
);
Ok(())
}
}
Expand Down