Skip to content
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

allow reading dimensions from md groups #291

Merged
merged 11 commits into from
Sep 2, 2022
Merged

Conversation

ChristianBeilschmidt
Copy link
Contributor

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

Added the wrapper for the dimension call for md groups.

@@ -413,7 +424,7 @@ impl<'a> Group<'a> {
}
}

pub fn open_group(&self, name: &str, options: CslStringList) -> Result<Group> {
pub fn open_group(&'_ self, name: &str, options: CslStringList) -> Result<Group<'a>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit groggy right now, does self here have a different lifetime from the resulting Group?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I prevented Group from having the lifetime of self. It needs the lifetime of the dataset.
I tested that in the changed test where I dropped a super-group.

@@ -440,13 +451,45 @@ impl<'a> Group<'a> {
Ok(Attribute::from_c_attribute(c_attribute))
}
}

pub fn dimensions(&self, options: CslStringList) -> Result<Vec<Dimension>> {
unsafe {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to make this unsafe block smaller :-).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let mut num_dimensions: usize = 0;
let c_dimensions = GDALGroupGetDimensions(
self.c_group,
std::ptr::addr_of_mut!(num_dimensions),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not necessarily against it, but I'd expect to see addr_of_mut! used with uninitialized variables, so it's a bit confusing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// `num_dimensions` is `0`, we can safely return an empty vector
// `GDALMDArrayGetDimensions` does not state that errors can occur
if num_dimensions > 0 && c_dimensions.is_null() {
return Err(_last_null_pointer_err("GDALGroupGetDimensions"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

Suggested change
return Err(_last_null_pointer_err("GDALGroupGetDimensions"));
return Err(_last_null_pointer_err("GDALMDArrayGetDimensions"));

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdroenner
Copy link
Member

can you resolve the conflicts?

@jdroenner
Copy link
Member

i think this PR is good to merge. @lnicola would that be okay for you? Or are there open issues?

@lnicola
Copy link
Member

lnicola commented Sep 2, 2022

bors r=jdroenner,lnicola

@bors
Copy link
Contributor

bors bot commented Sep 2, 2022

Build succeeded:

@bors bors bot merged commit 2a29d92 into master Sep 2, 2022
@ChristianBeilschmidt ChristianBeilschmidt deleted the gdal-md-group-dimensions branch September 2, 2022 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants