Codechange: Rearrange struct packing defines and make MinGW use _Pragma pack style

This commit is contained in:
Charles Pigott 2018-06-18 21:21:45 +01:00 committed by Patric Stout
parent 93469a92f2
commit 63898f61b0
4 changed files with 20 additions and 23 deletions

View File

@ -102,21 +102,19 @@ private:
bool ReadDLSWave(FILE *f, DWORD list_length, long offset); bool ReadDLSWave(FILE *f, DWORD list_length, long offset);
}; };
#pragma pack(2)
/** A RIFF chunk header. */ /** A RIFF chunk header. */
struct ChunkHeader { PACK_N(struct ChunkHeader {
FOURCC type; ///< Chunk type. FOURCC type; ///< Chunk type.
DWORD length; ///< Length of the chunk, not including the chunk header itself. DWORD length; ///< Length of the chunk, not including the chunk header itself.
}; }, 2);
/** Buffer format for a DLS wave download. */ /** Buffer format for a DLS wave download. */
struct WAVE_DOWNLOAD { PACK_N(struct WAVE_DOWNLOAD {
DMUS_DOWNLOADINFO dlInfo; DMUS_DOWNLOADINFO dlInfo;
ULONG ulOffsetTable[2]; ULONG ulOffsetTable[2];
DMUS_WAVE dmWave; DMUS_WAVE dmWave;
DMUS_WAVEDATA dmWaveData; DMUS_WAVEDATA dmWaveData;
}; }, 2);
#pragma pack()
struct PlaybackSegment { struct PlaybackSegment {
uint32 start, end; uint32 start, end;

View File

@ -805,16 +805,15 @@ int OTTDStringCompare(const char *s1, const char *s2)
} }
#ifdef _MSC_VER #ifdef _MSC_VER
/* Code from MSDN: https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx */ /* Based on code from MSDN: https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx */
const DWORD MS_VC_EXCEPTION = 0x406D1388; const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct { PACK_N(struct THREADNAME_INFO {
DWORD dwType; ///< Must be 0x1000. DWORD dwType; ///< Must be 0x1000.
LPCSTR szName; ///< Pointer to name (in user addr space). LPCSTR szName; ///< Pointer to name (in user addr space).
DWORD dwThreadID; ///< Thread ID (-1=caller thread). DWORD dwThreadID; ///< Thread ID (-1=caller thread).
DWORD dwFlags; ///< Reserved for future use, must be zero. DWORD dwFlags; ///< Reserved for future use, must be zero.
} THREADNAME_INFO; }, 8);
#pragma pack(pop)
/** /**
* Signal thread name to any attached debuggers. * Signal thread name to any attached debuggers.

View File

@ -71,23 +71,16 @@ struct ScreenshotFormat {
/************************************************* /*************************************************
**** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP)
*************************************************/ *************************************************/
#if defined(_MSC_VER) || defined(__WATCOMC__)
#pragma pack(push, 1)
#endif
/** BMP File Header (stored in little endian) */ /** BMP File Header (stored in little endian) */
struct BitmapFileHeader { PACK(struct BitmapFileHeader {
uint16 type; uint16 type;
uint32 size; uint32 size;
uint32 reserved; uint32 reserved;
uint32 off_bits; uint32 off_bits;
} GCC_PACK; });
assert_compile(sizeof(BitmapFileHeader) == 14); assert_compile(sizeof(BitmapFileHeader) == 14);
#if defined(_MSC_VER) || defined(__WATCOMC__)
#pragma pack(pop)
#endif
/** BMP Info Header (stored in little endian) */ /** BMP Info Header (stored in little endian) */
struct BitmapInfoHeader { struct BitmapInfoHeader {
uint32 size; uint32 size;

View File

@ -133,7 +133,6 @@
#define NORETURN __attribute__ ((noreturn)) #define NORETURN __attribute__ ((noreturn))
#define CDECL #define CDECL
#define __int64 long long #define __int64 long long
#define GCC_PACK __attribute__((packed))
/* Warn about functions using 'printf' format syntax. First argument determines which parameter /* Warn about functions using 'printf' format syntax. First argument determines which parameter
* is the format string, second argument is start of values passed to printf. */ * is the format string, second argument is start of values passed to printf. */
#define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args))) #define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args)))
@ -158,7 +157,6 @@
#if defined(__WATCOMC__) #if defined(__WATCOMC__)
#define NORETURN #define NORETURN
#define CDECL #define CDECL
#define GCC_PACK
#define WARN_FORMAT(string, args) #define WARN_FORMAT(string, args)
#define FINAL #define FINAL
#define FALLTHROUGH #define FALLTHROUGH
@ -224,7 +222,6 @@
#endif #endif
#define CDECL _cdecl #define CDECL _cdecl
#define GCC_PACK
#define WARN_FORMAT(string, args) #define WARN_FORMAT(string, args)
#define FINAL sealed #define FINAL sealed
@ -303,6 +300,16 @@
#define PATHSEPCHAR '/' #define PATHSEPCHAR '/'
#endif #endif
#if defined(_MSC_VER) || defined(__WATCOMC__)
# define PACK_N(type_dec, n) __pragma(pack(push, n)) type_dec; __pragma(pack(pop))
#elif defined(__MINGW32__)
# define PRAGMA(x) _Pragma(#x)
# define PACK_N(type_dec, n) PRAGMA(pack(push, n)) type_dec; PRAGMA(pack(pop))
#else
# define PACK_N(type_dec, n) type_dec __attribute__((__packed__, aligned(n)))
#endif
#define PACK(type_dec) PACK_N(type_dec, 1)
/* MSVCRT of course has to have a different syntax for long long *sigh* */ /* MSVCRT of course has to have a different syntax for long long *sigh* */
#if defined(_MSC_VER) || defined(__MINGW32__) #if defined(_MSC_VER) || defined(__MINGW32__)
#define OTTD_PRINTF64 "%I64d" #define OTTD_PRINTF64 "%I64d"