From f82d9d7d353f7ce02a32e347dea224e6d4f9c68c Mon Sep 17 00:00:00 2001 From: Jakub Pawlewicz Date: Sun, 31 Jul 2022 07:44:42 +0200 Subject: [PATCH] Serialize long as 32 or 64 bit integer depending on platform --- uppsrc/Core/Defs.h | 10 ++++++++++ uppsrc/Core/Stream.h | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/uppsrc/Core/Defs.h b/uppsrc/Core/Defs.h index b5ef1149d..e26e799e6 100644 --- a/uppsrc/Core/Defs.h +++ b/uppsrc/Core/Defs.h @@ -166,6 +166,16 @@ typedef long long unsigned uint64; typedef uint64 qword; +#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(_WIN32)) + #define LONG_SIZE 4 +#elif defined(__clang__) || defined(__INTEL_COMPILER) || defined(__GNUC__) + #if __LONG_MAX__ == 2147483647L + #define LONG_SIZE 4 + #else + #define LONG_SIZE 8 + #endif +#endif + struct m128 { int64 i64[2]; diff --git a/uppsrc/Core/Stream.h b/uppsrc/Core/Stream.h index 9c171a1ba..12b0ce47e 100644 --- a/uppsrc/Core/Stream.h +++ b/uppsrc/Core/Stream.h @@ -207,8 +207,13 @@ public: Stream& operator%(unsigned short& d) { return SerializeRaw((word *)&d); } Stream& operator%(int& d) { return SerializeRaw((dword *)&d); } Stream& operator%(unsigned int& d) { return SerializeRaw((dword *)&d); } +#if LONG_SIZE == 4 Stream& operator%(long& d) { return SerializeRaw((dword *)&d); } Stream& operator%(unsigned long& d) { return SerializeRaw((dword *)&d); } +#else + Stream& operator%(long& d) { return SerializeRaw((uint64 *)&d); } + Stream& operator%(unsigned long& d) { return SerializeRaw((uint64 *)&d); } +#endif Stream& operator%(float& d) { return SerializeRaw((dword *)&d); } Stream& operator%(double& d) { return SerializeRaw((uint64 *)&d); } Stream& operator%(int64& d) { return SerializeRaw((uint64 *)&d); } -- 2.25.1