Skip to content

Commit

Permalink
Ensure ESMF_KIND_I8 is consistently treated as 64-bit (long long int),
Browse files Browse the repository at this point in the history
regardless of ABI.
  • Loading branch information
theurich committed Jun 5, 2024
1 parent ae1ac79 commit c151560
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions scripts/jinja2_templating/generate_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions src/Infrastructure/Base/interface/ESMF_InfoCDefGeneric.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions src/Infrastructure/Base/src/ESMCI_Info.C
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1388,7 +1388,7 @@ void Info::set(key_t &key, T value, bool force, const int *index, const key_t *
template void Info::set<float>(key_t&, float, bool, const int*, const key_t * const);
template void Info::set<double>(key_t&, double, bool, const int*, const key_t * const);
template void Info::set<int>(key_t&, int, bool, const int*, const key_t * const);
template void Info::set<long int>(key_t&, long int, bool, const int*, const key_t * const);
template void Info::set<long long int>(key_t&, long long int, bool, const int*, const key_t * const);
template void Info::set<std::string>(key_t&, std::string, bool, const int*, const key_t * const);
template void Info::set<bool>(key_t&, bool, bool, const int*, const key_t * const);

Expand Down Expand Up @@ -1420,7 +1420,7 @@ void Info::set(key_t &key, T *values, int count, bool force, const key_t * const
template void Info::set<float>(key_t&, float*, int, bool, const key_t * const);
template void Info::set<double>(key_t&, double*, int, bool, const key_t * const);
template void Info::set<int>(key_t&, int*, int, bool, const key_t * const);
template void Info::set<long int>(key_t&, long int*, int, bool, const key_t * const);
template void Info::set<long long int>(key_t&, long long int*, int, bool, const key_t * const);
template void Info::set<bool>(key_t&, bool*, int, bool, const key_t * const);
template void Info::set<std::vector<std::string>>(key_t&, std::vector<std::string>*, int, bool, const key_t * const);

Expand Down
18 changes: 9 additions & 9 deletions src/Infrastructure/Base/src/ESMC_InfoCDefGeneric.C
Original file line number Diff line number Diff line change
Expand Up @@ -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<long int>(local_key, def, index, recursive, nullptr, false);
value = info->get<long long int>(local_key, def, index, recursive, nullptr, false);
esmc_rc = ESMF_SUCCESS;
}
ESMC_CATCH_ISOC
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<long int>(local_key, nullptr, nullptr, recursive, nullptr, false);
value[0] = info->get<long long int>(local_key, nullptr, nullptr, recursive, nullptr, false);
}
esmc_rc = ESMF_SUCCESS;
}
Expand Down Expand Up @@ -389,15 +389,15 @@ 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 {
std::string local_key(key);
std::string local_pkey(pkey);
std::string *local_pkeyp = nullptr;
if (local_pkey.size() != 0) {local_pkeyp = &local_pkey;}
info->set<long int>(local_key, value, force, index, local_pkeyp);
info->set<long long int>(local_key, value, force, index, local_pkeyp);
esmc_rc = ESMF_SUCCESS;
}
ESMC_CATCH_ISOC
Expand Down Expand Up @@ -471,15 +471,15 @@ 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 {
std::string local_key(key);
std::string local_pkey(pkey);
std::string *local_pkeyp = nullptr;
if (local_pkey.size() != 0) {local_pkeyp = &local_pkey;}
info->set<long int>(local_key, value, count, force, local_pkeyp);
info->set<long long int>(local_key, value, count, force, local_pkeyp);
esmc_rc = ESMF_SUCCESS;
}
ESMC_CATCH_ISOC
Expand All @@ -501,4 +501,4 @@ void ESMC_InfoSetArrayLG(ESMCI::Info *info, char *key, bool *value, int &count,
ESMC_CATCH_ISOC
}

} // extern "C"
} // extern "C"
2 changes: 1 addition & 1 deletion src/Infrastructure/Base/tests/ESMCI_InfoUTest.C
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ void test_bit_overflow(int& rc, char failMsg[]) {

// Test integer overflow
try {
info.set("bigint", ((long int)(std::numeric_limits<int>::max()))+10, false);
info.set("bigint", ((long long int)(std::numeric_limits<int>::max()))+10, false);
int too_small = info.get<int>("bigint");
return finalizeFailure(rc, failMsg, "did not catch overflow");
}
Expand Down

0 comments on commit c151560

Please sign in to comment.