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

h5fget_name_f: No way to obtain filename length from Fortran #824

Closed
jhaiduce opened this issue Jul 6, 2021 · 5 comments
Closed

h5fget_name_f: No way to obtain filename length from Fortran #824

jhaiduce opened this issue Jul 6, 2021 · 5 comments
Assignees
Labels
Component - Fortran Fortran wrappers Priority - 1. High 🔼 These are important issues that should be resolved in the next release Type - Bug / Bugfix Please report security issues to [email protected] instead of creating an issue on GitHub

Comments

@jhaiduce
Copy link

jhaiduce commented Jul 6, 2021

The documentation of h5fget_name says: "If the length of the name, which determines the required value of size, is unknown, a preliminary H5Fget_name call can be made by setting name to NULL. The return value of this call will be the size of the filename; that value plus one (1) can then be assigned to size for a second H5Fget_name call, which will retrieve the actual name. "

However, this does not work from Fortran. Passing a null (unassociated in Fortran parlance) pointer to an ordinary (non-pointer, non allocatable) dummy argument is not allowed in the Fortran standard. If one tries to do so anyway, the current implementation does not obtain the size as expected, because h5fget_name_c allocates a new buffer for the filename anyway. As a result, there is no way to obtain the length of the filename using the Fortran API.

@brtnfld
Copy link
Contributor

brtnfld commented Jan 7, 2022

Currently, you need to pass a valid character string for "buf", but it can be a length of 1 if you like. The "size" returned will be the needed length.

@jhaiduce
Copy link
Author

jhaiduce commented Jan 7, 2022

Just tried that. I get the correct length with a zero-length string as well.

So it seems that the implementation is working, the problem is just an omission in the documentation.

@jhaiduce
Copy link
Author

jhaiduce commented Jan 7, 2022

I submitted a pull request that adds a sentence to H5Fget_name.htm in the documentation to explain this.

@brtnfld
Copy link
Contributor

brtnfld commented Jan 8, 2022

I found a bug with H5Fget_name_f when looking into using an allocatable character string. If the buffer is the exact size needed, then the filename returned will be truncated by one character. See PR #1345 for the fix.

@brtnfld brtnfld self-assigned this Jan 8, 2022
@derobins derobins added Priority - 1. High 🔼 These are important issues that should be resolved in the next release Component - Fortran Fortran wrappers Type - Bug / Bugfix Please report security issues to [email protected] instead of creating an issue on GitHub labels May 4, 2023
@brtnfld
Copy link
Contributor

brtnfld commented Apr 4, 2024

Everything related to this issue has been resolved, so I will close it. Thanks for your help!

@brtnfld brtnfld closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Fortran Fortran wrappers Priority - 1. High 🔼 These are important issues that should be resolved in the next release Type - Bug / Bugfix Please report security issues to [email protected] instead of creating an issue on GitHub
Projects
None yet
Development

No branches or pull requests

3 participants