Array lengths should be explicit in fortran interface
@jhp-lanl is already working on this.
Since Feb 14, 2024.
- Dominant language
- C++
- Stars
- 39
- Forks
- 22
- Avg merge
- 10h 22m
- Merged PRs (30d)
- 3
Description
Much (if not all) of the fortran interface currently uses function signatures that look like
integer function fun_f(val, array_vals) result(err)
integer, value, intent(in) :: val
integer, dimension(:), target, intent(inout) :: array_vals
err = fun(val, c_loc(array_vals))
where the dimension of the dummy variable is not explicitly defined. Since all that's passed over the C++ side is the pointer to the array, it is very easy for the array to be under-allocated and go out of bounds.
In particular, if we choose to change the length of array_vals on the C++ side, we have no way of alerting the Fortran host codes that the length has changed and they need to allocate more space.
I think it would be better if our interface dummy arguments use explicit lengths so that fortran can do length checking at compile time. Then the interface will look like
integer function fun_f(val, array_vals) result(err)
integer, value, intent(in) :: val
integer, dimension(4), target, intent(inout) :: array_vals
err = fun(val, c_loc(array_vals))
This will produce a compile-time error if the host code tries to pass an array in that doesn't comply with the API we've defined:
Error: Actual argument contains too few elements for dummy argument 'array_vals' (2/4) at (1)
@dholladay00 this would fix some UB I saw in the xRAGE interface
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.