From 8c576ef9c5470f0ba421f338fbc8019ef4cb8372 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 19 Dec 2019 23:38:17 -0600 Subject: [PATCH] [ox] Replace __attribute__((packed)) with OX_PACKED --- deps/ox/src/ox/fs/filestore/filestoretemplate.hpp | 4 ++-- deps/ox/src/ox/fs/filesystem/directory.hpp | 4 ++-- deps/ox/src/ox/fs/filesystem/filesystem.hpp | 2 +- deps/ox/src/ox/ptrarith/nodebuffer.hpp | 7 ++++--- deps/ox/src/ox/ptrarith/test/tests.cpp | 2 +- deps/ox/src/ox/std/byteswap.hpp | 3 ++- deps/ox/src/ox/std/random.hpp | 3 ++- deps/ox/src/ox/std/stddef.hpp | 6 ++++++ 8 files changed, 20 insertions(+), 11 deletions(-) diff --git a/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp b/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp index 77961779..4d7ccdb4 100644 --- a/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp +++ b/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp @@ -23,7 +23,7 @@ struct StatInfo { }; template -struct __attribute__((packed)) FileStoreItem: public ptrarith::Item { +struct OX_PACKED FileStoreItem: public ptrarith::Item { ox::LittleEndian id = 0; ox::LittleEndian fileType = 0; ox::LittleEndian links = 0; @@ -64,7 +64,7 @@ class FileStoreTemplate { static constexpr InodeId_t ReservedInodeEnd = 100; static constexpr auto MaxInode = MaxValue / 2; - struct __attribute__((packed)) FileStoreData { + struct OX_PACKED FileStoreData { ox::LittleEndian rootNode = 0; ox::Random random; }; diff --git a/deps/ox/src/ox/fs/filesystem/directory.hpp b/deps/ox/src/ox/fs/filesystem/directory.hpp index 1b625fc3..cfe1d69c 100644 --- a/deps/ox/src/ox/fs/filesystem/directory.hpp +++ b/deps/ox/src/ox/fs/filesystem/directory.hpp @@ -16,10 +16,10 @@ namespace ox { template -struct __attribute__((packed)) DirectoryEntry { +struct OX_PACKED DirectoryEntry { public: - struct __attribute__((packed)) DirectoryEntryData { + struct OX_PACKED DirectoryEntryData { // DirectoryEntry fields LittleEndian inode = 0; char name[MaxFileNameLength]; diff --git a/deps/ox/src/ox/fs/filesystem/filesystem.hpp b/deps/ox/src/ox/fs/filesystem/filesystem.hpp index c81eb29c..a8eed502 100644 --- a/deps/ox/src/ox/fs/filesystem/filesystem.hpp +++ b/deps/ox/src/ox/fs/filesystem/filesystem.hpp @@ -89,7 +89,7 @@ class FileSystemTemplate: public FileSystem { private: static constexpr auto InodeFsData = 2; - struct __attribute__((packed)) FileSystemData { + struct OX_PACKED FileSystemData { LittleEndian rootDirInode; }; diff --git a/deps/ox/src/ox/ptrarith/nodebuffer.hpp b/deps/ox/src/ox/ptrarith/nodebuffer.hpp index bf92b925..bbb190de 100644 --- a/deps/ox/src/ox/ptrarith/nodebuffer.hpp +++ b/deps/ox/src/ox/ptrarith/nodebuffer.hpp @@ -8,6 +8,7 @@ #pragma once +#include #include #include "ptr.hpp" @@ -15,10 +16,10 @@ namespace ox::ptrarith { template -class __attribute__((packed)) NodeBuffer { +class OX_PACKED NodeBuffer { public: - struct __attribute__((packed)) Header { + struct OX_PACKED Header { ox::LittleEndian size = sizeof(Header); // capacity ox::LittleEndian bytesUsed = sizeof(Header); ox::LittleEndian firstItem = 0; @@ -433,7 +434,7 @@ uint8_t *NodeBuffer::data() { template -struct __attribute__((packed)) Item { +struct OX_PACKED Item { public: ox::LittleEndian prev = 0; ox::LittleEndian next = 0; diff --git a/deps/ox/src/ox/ptrarith/test/tests.cpp b/deps/ox/src/ox/ptrarith/test/tests.cpp index e15546c5..fdb79e11 100644 --- a/deps/ox/src/ox/ptrarith/test/tests.cpp +++ b/deps/ox/src/ox/ptrarith/test/tests.cpp @@ -26,7 +26,7 @@ using namespace std; using namespace ox; template -struct __attribute__((packed)) NodeType: public ox::ptrarith::Item { +struct OX_PACKED NodeType: public ox::ptrarith::Item { public: size_t fullSize() const { return this->size() + sizeof(*this); diff --git a/deps/ox/src/ox/std/byteswap.hpp b/deps/ox/src/ox/std/byteswap.hpp index d4dd9612..ff0ac3bf 100644 --- a/deps/ox/src/ox/std/byteswap.hpp +++ b/deps/ox/src/ox/std/byteswap.hpp @@ -9,6 +9,7 @@ #pragma once #include "defines.hpp" +#include "stddef.hpp" #include "types.hpp" #include "typetraits.hpp" @@ -58,7 +59,7 @@ template } template -class __attribute__((packed)) ByteSwapInteger { +class OX_PACKED ByteSwapInteger { private: T m_value; diff --git a/deps/ox/src/ox/std/random.hpp b/deps/ox/src/ox/std/random.hpp index 72108e0b..8743272f 100644 --- a/deps/ox/src/ox/std/random.hpp +++ b/deps/ox/src/ox/std/random.hpp @@ -8,13 +8,14 @@ #pragma once +#include "stddef.hpp" #include "types.hpp" namespace ox { using RandomSeed = uint64_t[2]; -class __attribute__((packed)) Random { +class OX_PACKED Random { private: RandomSeed m_seed; diff --git a/deps/ox/src/ox/std/stddef.hpp b/deps/ox/src/ox/std/stddef.hpp index ad44d883..1a41f50c 100644 --- a/deps/ox/src/ox/std/stddef.hpp +++ b/deps/ox/src/ox/std/stddef.hpp @@ -13,3 +13,9 @@ #else #define offsetof(type, member) __builtin_offsetof(type, member) #endif + +#ifdef _MSC_VER +#define OX_PACKED +#else +#define OX_PACKED __attribute__((packed)) +#endif