From ce5da1c9d8501b908adcadfe056bdec927661f04 Mon Sep 17 00:00:00 2001 From: Cyrus Harrison Date: Tue, 20 Jul 2021 11:18:44 -0700 Subject: [PATCH 1/3] fix overread issue in fortran due to bool vs int binding --- src/libs/conduit/fortran/conduit_fortran.F90 | 224 ++++++++++++++++--- 1 file changed, 190 insertions(+), 34 deletions(-) diff --git a/src/libs/conduit/fortran/conduit_fortran.F90 b/src/libs/conduit/fortran/conduit_fortran.F90 index ce57011c4..518945c9c 100644 --- a/src/libs/conduit/fortran/conduit_fortran.F90 +++ b/src/libs/conduit/fortran/conduit_fortran.F90 @@ -174,23 +174,22 @@ end function c_conduit_node_child_by_name !-------------------------------------------------------------------------- !-------------------------------------------------------------------------- - function conduit_node_is_root(cnode) result(res) & + function c_conduit_node_is_root(cnode) result(res) & bind(C, name="conduit_node_is_root") use iso_c_binding implicit none type(C_PTR), value, intent(IN) :: cnode - logical(C_BOOL) :: res - end function conduit_node_is_root - + integer(C_INT) :: res + end function c_conduit_node_is_root - !-------------------------------------------------------------------------- - function conduit_node_is_data_external(cnode) result(res) & - bind(C, name="conduit_node_is_data_external") - use iso_c_binding - implicit none - type(C_PTR), value, intent(IN) :: cnode - logical(C_BOOL) :: res - end function conduit_node_is_data_external + !-------------------------------------------------------------------------- + function c_conduit_node_is_data_external(cnode) result(res) & + bind(C, name="conduit_node_is_data_external") + use iso_c_binding + implicit none + type(C_PTR), value, intent(IN) :: cnode + integer(C_INT) :: res + end function c_conduit_node_is_data_external !-------------------------------------------------------------------------- function conduit_node_parent(cnode) result(res) & @@ -226,7 +225,7 @@ function c_conduit_node_has_child(cnode,name) result(res) & implicit none type(C_PTR), value, intent(IN) :: cnode character(kind=C_CHAR), intent(IN) :: name(*) - logical(C_BOOL) :: res + integer(C_INT) :: res end function c_conduit_node_has_child !-------------------------------------------------------------------------- @@ -282,7 +281,7 @@ function c_conduit_node_has_path(cnode,path) result(res) & implicit none type(C_PTR), value, intent(IN) :: cnode character(kind=C_CHAR), intent(IN) :: path(*) - logical(C_BOOL) :: res + integer(C_INT) :: res end function c_conduit_node_has_path !-------------------------------------------------------------------------- @@ -313,32 +312,32 @@ function conduit_node_total_bytes_compact(cnode) result(res) & end function conduit_node_total_bytes_compact !-------------------------------------------------------------------------- - function conduit_node_is_compact(cnode) result(res) & + function c_conduit_node_is_compact(cnode) result(res) & bind(C, name="conduit_node_is_compact") use iso_c_binding implicit none type(C_PTR), value, intent(IN) :: cnode - logical(C_BOOL) :: res - end function conduit_node_is_compact + integer(C_INT) :: res + end function c_conduit_node_is_compact !-------------------------------------------------------------------------- - function conduit_node_is_contiguous(cnode) result(res) & + function c_conduit_node_is_contiguous(cnode) result(res) & bind(C, name="conduit_node_is_contiguous") use iso_c_binding implicit none type(C_PTR), value, intent(IN) :: cnode - logical(C_BOOL) :: res - end function conduit_node_is_contiguous + integer(C_INT) :: res + end function c_conduit_node_is_contiguous !-------------------------------------------------------------------------- - function conduit_node_contiguous_with_node(cnode,cother) result(res) & + function c_conduit_node_contiguous_with_node(cnode,cother) result(res) & bind(C, name="conduit_node_contiguous_with_node") use iso_c_binding implicit none type(C_PTR), value, intent(IN) :: cnode type(C_PTR), value, intent(IN) :: cother - logical(C_BOOL) :: res - end function conduit_node_contiguous_with_node + integer(C_INT) :: res + end function c_conduit_node_contiguous_with_node !-------------------------------------------------------------------------- subroutine conduit_node_compact_to(cnode,cdest) & @@ -350,7 +349,7 @@ subroutine conduit_node_compact_to(cnode,cdest) & end subroutine conduit_node_compact_to !-------------------------------------------------------------------------- - function conduit_node_diff(cnode,cother,cinfo,epsilon) result(res) & + function c_conduit_node_diff(cnode,cother,cinfo,epsilon) result(res) & bind(C, name="conduit_node_diff") use iso_c_binding implicit none @@ -358,11 +357,11 @@ function conduit_node_diff(cnode,cother,cinfo,epsilon) result(res) & type(C_PTR), value, intent(IN) :: cother type(C_PTR), value, intent(IN) :: cinfo real(8), value, intent(IN) :: epsilon - logical(C_BOOL) :: res - end function conduit_node_diff + integer(C_INT) :: res + end function c_conduit_node_diff !-------------------------------------------------------------------------- - function conduit_node_diff_compatible(cnode,cother,cinfo,epsilon) result(res) & + function c_conduit_node_diff_compatible(cnode,cother,cinfo,epsilon) result(res) & bind(C, name="conduit_node_diff_compatible") use iso_c_binding implicit none @@ -370,18 +369,18 @@ function conduit_node_diff_compatible(cnode,cother,cinfo,epsilon) result(res) & type(C_PTR), value, intent(IN) :: cother type(C_PTR), value, intent(IN) :: cinfo real(8), value, intent(IN) :: epsilon - logical(C_BOOL) :: res - end function conduit_node_diff_compatible + integer(C_INT) :: res + end function c_conduit_node_diff_compatible !-------------------------------------------------------------------------- - function conduit_node_compatible(cnode,cother) result(res) & + function c_conduit_node_compatible(cnode,cother) result(res) & bind(C, name="conduit_node_compatible") use iso_c_binding implicit none type(C_PTR), value, intent(IN) :: cnode type(C_PTR), value, intent(IN) :: cother - logical(C_BOOL) :: res - end function conduit_node_compatible + integer(C_INT) :: res + end function c_conduit_node_compatible !-------------------------------------------------------------------------- subroutine conduit_node_info(cnode,cdest) & @@ -1163,6 +1162,149 @@ end function conduit_node_as_double contains ! !------------------------------------------------------------------------------ + !-------------------------------------------------------------------------- + function conduit_node_is_root(cnode) result(res) + use iso_c_binding + implicit none + type(C_PTR), value, intent(IN) :: cnode + logical(C_BOOL) :: res + !-- c interface returns an int, we convert to logical here + integer(C_INT) :: c_res + !--- + c_res = c_conduit_node_is_root(cnode) + if (c_res .EQ. 1) then + res = .true. + else + res = .false. + endif + end function conduit_node_is_root + + !-------------------------------------------------------------------------- + function conduit_node_is_data_external(cnode) result(res) + use iso_c_binding + implicit none + type(C_PTR), value, intent(IN) :: cnode + logical(C_BOOL) :: res + !-- c interface returns an int, we convert to logical here + integer(C_INT) :: c_res + !--- + c_res = c_conduit_node_is_data_external(cnode) + if (c_res .EQ. 1) then + res = .true. + else + res = .false. + endif + end function conduit_node_is_data_external + + !-------------------------------------------------------------------------- + function conduit_node_is_compact(cnode) result(res) + use iso_c_binding + implicit none + type(C_PTR), value, intent(IN) :: cnode + logical(C_BOOL) :: res + !-- c interface returns an int, we convert to logical here + integer(C_INT) :: c_res + !--- + c_res = c_conduit_node_is_compact(cnode) + if (c_res .EQ. 1) then + res = .true. + else + res = .false. + endif + end function conduit_node_is_compact + + !-------------------------------------------------------------------------- + function conduit_node_is_contiguous(cnode) result(res) + use iso_c_binding + implicit none + type(C_PTR), value, intent(IN) :: cnode + logical(C_BOOL) :: res + !-- c interface returns an int, we convert to logical here + integer(C_INT) :: c_res + !--- + c_res = c_conduit_node_is_contiguous(cnode) + if (c_res .EQ. 1) then + res = .true. + else + res = .false. + endif + end function conduit_node_is_contiguous + + !-------------------------------------------------------------------------- + function conduit_node_contiguous_with_node(cnode,cother) result(res) + use iso_c_binding + implicit none + type(C_PTR), value, intent(IN) :: cnode + type(C_PTR), value, intent(IN) :: cother + logical(C_BOOL) :: res + !-- c interface returns an int, we convert to logical here + integer(C_INT) :: c_res + !--- + c_res = c_conduit_node_contiguous_with_node(cnode,cother) + if (c_res .EQ. 1) then + res = .true. + else + res = .false. + endif + end function conduit_node_contiguous_with_node + + !-------------------------------------------------------------------------- + function conduit_node_diff(cnode,cother,cinfo,epsilon) result(res) + use iso_c_binding + implicit none + type(C_PTR), value, intent(IN) :: cnode + type(C_PTR), value, intent(IN) :: cother + type(C_PTR), value, intent(IN) :: cinfo + real(8), value, intent(IN) :: epsilon + logical(C_BOOL) :: res + !-- c interface returns an int, we convert to logical here + integer(C_INT) :: c_res + !--- + c_res = c_conduit_node_diff(cnode,cother,cinfo,epsilon) + if (c_res .EQ. 1) then + res = .true. + else + res = .false. + endif + end function conduit_node_diff + + !-------------------------------------------------------------------------- + function conduit_node_diff_compatible(cnode,cother,cinfo,epsilon) result(res) + use iso_c_binding + implicit none + type(C_PTR), value, intent(IN) :: cnode + type(C_PTR), value, intent(IN) :: cother + type(C_PTR), value, intent(IN) :: cinfo + real(8), value, intent(IN) :: epsilon + logical(C_BOOL) :: res + !-- c interface returns an int, we convert to logical here + integer(C_INT) :: c_res + !--- + c_res = c_conduit_node_diff_compatible(cnode,cother,cinfo,epsilon) + if (c_res .EQ. 1) then + res = .true. + else + res = .false. + endif + end function conduit_node_diff_compatible + + !-------------------------------------------------------------------------- + function conduit_node_compatible(cnode,cother) result(res) + use iso_c_binding + implicit none + type(C_PTR), value, intent(IN) :: cnode + type(C_PTR), value, intent(IN) :: cother + logical(C_BOOL) :: res + !-- c interface returns an int, we convert to logical here + integer(C_INT) :: c_res + !--- + c_res = c_conduit_node_compatible(cnode,cother) + if (c_res .EQ. 1) then + res = .true. + else + res = .false. + endif + end function conduit_node_compatible !-------------------------------------------------------------------------- function conduit_node_fetch(cnode, path) result(res) @@ -1193,8 +1335,15 @@ function conduit_node_has_child(cnode, name) result(res) type(C_PTR), value, intent(IN) :: cnode character(*), intent(IN) :: name logical(C_BOOL) :: res + !-- c interface returns an int, we convert to logical here + integer(C_INT) :: c_res !--- - res = c_conduit_node_has_child(cnode, trim(name) // C_NULL_CHAR) + c_res = c_conduit_node_has_child(cnode, trim(name) // C_NULL_CHAR) + if (c_res .EQ. 1) then + res = .true. + else + res = .false. + endif end function conduit_node_has_child !-------------------------------------------------------------------------- @@ -1290,8 +1439,15 @@ function conduit_node_has_path(cnode, path) result(res) type(C_PTR), value, intent(IN) :: cnode character(*), intent(IN) :: path logical(C_BOOL) :: res + !-- c interface returns an int, we convert to logical here + integer(C_INT) :: c_res !--- - res = c_conduit_node_has_path(cnode, trim(path) // C_NULL_CHAR) + c_res = c_conduit_node_has_path(cnode, trim(path) // C_NULL_CHAR) + if (c_res .EQ. 1) then + res = .true. + else + res = .false. + endif end function conduit_node_has_path !-------------------------------------------------------------------------- From 35afdd715bfe5555e3a9268ec2f10e6d95b45549 Mon Sep 17 00:00:00 2001 From: Cyrus Harrison Date: Tue, 20 Jul 2021 11:22:02 -0700 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c089809d..07732837e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s #### General - Fixed missing implementation of DataType::is_index_t - Fixed issue with compiling t_h5z_zfp_smoke.cpp against an MPI-enabled HDF5. +- Fixed overread issue with Fortran API due to int vs bool binding error. Fortran API still provides logical returns for methods like conduit_node_has_path() however the binding implementation now properly translates C_INT return codes into logical values. #### Blueprint - Fixed a bug that caused HDF5 reference paths to appear twice in Relay HDF5 Error messages. From 567d230f91106b13fccec3a8473e1e971e380f7d Mon Sep 17 00:00:00 2001 From: Cyrus Harrison Date: Tue, 20 Jul 2021 11:28:48 -0700 Subject: [PATCH 3/3] move changelog entry to correct place --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07732837e..e0867c9be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,14 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s #### General - Avoid compile issue with using `_Pragma()` with Python 3.8 on Windows - `conduit_node` and `conduit_datatype` in the C API are no longer aliases to `void` so that callers cannot pass just any pointer to the APIs. +- Fixed overread issue with Fortran API due to int vs bool binding error. Fortran API still provides logical returns for methods like conduit_node_has_path() however the binding implementation now properly translates C_INT return codes into logical values. #### Blueprint - Added the `blueprint::mesh::examples::polychain` example. It is an example of a polyhedral mesh. See Mesh Blueprint Examples docs (https://llnl-conduit.readthedocs.io/en/latest/blueprint_mesh.html#polychain) for more details. - Fixed a bug that was causing the `conduit::blueprint::mesh::topology::unstructured::generate_*` functions to produce bad results for polyhedral input topologies with heterogeneous elements (e.g. tets and hexs). - Added a new function signature for `blueprint::mesh::topology::unstructured::generated_sides`, which performs the same task as the original and also takes fields from the original topology and maps them onto the new topology. + ## [0.7.2] - Released 2021-05-19 ### Added @@ -48,7 +50,6 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s #### General - Fixed missing implementation of DataType::is_index_t - Fixed issue with compiling t_h5z_zfp_smoke.cpp against an MPI-enabled HDF5. -- Fixed overread issue with Fortran API due to int vs bool binding error. Fortran API still provides logical returns for methods like conduit_node_has_path() however the binding implementation now properly translates C_INT return codes into logical values. #### Blueprint - Fixed a bug that caused HDF5 reference paths to appear twice in Relay HDF5 Error messages.