From ae1ac799528303d15c602e8e50edb3a7664c0eff Mon Sep 17 00:00:00 2001 From: Gerhard Theurich Date: Thu, 30 May 2024 12:11:08 -0700 Subject: [PATCH] Clean-up portable ABI support implementation for https://github.com/esmf-org/esmf/issues/254 --- src/Infrastructure/Util/include/ESMCI_Util.h | 2 +- src/Infrastructure/Util/include/ESMC_Util.h | 9 ++------- src/Infrastructure/Util/src/ESMCI_Util.C | 2 +- .../Util/src/ESMF_FortranWordsize.cppF90 | 13 +++++++------ src/Infrastructure/Util/src/ESMF_UtilTypes.F90 | 8 -------- 5 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/Infrastructure/Util/include/ESMCI_Util.h b/src/Infrastructure/Util/include/ESMCI_Util.h index 995bc9b5cc..d97d5a1128 100644 --- a/src/Infrastructure/Util/include/ESMCI_Util.h +++ b/src/Infrastructure/Util/include/ESMCI_Util.h @@ -195,7 +195,7 @@ const char *ESMC_LogicalString(ESMC_Logical tf); extern "C" { void FTN_X(esmf_pointertoint)(int *n, short *s, ESMC_POINTER *len); -void FTN_X(esmf_pointerdifference)(long *n, short *s1, short *s2, int *len); +void FTN_X(esmf_pointerdifference)(size_t *n, short *s1, short *s2, int *len); void FTN_X(c_esmc_getcwd)(char *pathname, int *rc, ESMCI_FortranStrLenArg pathname_l); void FTN_X(c_esmc_makedirectory)(const char *pathname, int *mode, ESMC_Logical *relaxedFlag, int *rc, ESMCI_FortranStrLenArg pathname_l); diff --git a/src/Infrastructure/Util/include/ESMC_Util.h b/src/Infrastructure/Util/include/ESMC_Util.h index 48f97282f3..400eb99d5d 100644 --- a/src/Infrastructure/Util/include/ESMC_Util.h +++ b/src/Infrastructure/Util/include/ESMC_Util.h @@ -21,6 +21,7 @@ #define ESMC_UTIL_H #include "ESMC_Conf.h" +#include #ifdef __cplusplus extern "C" { @@ -40,13 +41,7 @@ extern "C" { typedef char ESMC_I1; typedef double ESMC_R8; typedef float ESMC_R4; -#if (ESMC_POINTER_SIZE == 4) - // 32-bit machine - typedef unsigned long ESMC_POINTER; -#else - // 64-bit machine - typedef unsigned long long ESMC_POINTER; -#endif + typedef size_t ESMC_POINTER; enum ESMC_CoordSys_Flag {ESMC_COORDSYS_INVALID=-2, ESMC_COORDSYS_UNINIT, diff --git a/src/Infrastructure/Util/src/ESMCI_Util.C b/src/Infrastructure/Util/src/ESMCI_Util.C index e2f54f58ac..72039c1fb2 100644 --- a/src/Infrastructure/Util/src/ESMCI_Util.C +++ b/src/Infrastructure/Util/src/ESMCI_Util.C @@ -716,7 +716,7 @@ extern "C" { // 2 ^ 32 apart so the result fits in to a standard integer return val. // // !ARGUMENTS: - long *n, // in - number of expected bytes in a pointer + size_t *n, // in - number of expected bytes in a pointer short *s1, // in - F90 pointer of some kind short *s2, // in - F90 pointer of some kind int *len) { // out - that same value cast to an int diff --git a/src/Infrastructure/Util/src/ESMF_FortranWordsize.cppF90 b/src/Infrastructure/Util/src/ESMF_FortranWordsize.cppF90 index 9d77d976ea..ea9093956a 100644 --- a/src/Infrastructure/Util/src/ESMF_FortranWordsize.cppF90 +++ b/src/Infrastructure/Util/src/ESMF_FortranWordsize.cppF90 @@ -30,7 +30,7 @@ module ESMF_FortranWordsizeMod ! !USES: use iso_c_binding - use ESMF_UtilTypesMod + use ESMF_UtilTypesMod use ESMF_LogErrMod implicit none @@ -71,12 +71,13 @@ module ESMF_FortranWordsizeMod ^ifndef ESMF_NO_F2018ASSUMEDTYPE interface - + subroutine esmf_pointerdifference(n, s1, s2, len) - integer*8 :: n - type(*) :: s1 - type(*) :: s2 - integer :: len + use iso_c_binding + integer(C_SIZE_T) :: n + type(*) :: s1 + type(*) :: s2 + integer :: len end subroutine !EOPI diff --git a/src/Infrastructure/Util/src/ESMF_UtilTypes.F90 b/src/Infrastructure/Util/src/ESMF_UtilTypes.F90 index e0151b66e1..c9644956bd 100644 --- a/src/Infrastructure/Util/src/ESMF_UtilTypes.F90 +++ b/src/Infrastructure/Util/src/ESMF_UtilTypes.F90 @@ -164,15 +164,7 @@ module ESMF_UtilTypesMod sequence #endif !private -#if 1 integer(C_SIZE_T) :: ptr -#else -#if (ESMC_POINTER_SIZE == 4) - integer(selected_int_kind( 9)) :: ptr -#else - integer(selected_int_kind(18)) :: ptr -#endif -#endif end type type(ESMF_Pointer), parameter :: ESMF_NULL_POINTER = ESMF_Pointer(0), &