From 0a8a6b04dc7ac8ef3c18650cf5cb7f83a8acf833 Mon Sep 17 00:00:00 2001 From: William F Godoy <williamfgc@yahoo.com> Date: Mon, 20 Nov 2017 14:12:12 -0500 Subject: [PATCH] Issue #313 Long integer ambiguity on Mac, Windows and Linux Resolving long ambiguity Correcting APPLE MACROS --- source/adios2/helper/adiosType.h | 2 +- source/adios2/toolkit/format/bp3/BP3Base.tcc | 14 ++++++++-- .../toolkit/format/bp3/BP3Deserializer.cpp | 27 +++---------------- .../toolkit/format/bp3/BP3Deserializer.tcc | 10 +++---- .../toolkit/format/bp3/BP3Serializer.cpp | 9 +++---- .../bp/TestBPWriteReadAttributesADIOS2.cpp | 10 +++---- 6 files changed, 30 insertions(+), 42 deletions(-) diff --git a/source/adios2/helper/adiosType.h b/source/adios2/helper/adiosType.h index 8392a9672..75c53a23c 100644 --- a/source/adios2/helper/adiosType.h +++ b/source/adios2/helper/adiosType.h @@ -52,7 +52,7 @@ using SubFileInfoMap = * @return string with type */ template <class T> -inline std::string GetType() noexcept; +std::string GetType() noexcept; /** * Check in types set if "type" is one of the aliases for a certain type, diff --git a/source/adios2/toolkit/format/bp3/BP3Base.tcc b/source/adios2/toolkit/format/bp3/BP3Base.tcc index 5c7fcbdcd..ffd66cba5 100644 --- a/source/adios2/toolkit/format/bp3/BP3Base.tcc +++ b/source/adios2/toolkit/format/bp3/BP3Base.tcc @@ -61,7 +61,12 @@ int8_t BP3Base::GetDataType<int>() const noexcept template <> int8_t BP3Base::GetDataType<long int>() const noexcept { - const int8_t type = static_cast<int8_t>(type_long); + int8_t type = static_cast<int8_t>(type_long); + if (sizeof(long int) == sizeof(int)) + { + type = static_cast<int8_t>(type_integer); + } + return type; } @@ -96,7 +101,12 @@ int8_t BP3Base::GetDataType<unsigned int>() const noexcept template <> int8_t BP3Base::GetDataType<unsigned long int>() const noexcept { - const int8_t type = static_cast<int8_t>(type_unsigned_long); + int8_t type = static_cast<int8_t>(type_unsigned_long); + if (sizeof(unsigned long int) == sizeof(unsigned int)) + { + type = static_cast<int8_t>(type_unsigned_integer); + } + return type; } diff --git a/source/adios2/toolkit/format/bp3/BP3Deserializer.cpp b/source/adios2/toolkit/format/bp3/BP3Deserializer.cpp index 317e0770c..99b668ffd 100644 --- a/source/adios2/toolkit/format/bp3/BP3Deserializer.cpp +++ b/source/adios2/toolkit/format/bp3/BP3Deserializer.cpp @@ -159,11 +159,7 @@ void BP3Deserializer::ParseVariablesIndex(IO &io) case (type_long): { -#ifdef _WIN32 - DefineVariableInIO<long long int>(header, io, buffer, position); -#else - DefineVariableInIO<long int>(header, io, buffer, position); -#endif + DefineVariableInIO<int64_t>(header, io, buffer, position); break; } @@ -187,12 +183,7 @@ void BP3Deserializer::ParseVariablesIndex(IO &io) case (type_unsigned_long): { -#ifdef _WIN32 - DefineVariableInIO<unsigned long long int>(header, io, buffer, - position); -#else - DefineVariableInIO<unsigned long int>(header, io, buffer, position); -#endif + DefineVariableInIO<uint64_t>(header, io, buffer, position); break; } @@ -332,11 +323,7 @@ void BP3Deserializer::ParseAttributesIndex(IO &io) case (type_long): { -#ifdef _WIN32 - DefineAttributeInIO<long long int>(header, io, buffer, position); -#else - DefineAttributeInIO<long int>(header, io, buffer, position); -#endif + DefineAttributeInIO<int64_t>(header, io, buffer, position); break; } @@ -360,13 +347,7 @@ void BP3Deserializer::ParseAttributesIndex(IO &io) case (type_unsigned_long): { -#ifdef _WIN32 - DefineAttributeInIO<unsigned long long int>(header, io, buffer, - position); -#else - DefineAttributeInIO<unsigned long int>(header, io, buffer, - position); -#endif + DefineAttributeInIO<uint64_t>(header, io, buffer, position); break; } diff --git a/source/adios2/toolkit/format/bp3/BP3Deserializer.tcc b/source/adios2/toolkit/format/bp3/BP3Deserializer.tcc index 469bea855..f36d3fb7f 100644 --- a/source/adios2/toolkit/format/bp3/BP3Deserializer.tcc +++ b/source/adios2/toolkit/format/bp3/BP3Deserializer.tcc @@ -136,17 +136,15 @@ void BP3Deserializer::DefineAttributeInIO(const ElementIndexHeader &header, attributeName = header.Path + PathSeparator + header.Name; } - Attribute<T> *attribute = nullptr; if (characteristics.Statistics.IsValue) { - attribute = &io.DefineAttribute<T>(attributeName, - characteristics.Statistics.Value); + io.DefineAttribute<T>(attributeName, characteristics.Statistics.Value); } else { - attribute = &io.DefineAttribute<T>( - attributeName, characteristics.Statistics.Values.data(), - characteristics.Statistics.Values.size()); + io.DefineAttribute<T>(attributeName, + characteristics.Statistics.Values.data(), + characteristics.Statistics.Values.size()); } } diff --git a/source/adios2/toolkit/format/bp3/BP3Serializer.cpp b/source/adios2/toolkit/format/bp3/BP3Serializer.cpp index 84127dda3..6e8f681ef 100644 --- a/source/adios2/toolkit/format/bp3/BP3Serializer.cpp +++ b/source/adios2/toolkit/format/bp3/BP3Serializer.cpp @@ -856,8 +856,8 @@ void BP3Serializer::MergeSerializeIndices( case (type_long): { const auto characteristics = - ReadElementIndexCharacteristics<long int>(buffer, position, - type_long, true); + ReadElementIndexCharacteristics<int64_t>(buffer, position, + type_long, true); count = characteristics.EntryCount; length = characteristics.EntryLength; timeStep = characteristics.Statistics.Step; @@ -899,9 +899,8 @@ void BP3Serializer::MergeSerializeIndices( case (type_unsigned_long): { - auto characteristics = - ReadElementIndexCharacteristics<unsigned long int>( - buffer, position, type_unsigned_long, true); + auto characteristics = ReadElementIndexCharacteristics<uint64_t>( + buffer, position, type_unsigned_long, true); count = characteristics.EntryCount; length = characteristics.EntryLength; timeStep = characteristics.Statistics.Step; diff --git a/testing/adios2/engine/bp/TestBPWriteReadAttributesADIOS2.cpp b/testing/adios2/engine/bp/TestBPWriteReadAttributesADIOS2.cpp index db949a31b..91ba991e4 100644 --- a/testing/adios2/engine/bp/TestBPWriteReadAttributesADIOS2.cpp +++ b/testing/adios2/engine/bp/TestBPWriteReadAttributesADIOS2.cpp @@ -131,7 +131,7 @@ TEST_F(BPWriteReadAttributeTestADIOS2, ADIOS2BPWriteReadSingleTypes) ASSERT_NE(attr_i64, nullptr); ASSERT_EQ(attr_i64->m_Name, i64_Single); ASSERT_EQ(attr_i64->m_IsSingleValue, true); -#ifdef _WIN32 +#if defined(_WIN32) || defined(__APPLE__) ASSERT_EQ(attr_i64->m_Type, "long long int"); #else ASSERT_EQ(attr_i64->m_Type, "long int"); @@ -159,8 +159,7 @@ TEST_F(BPWriteReadAttributeTestADIOS2, ADIOS2BPWriteReadSingleTypes) ASSERT_NE(attr_u64, nullptr); ASSERT_EQ(attr_u64->m_Name, u64_Single); ASSERT_EQ(attr_u64->m_IsSingleValue, true); - -#ifdef _WIN32 +#if defined(_WIN32) || defined(__APPLE__) ASSERT_EQ(attr_u64->m_Type, "unsigned long long int"); #else ASSERT_EQ(attr_u64->m_Type, "unsigned long int"); @@ -301,7 +300,7 @@ TEST_F(BPWriteReadAttributeTestADIOS2, ADIOS2BPWriteReadArrayTypes) ASSERT_NE(attr_i64, nullptr); ASSERT_EQ(attr_i64->m_Name, i64_Array); ASSERT_EQ(attr_i64->m_IsSingleValue, false); -#ifdef _WIN32 +#if defined(_WIN32) || defined(__APPLE__) ASSERT_EQ(attr_i64->m_Type, "long long int"); #else ASSERT_EQ(attr_i64->m_Type, "long int"); @@ -325,11 +324,12 @@ TEST_F(BPWriteReadAttributeTestADIOS2, ADIOS2BPWriteReadArrayTypes) ASSERT_NE(attr_u64, nullptr); ASSERT_EQ(attr_u64->m_Name, u64_Array); ASSERT_EQ(attr_u64->m_IsSingleValue, false); -#ifdef _WIN32 +#if defined(_WIN32) || defined(__APPLE__) ASSERT_EQ(attr_u64->m_Type, "unsigned long long int"); #else ASSERT_EQ(attr_u64->m_Type, "unsigned long int"); #endif + ASSERT_NE(attr_r32, nullptr); ASSERT_EQ(attr_r32->m_Name, r32_Array); ASSERT_EQ(attr_r32->m_IsSingleValue, false); -- GitLab