From c151560b55862c00ea630bc0f17f52524d92d2ac Mon Sep 17 00:00:00 2001 From: Gerhard Theurich Date: Tue, 4 Jun 2024 18:00:08 -0700 Subject: [PATCH] Ensure ESMF_KIND_I8 is consistently treated as 64-bit (long long int), regardless of ABI. --- .../jinja2_templating/generate_templates.py | 4 ++-- .../Base/interface/ESMF_InfoCDefGeneric.F90 | 10 +++++----- src/Infrastructure/Base/src/ESMCI_Info.C | 8 ++++---- .../Base/src/ESMC_InfoCDefGeneric.C | 18 +++++++++--------- .../Base/tests/ESMCI_InfoUTest.C | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/jinja2_templating/generate_templates.py b/scripts/jinja2_templating/generate_templates.py index 4feb3e0d73..baca598e73 100644 --- a/scripts/jinja2_templating/generate_templates.py +++ b/scripts/jinja2_templating/generate_templates.py @@ -16,7 +16,7 @@ F = 'float' D = 'double' I = 'int' -L = 'long int' +L = 'long long int' ST = 'std::string' B = 'bool' A = 'ESMCI::Info' @@ -41,7 +41,7 @@ 'ftype': 'integer', 'ctype': I, 'full_ftype': 'integer(ESMF_KIND_I4)'}, - L: {'iso_ctype': 'C_LONG', + L: {'iso_ctype': 'C_LONG_LONG', 'esmf_type': 'ESMF_KIND_I8', 'json_type': 'number_integer_t', 'esmf_suffix': 'I8', diff --git a/src/Infrastructure/Base/interface/ESMF_InfoCDefGeneric.F90 b/src/Infrastructure/Base/interface/ESMF_InfoCDefGeneric.F90 index ab15ea629b..d706c18070 100644 --- a/src/Infrastructure/Base/interface/ESMF_InfoCDefGeneric.F90 +++ b/src/Infrastructure/Base/interface/ESMF_InfoCDefGeneric.F90 @@ -62,7 +62,7 @@ subroutine c_info_get_I8(info, key, value, rc, default, idx, recursive) bind(C, implicit none type(C_PTR), value :: info character(C_CHAR), intent(in) :: key(*) - integer(C_LONG), intent(out) :: value + integer(C_LONG_LONG), intent(out) :: value integer(C_INT), intent(inout) :: rc type(C_PTR), value :: default, idx integer(C_INT), intent(in) :: recursive @@ -123,7 +123,7 @@ subroutine c_info_get_array_I8(info, key, value, itemcount, rc, recursive, local implicit none type(C_PTR), value :: info character(C_CHAR), intent(in) :: key(*) - integer(C_LONG), dimension(*), intent(out) :: value + integer(C_LONG_LONG), dimension(*), intent(out) :: value integer(C_INT), intent(out) :: itemcount integer(C_INT), intent(inout) :: rc integer(C_INT), intent(in) :: recursive @@ -189,7 +189,7 @@ subroutine c_info_set_I8(info, key, value, force, rc, idx, pkey) bind(C, name="E implicit none type(C_PTR), value :: info character(kind=C_CHAR), intent(in) :: key(*) - integer(C_LONG), intent(in) :: value + integer(C_LONG_LONG), intent(in) :: value logical(C_BOOL), intent(in) :: force integer(C_INT), intent(inout) :: rc type(C_PTR), value :: idx @@ -261,7 +261,7 @@ subroutine c_info_set_array_I8(info, key, value, itemcount, force, rc, pkey) bin implicit none type(C_PTR), value :: info character(kind=C_CHAR), intent(in) :: key(*) - integer(C_LONG), dimension(*), intent(in) :: value + integer(C_LONG_LONG), dimension(*), intent(in) :: value integer(C_INT), intent(in) :: itemcount logical(C_BOOL), intent(in) :: force integer(C_INT), intent(inout) :: rc @@ -280,4 +280,4 @@ subroutine c_info_set_array_LG(info, key, value, itemcount, force, rc, pkey) bin character(kind=C_CHAR), intent(in) :: pkey(*) end subroutine c_info_set_array_LG -end interface +end interface \ No newline at end of file diff --git a/src/Infrastructure/Base/src/ESMCI_Info.C b/src/Infrastructure/Base/src/ESMCI_Info.C index 77706d1e82..8118184848 100644 --- a/src/Infrastructure/Base/src/ESMCI_Info.C +++ b/src/Infrastructure/Base/src/ESMCI_Info.C @@ -727,7 +727,7 @@ void check_overflow(T dst, T2 tocheck) { ESMC_CHECK_RC("ESMC_RC_ARG_BAD", ESMC_RC_ARG_BAD, errmsg) } }; -template void check_overflow(int, long int); +template void check_overflow(int, long long int); template void check_overflow(int, unsigned long int); template void check_overflow(float, double); @@ -839,7 +839,7 @@ T Info::get(key_t &key, const T *def, const int *index, bool recursive, std::str template float Info::get(key_t&, const float*, const int*, bool, std::string*, bool) const; template double Info::get(key_t&, const double*, const int*, bool, std::string*, bool) const; template int Info::get(key_t&, const int*, const int*, bool, std::string*, bool) const; -template long int Info::get(key_t&, const long int*, const int*, bool, std::string*, bool) const; +template long long int Info::get(key_t&, const long long int*, const int*, bool, std::string*, bool) const; template bool Info::get(key_t&, const bool*, const int*, bool, std::string*, bool) const; template std::string Info::get(key_t&, const std::string*, const int*, bool, std::string*, bool) const; template json Info::get(key_t&, const json*, const int*, bool, std::string*, bool) const; @@ -1388,7 +1388,7 @@ void Info::set(key_t &key, T value, bool force, const int *index, const key_t * template void Info::set(key_t&, float, bool, const int*, const key_t * const); template void Info::set(key_t&, double, bool, const int*, const key_t * const); template void Info::set(key_t&, int, bool, const int*, const key_t * const); -template void Info::set(key_t&, long int, bool, const int*, const key_t * const); +template void Info::set(key_t&, long long int, bool, const int*, const key_t * const); template void Info::set(key_t&, std::string, bool, const int*, const key_t * const); template void Info::set(key_t&, bool, bool, const int*, const key_t * const); @@ -1420,7 +1420,7 @@ void Info::set(key_t &key, T *values, int count, bool force, const key_t * const template void Info::set(key_t&, float*, int, bool, const key_t * const); template void Info::set(key_t&, double*, int, bool, const key_t * const); template void Info::set(key_t&, int*, int, bool, const key_t * const); -template void Info::set(key_t&, long int*, int, bool, const key_t * const); +template void Info::set(key_t&, long long int*, int, bool, const key_t * const); template void Info::set(key_t&, bool*, int, bool, const key_t * const); template void Info::set>(key_t&, std::vector*, int, bool, const key_t * const); diff --git a/src/Infrastructure/Base/src/ESMC_InfoCDefGeneric.C b/src/Infrastructure/Base/src/ESMC_InfoCDefGeneric.C index 64d03d2b47..d8323e5f53 100644 --- a/src/Infrastructure/Base/src/ESMC_InfoCDefGeneric.C +++ b/src/Infrastructure/Base/src/ESMC_InfoCDefGeneric.C @@ -102,13 +102,13 @@ void ESMC_InfoGetI4(ESMCI::Info *info, char *key, int &value, int &esmc_rc, int #undef ESMC_METHOD #define ESMC_METHOD "ESMC_InfoGetI8()" -void ESMC_InfoGetI8(ESMCI::Info *info, char *key, long int &value, int &esmc_rc, long int *def, int *index, int &fortran_bool_recursive) { +void ESMC_InfoGetI8(ESMCI::Info *info, char *key, long long int &value, int &esmc_rc, long long int *def, int *index, int &fortran_bool_recursive) { ESMC_CHECK_INIT(info, esmc_rc) esmc_rc = ESMF_FAILURE; try { std::string local_key(key); bool recursive = fortran_bool_recursive == 1; - value = info->get(local_key, def, index, recursive, nullptr, false); + value = info->get(local_key, def, index, recursive, nullptr, false); esmc_rc = ESMF_SUCCESS; } ESMC_CATCH_ISOC @@ -253,7 +253,7 @@ void ESMC_InfoGetArrayI4(ESMCI::Info *info, char *key, int *value, int &count, i #undef ESMC_METHOD #define ESMC_METHOD "ESMC_InfoGetArrayI8()" -void ESMC_InfoGetArrayI8(ESMCI::Info *info, char *key, long int *value, int &count, int &esmc_rc, int &fortran_bool_recursive, bool &fortran_bool_scalarToArray, int &expected_size) { +void ESMC_InfoGetArrayI8(ESMCI::Info *info, char *key, long long int *value, int &count, int &esmc_rc, int &fortran_bool_recursive, bool &fortran_bool_scalarToArray, int &expected_size) { ESMC_CHECK_INIT(info, esmc_rc) esmc_rc = ESMF_FAILURE; try { @@ -285,7 +285,7 @@ void ESMC_InfoGetArrayI8(ESMCI::Info *info, char *key, long int *value, int &cou ESMC_CATCH_ERRPASSTHRU } } else { - value[0] = info->get(local_key, nullptr, nullptr, recursive, nullptr, false); + value[0] = info->get(local_key, nullptr, nullptr, recursive, nullptr, false); } esmc_rc = ESMF_SUCCESS; } @@ -389,7 +389,7 @@ void ESMC_InfoSetI4(ESMCI::Info *info, char *key, int &value, bool &force, int & #undef ESMC_METHOD #define ESMC_METHOD "ESMC_InfoSetI8()" -void ESMC_InfoSetI8(ESMCI::Info *info, char *key, long int &value, bool &force, int &esmc_rc, int *index, char *pkey) { +void ESMC_InfoSetI8(ESMCI::Info *info, char *key, long long int &value, bool &force, int &esmc_rc, int *index, char *pkey) { ESMC_CHECK_INIT(info, esmc_rc) esmc_rc = ESMF_FAILURE; try { @@ -397,7 +397,7 @@ void ESMC_InfoSetI8(ESMCI::Info *info, char *key, long int &value, bool &force, std::string local_pkey(pkey); std::string *local_pkeyp = nullptr; if (local_pkey.size() != 0) {local_pkeyp = &local_pkey;} - info->set(local_key, value, force, index, local_pkeyp); + info->set(local_key, value, force, index, local_pkeyp); esmc_rc = ESMF_SUCCESS; } ESMC_CATCH_ISOC @@ -471,7 +471,7 @@ void ESMC_InfoSetArrayI4(ESMCI::Info *info, char *key, int *value, int &count, b #undef ESMC_METHOD #define ESMC_METHOD "ESMC_InfoSetArrayI8()" -void ESMC_InfoSetArrayI8(ESMCI::Info *info, char *key, long int *value, int &count, bool &force, int &esmc_rc, char *pkey) { +void ESMC_InfoSetArrayI8(ESMCI::Info *info, char *key, long long int *value, int &count, bool &force, int &esmc_rc, char *pkey) { ESMC_CHECK_INIT(info, esmc_rc) esmc_rc = ESMF_FAILURE; try { @@ -479,7 +479,7 @@ void ESMC_InfoSetArrayI8(ESMCI::Info *info, char *key, long int *value, int &cou std::string local_pkey(pkey); std::string *local_pkeyp = nullptr; if (local_pkey.size() != 0) {local_pkeyp = &local_pkey;} - info->set(local_key, value, count, force, local_pkeyp); + info->set(local_key, value, count, force, local_pkeyp); esmc_rc = ESMF_SUCCESS; } ESMC_CATCH_ISOC @@ -501,4 +501,4 @@ void ESMC_InfoSetArrayLG(ESMCI::Info *info, char *key, bool *value, int &count, ESMC_CATCH_ISOC } -} // extern "C" +} // extern "C" \ No newline at end of file diff --git a/src/Infrastructure/Base/tests/ESMCI_InfoUTest.C b/src/Infrastructure/Base/tests/ESMCI_InfoUTest.C index adcfa8de3c..79fcf9b6d9 100644 --- a/src/Infrastructure/Base/tests/ESMCI_InfoUTest.C +++ b/src/Infrastructure/Base/tests/ESMCI_InfoUTest.C @@ -1232,7 +1232,7 @@ void test_bit_overflow(int& rc, char failMsg[]) { // Test integer overflow try { - info.set("bigint", ((long int)(std::numeric_limits::max()))+10, false); + info.set("bigint", ((long long int)(std::numeric_limits::max()))+10, false); int too_small = info.get("bigint"); return finalizeFailure(rc, failMsg, "did not catch overflow"); }