Changeset - r22957:2af6ade860c3
[Not reviewed]
master
0 4 0
Charles Pigott - 6 years ago 2018-06-18 20:21:45
charlespigott@googlemail.com
Codechange: Rearrange struct packing defines and make MinGW use _Pragma pack style
4 files changed with 20 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/music/dmusic.cpp
Show inline comments
 
@@ -99,27 +99,25 @@ private:
 
	/** Load a list of waves from a DLS file. */
 
	bool ReadDLSWaveList(FILE *f, DWORD list_length);
 
	/** Load a single wave from a DLS file. */
 
	bool ReadDLSWave(FILE *f, DWORD list_length, long offset);
 
};
 

	
 
#pragma pack(2)
 
/** A RIFF chunk header. */
 
struct ChunkHeader {
 
PACK_N(struct ChunkHeader {
 
	FOURCC type;  ///< Chunk type.
 
	DWORD length; ///< Length of the chunk, not including the chunk header itself.
 
};
 
}, 2);
 

	
 
/** Buffer format for a DLS wave download. */
 
struct WAVE_DOWNLOAD {
 
PACK_N(struct WAVE_DOWNLOAD {
 
	DMUS_DOWNLOADINFO   dlInfo;
 
	ULONG               ulOffsetTable[2];
 
	DMUS_WAVE           dmWave;
 
	DMUS_WAVEDATA       dmWaveData;
 
};
 
#pragma pack()
 
}, 2);
 

	
 
struct PlaybackSegment {
 
	uint32 start, end;
 
	size_t start_block;
 
	bool loop;
 
};
src/os/windows/win32.cpp
Show inline comments
 
@@ -802,22 +802,21 @@ int OTTDStringCompare(const char *s1, co
 
	convert_to_fs(s2, s2_buf, lengthof(s2_buf));
 

	
 
	return CompareString(MAKELCID(_current_language->winlangid, SORT_DEFAULT), NORM_IGNORECASE, s1_buf, -1, s2_buf, -1);
 
}
 

	
 
#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;
 
#pragma pack(push,8)
 
typedef struct {
 

	
 
PACK_N(struct THREADNAME_INFO {
 
	DWORD dwType;     ///< Must be 0x1000.
 
	LPCSTR szName;    ///< Pointer to name (in user addr space).
 
	DWORD dwThreadID; ///< Thread ID (-1=caller thread).
 
	DWORD dwFlags;    ///< Reserved for future use, must be zero.
 
} THREADNAME_INFO;
 
#pragma pack(pop)
 
}, 8);
 

	
 
/**
 
 * Signal thread name to any attached debuggers.
 
 */
 
void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
 
{
src/screenshot.cpp
Show inline comments
 
@@ -68,29 +68,22 @@ struct ScreenshotFormat {
 
	ScreenshotHandlerProc *proc; ///< Function for writing the screenshot.
 
};
 

	
 
/*************************************************
 
 **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP)
 
 *************************************************/
 
#if defined(_MSC_VER) || defined(__WATCOMC__)
 
#pragma pack(push, 1)
 
#endif
 

	
 
/** BMP File Header (stored in little endian) */
 
struct BitmapFileHeader {
 
PACK(struct BitmapFileHeader {
 
	uint16 type;
 
	uint32 size;
 
	uint32 reserved;
 
	uint32 off_bits;
 
} GCC_PACK;
 
});
 
assert_compile(sizeof(BitmapFileHeader) == 14);
 

	
 
#if defined(_MSC_VER) || defined(__WATCOMC__)
 
#pragma pack(pop)
 
#endif
 

	
 
/** BMP Info Header (stored in little endian) */
 
struct BitmapInfoHeader {
 
	uint32 size;
 
	int32 width, height;
 
	uint16 planes, bitcount;
 
	uint32 compression, sizeimage, xpels, ypels, clrused, clrimp;
src/stdafx.h
Show inline comments
 
@@ -130,13 +130,12 @@
 

	
 
/* Stuff for GCC */
 
#if defined(__GNUC__)
 
	#define NORETURN __attribute__ ((noreturn))
 
	#define CDECL
 
	#define __int64 long long
 
	#define GCC_PACK __attribute__((packed))
 
	/* 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. */
 
	#define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args)))
 
	#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
 
		#define FINAL final
 
	#else
 
@@ -155,13 +154,12 @@
 
	#endif
 
#endif /* __GNUC__ */
 

	
 
#if defined(__WATCOMC__)
 
	#define NORETURN
 
	#define CDECL
 
	#define GCC_PACK
 
	#define WARN_FORMAT(string, args)
 
	#define FINAL
 
	#define FALLTHROUGH
 
	#include <malloc.h>
 
#endif /* __WATCOMC__ */
 

	
 
@@ -221,13 +219,12 @@
 
	#define NORETURN __declspec(noreturn)
 
	#if (_MSC_VER < 1900)
 
		#define inline __forceinline
 
	#endif
 

	
 
	#define CDECL _cdecl
 
	#define GCC_PACK
 
	#define WARN_FORMAT(string, args)
 
	#define FINAL sealed
 

	
 
	/* fallthrough attribute, VS 2017 */
 
	#if (_MSC_VER >= 1910)
 
		#define FALLTHROUGH [[fallthrough]]
 
@@ -300,12 +297,22 @@
 
	#define PATHSEPCHAR '\\'
 
#else
 
	#define PATHSEP "/"
 
	#define PATHSEPCHAR '/'
 
#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* */
 
#if defined(_MSC_VER) || defined(__MINGW32__)
 
	#define OTTD_PRINTF64 "%I64d"
 
	#define OTTD_PRINTFHEX64 "%I64x"
 
	#define PRINTF_SIZE "%Iu"
 
#else
0 comments (0 inline, 0 general)