Skip to content

Commit 840dbe8

Browse files
committed
fix: Gate ObjectReference2 on v1.12.1
There appear to be bugs in the v1.12.0 version which certainly break ObjectReference2 is an element in compound type. Other bugs were seen previously as well so this appears to be a more stable option.
1 parent 43351b9 commit 840dbe8

File tree

4 files changed

+34
-42
lines changed

4 files changed

+34
-42
lines changed

hdf5/src/hl/references/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use crate::Location;
33

44
mod legacy;
55

6-
#[cfg(feature = "1.12.0")]
6+
#[cfg(feature = "1.12.1")]
77
mod standard;
88

99
use hdf5_sys::h5o::H5O_type_t;
1010
use hdf5_sys::h5r::H5R_type_t;
1111

1212
pub use legacy::ObjectReference1;
13-
#[cfg(feature = "1.12.0")]
13+
#[cfg(feature = "1.12.1")]
1414
pub use standard::ObjectReference2;
1515

1616
pub trait ObjectReference: Sized + H5Type {

hdf5/src/hl/references/standard.rs

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use std::ops::Deref;
2-
1+
//! New standard reference types introduced in v1.12.0.
2+
//!
3+
//! These are gated on v1.12.1 since there appear to be multiple bugs in v1.12.0.
4+
//!
35
use hdf5_sys::h5o::H5O_type_t;
46
use hdf5_sys::h5r::H5R_type_t::H5R_OBJECT2;
57
use hdf5_sys::h5r::{H5R_ref_t, H5Rcreate_object, H5Rdestroy, H5Rget_obj_type3, H5Ropen_object};
@@ -10,28 +12,37 @@ use crate::Location;
1012

1113
/// A reference to a HDF5 item that can be stored in attributes or datasets.
1214
#[repr(transparent)]
13-
pub struct StdReference {
14-
inner: H5R_ref_t,
15-
}
15+
pub struct StdReference(H5R_ref_t);
1616

1717
impl StdReference {
1818
fn ptr(&self) -> *const H5R_ref_t {
19-
std::ptr::addr_of!(self.inner)
19+
std::ptr::addr_of!(self.0)
2020
}
2121
}
2222

23-
#[repr(transparent)]
24-
#[derive(Debug)]
25-
pub struct ObjectReference2(StdReference);
23+
//todo: could we query some actual object parameters to make this more useful?
24+
impl std::fmt::Debug for StdReference {
25+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26+
f.write_str("StdReference")
27+
}
28+
}
2629

27-
impl Deref for ObjectReference2 {
28-
type Target = StdReference;
30+
unsafe impl H5Type for StdReference {
31+
fn type_descriptor() -> hdf5_types::TypeDescriptor {
32+
hdf5_types::TypeDescriptor::Reference(hdf5_types::Reference::Std)
33+
}
34+
}
2935

30-
fn deref(&self) -> &Self::Target {
31-
&self.0
36+
impl Drop for StdReference {
37+
fn drop(&mut self) {
38+
let _e = h5call!(H5Rdestroy(&mut self.0));
3239
}
3340
}
3441

42+
#[repr(transparent)]
43+
#[derive(Debug)]
44+
pub struct ObjectReference2(StdReference);
45+
3546
impl ObjectReference for ObjectReference2 {
3647
const REF_TYPE: hdf5_sys::h5r::H5R_type_t = H5R_OBJECT2;
3748

@@ -41,7 +52,7 @@ impl ObjectReference for ObjectReference2 {
4152

4253
fn create(location: &Location, name: &str) -> Result<Self> {
4354
let reference: H5R_ref_t = create_object_reference(location, name)?;
44-
Ok(Self(StdReference { inner: reference }))
55+
Ok(Self(StdReference(reference)))
4556
}
4657

4758
fn get_object_type(&self, _location: &Location) -> Result<hdf5_sys::h5o::H5O_type_t> {
@@ -64,25 +75,6 @@ unsafe impl H5Type for ObjectReference2 {
6475
}
6576
}
6677

67-
//todo: could we query some actual object parameters to make this more useful?
68-
impl std::fmt::Debug for StdReference {
69-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70-
f.write_str("StdReference")
71-
}
72-
}
73-
74-
unsafe impl H5Type for StdReference {
75-
fn type_descriptor() -> hdf5_types::TypeDescriptor {
76-
hdf5_types::TypeDescriptor::Reference(hdf5_types::Reference::Std)
77-
}
78-
}
79-
80-
impl Drop for StdReference {
81-
fn drop(&mut self) {
82-
let _e = h5call!(H5Rdestroy(&mut self.inner));
83-
}
84-
}
85-
8678
fn create_object_reference(dataset: &Location, name: &str) -> Result<H5R_ref_t> {
8779
let mut out: std::mem::MaybeUninit<H5R_ref_t> = std::mem::MaybeUninit::uninit();
8880
let name = to_cstring(name)?;

hdf5/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ mod export {
6767
},
6868
};
6969

70-
#[cfg(feature = "1.12.0")]
70+
#[cfg(feature = "1.12.1")]
7171
pub use crate::hl::references::ObjectReference2;
7272

7373
#[doc(hidden)]

hdf5/tests/test_object_references.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
mod common;
55

66
use common::util::new_in_memory_file;
7-
#[cfg(feature = "1.12.0")]
7+
#[cfg(feature = "1.12.1")]
88
use hdf5::ObjectReference2;
99
use hdf5::{H5Type, ObjectReference, ObjectReference1, ReferencedObject};
1010

@@ -217,30 +217,30 @@ fn test_reference_in_datatype_object_reference1() {
217217
test_reference_in_datatype::<ObjectReference1>();
218218
}
219219

220-
#[cfg(feature = "1.12.0")]
220+
#[cfg(feature = "1.12.1")]
221221
#[test]
222222
fn test_group_references_with_objectreference2() {
223223
test_group_references::<ObjectReference2>();
224224
}
225225

226-
#[cfg(feature = "1.12.0")]
226+
#[cfg(feature = "1.12.1")]
227227
#[test]
228228
fn test_dataset_references_with_object_reference2() {
229229
test_dataset_references::<ObjectReference2>();
230230
}
231-
#[cfg(feature = "1.12.0")]
231+
#[cfg(feature = "1.12.1")]
232232
#[test]
233233
fn test_reference_in_attribute_object_reference2() {
234234
test_reference_in_attribute::<ObjectReference2>();
235235
}
236236

237-
#[cfg(feature = "1.12.0")]
237+
#[cfg(feature = "1.12.1")]
238238
#[test]
239239
fn test_reference_errors_on_attribute_object_reference2() {
240240
test_reference_errors_on_attribute::<ObjectReference2>();
241241
}
242242

243-
#[cfg(feature = "1.12.0")]
243+
#[cfg(feature = "1.12.1")]
244244
#[test]
245245
fn test_reference_in_datatype_object_reference2() {
246246
test_reference_in_datatype::<ObjectReference2>();

0 commit comments

Comments
 (0)