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

Fix issue with invalid compound conversions performing no-op I/O #4166

Closed

Conversation

jhendersonHDF
Copy link
Collaborator

No description provided.

@jhendersonHDF jhendersonHDF added Merge - To 1.14 Priority - 3. Low 🔽 Code cleanup, small feature change requests, etc. Component - C Library Core C library issues (usually in the src directory) Component - Testing Code in test or testpar directories, GitHub workflows Type - Bug / Bugfix Please report security issues to [email protected] instead of creating an issue on GitHub labels Mar 17, 2024
hid_t compound_i32 = H5I_INVALID_HID;
#endif
#if H5_SIZEOF_INT64_T != 0
hid_t compound_i64 = H5I_INVALID_HID;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed size types are used here just to make sure that the optimizations in struct conversions around smaller or larger destination types don't potentially break this in the future

@jhendersonHDF jhendersonHDF force-pushed the compound_conv_empty_subset branch from e615fbe to 5548a16 Compare March 17, 2024 01:02

TESTING("compound conversions where destination compound has no members from source compound");

#if H5_SIZEOF_INT32_T != 0
Copy link
Member

Choose a reason for hiding this comment

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

Why the ifdefs on type sizes? We demand C99 types and use them elsewhere in the library without protection.

Copy link
Collaborator Author

@jhendersonHDF jhendersonHDF Mar 17, 2024

Choose a reason for hiding this comment

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

int8_t, 16, 32 and 64 are optional in C99, though I suspect they're fairly widely supported. It could be a problem on some systems though; this is just being cautious about it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The least and fast variants are guaranteed in C99 for 8, 16, 32, and 64, but the exact width types aren't.

Copy link
Member

Choose a reason for hiding this comment

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

We use int32_t, etc. throughout the library. A hid_t ID is defined to be an int64_t. It's basically a requirement to build, or even use, HDF5. There's no need for the ifdefs here.

Copy link
Collaborator Author

@jhendersonHDF jhendersonHDF Mar 19, 2024

Choose a reason for hiding this comment

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

Just because int64_t is defined doesn't guarantee that int16_t is, for example. I can remove the ifdefs if we think it's just visual noise, but something to think about. If those are requirements for the library, it may not be a bad idea to throw an error at configure time if one of the types we use directly is missing (if we don't already have that).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think int16_t is as well-established as int32_t and int64_t at this point.

@fortnern
Copy link
Member

Why is this considered an error? Is there an associated issue? I'd argue that the library is doing exactly what was asked of it.

@jhendersonHDF
Copy link
Collaborator Author

jhendersonHDF commented Mar 19, 2024

Why is this considered an error? Is there an associated issue? I'd argue that the library is doing exactly what was asked of it.

To me this seems like surprising behavior. While I agree the library is basically just doing what it's told, in my opinion it seems like this case would more often than not be user error that would be better to error on. I'm thinking of the case where a user may want to convert between two compounds of slightly different member types during write, say float->float16, but accidentally messed up the member name in the source compound slightly and is surprised when the dataset has fill data.

It's definitely arguing semantics, but I'm not sure if we document anywhere what the expected behavior should be. I picked a behavior here, but am also fine with leaving the behavior as is, as long as we document it (or make that more prominent if we already have).

@qkoziol
Copy link
Contributor

qkoziol commented Mar 19, 2024

There's definitely good arguments for both sides here. To Neil's point: we don't throw an error when an application ends up with a selection of 0 elements and performs I/O on it. On the other hand, it is easy to misspell a field name.

@qkoziol
Copy link
Contributor

qkoziol commented Mar 19, 2024

Perhaps we could have a query-only property that provided the number of elements accessed for an I/O operation?

@jhendersonHDF jhendersonHDF marked this pull request as draft March 20, 2024 16:03
@jhendersonHDF
Copy link
Collaborator Author

Closing as it was decided that this should be the expected behavior and should be documented. This may be revisited in the future if we add a method for telling the library to check for possibly unexpected circumstances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - C Library Core C library issues (usually in the src directory) Component - Testing Code in test or testpar directories, GitHub workflows Priority - 3. Low 🔽 Code cleanup, small feature change requests, etc. Type - Bug / Bugfix Please report security issues to [email protected] instead of creating an issue on GitHub
Projects
Status: Merges Complete
Development

Successfully merging this pull request may close these issues.

5 participants