From 4fad6e0631718a4bb574d67505e0ebfef1f171ce Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Thu, 1 Apr 2021 10:48:13 +0200 Subject: [PATCH] fix pickling on arm, store long type platform independent --- libsrc/core/archive.hpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libsrc/core/archive.hpp b/libsrc/core/archive.hpp index 430262bf..decf8718 100644 --- a/libsrc/core/archive.hpp +++ b/libsrc/core/archive.hpp @@ -688,7 +688,11 @@ namespace ngcore Archive & operator & (short & i) override { return Write(i); } Archive & operator & (long & i) override - { return Write(i); } + { + // for platform independence + int64_t tmp = i; + return Write(tmp); + } Archive & operator & (size_t & i) override { return Write(i); } Archive & operator & (unsigned char & i) override @@ -726,14 +730,13 @@ namespace ngcore template Archive & Write (T x) { + static_assert(sizeof(T) < BUFFERSIZE, "Cannot write large types with this function!"); if (unlikely(ptr > BUFFERSIZE-sizeof(T))) { stream->write(&buffer[0], ptr); - *reinterpret_cast(&buffer[0]) = x; // NOLINT - ptr = sizeof(T); - return *this; + ptr = 0; } - *reinterpret_cast(&buffer[ptr]) = x; // NOLINT + memcpy(&buffer[ptr], &x, sizeof(T)); ptr += sizeof(T); return *this; } @@ -761,7 +764,12 @@ namespace ngcore Archive & operator & (short & i) override { Read(i); return *this; } Archive & operator & (long & i) override - { Read(i); return *this; } + { + int64_t tmp; + Read(tmp); + i = tmp; + return *this; + } Archive & operator & (size_t & i) override { Read(i); return *this; } Archive & operator & (unsigned char & i) override