Merge branch 'save_ext' into jgrpp

This commit is contained in:
Jonathan G Rennison
2018-06-06 01:56:07 +01:00
3 changed files with 17 additions and 7 deletions

View File

@@ -393,7 +393,7 @@ static inline T ROR(const T x, const uint8 n)
* (since it will use hardware swapping if available). * (since it will use hardware swapping if available).
* Even though they should return uint16 and uint32, we get * Even though they should return uint16 and uint32, we get
* warnings if we don't cast those (why?) */ * warnings if we don't cast those (why?) */
#define BSWAP64(x) ((uint32)CFSwapInt64(x)) #define BSWAP64(x) ((uint64)CFSwapInt64(x))
#define BSWAP32(x) ((uint32)CFSwapInt32(x)) #define BSWAP32(x) ((uint32)CFSwapInt32(x))
#define BSWAP16(x) ((uint16)CFSwapInt16(x)) #define BSWAP16(x) ((uint16)CFSwapInt16(x))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)

View File

@@ -79,7 +79,7 @@ struct ReadBuffer {
inline int RawReadUint16() inline int RawReadUint16()
{ {
#if OTTD_ALIGNMENT == 0 #if OTTD_ALIGNMENT == 0
int x = FROM_BE16(*((const uint16*) this->bufp)); int x = FROM_BE16(*((const unaligned_uint16*) this->bufp));
this->bufp += 2; this->bufp += 2;
return x; return x;
#else #else
@@ -91,7 +91,7 @@ struct ReadBuffer {
inline uint32 RawReadUint32() inline uint32 RawReadUint32()
{ {
#if OTTD_ALIGNMENT == 0 #if OTTD_ALIGNMENT == 0
uint32 x = FROM_BE32(*((const uint32*) this->bufp)); uint32 x = FROM_BE32(*((const unaligned_uint32*) this->bufp));
this->bufp += 4; this->bufp += 4;
return x; return x;
#else #else
@@ -103,7 +103,7 @@ struct ReadBuffer {
inline uint64 RawReadUint64() inline uint64 RawReadUint64()
{ {
#if OTTD_ALIGNMENT == 0 #if OTTD_ALIGNMENT == 0
uint64 x = FROM_BE64(*((const uint64*) this->bufp)); uint64 x = FROM_BE64(*((const unaligned_uint64*) this->bufp));
this->bufp += 8; this->bufp += 8;
return x; return x;
#else #else
@@ -219,7 +219,7 @@ struct MemoryDumper {
inline void RawWriteUint16(uint16 v) inline void RawWriteUint16(uint16 v)
{ {
#if OTTD_ALIGNMENT == 0 #if OTTD_ALIGNMENT == 0
*((uint16 *) this->buf) = TO_BE16(v); *((unaligned_uint16 *) this->buf) = TO_BE16(v);
#else #else
this->buf[0] = GB(v, 8, 8)); this->buf[0] = GB(v, 8, 8));
this->buf[1] = GB(v, 0, 8)); this->buf[1] = GB(v, 0, 8));
@@ -230,7 +230,7 @@ struct MemoryDumper {
inline void RawWriteUint32(uint32 v) inline void RawWriteUint32(uint32 v)
{ {
#if OTTD_ALIGNMENT == 0 #if OTTD_ALIGNMENT == 0
*((uint32 *) this->buf) = TO_BE32(v); *((unaligned_uint32 *) this->buf) = TO_BE32(v);
#else #else
this->buf[0] = GB(v, 24, 8)); this->buf[0] = GB(v, 24, 8));
this->buf[1] = GB(v, 16, 8)); this->buf[1] = GB(v, 16, 8));
@@ -243,7 +243,7 @@ struct MemoryDumper {
inline void RawWriteUint64(uint64 v) inline void RawWriteUint64(uint64 v)
{ {
#if OTTD_ALIGNMENT == 0 #if OTTD_ALIGNMENT == 0
*((uint64 *) this->buf) = TO_BE64(v); *((unaligned_uint64 *) this->buf) = TO_BE64(v);
#else #else
this->buf[0] = GB(v, 56, 8)); this->buf[0] = GB(v, 56, 8));
this->buf[1] = GB(v, 48, 8)); this->buf[1] = GB(v, 48, 8));

View File

@@ -419,6 +419,16 @@ assert_compile(SIZE_MAX >= UINT32_MAX);
#define unlikely(x) (x) #define unlikely(x) (x)
#endif /* __GNUC__ || __clang__ */ #endif /* __GNUC__ || __clang__ */
#if defined(__GNUC__) || defined(__clang__)
__attribute__((aligned(1))) typedef uint16 unaligned_uint16;
__attribute__((aligned(1))) typedef uint32 unaligned_uint32;
__attribute__((aligned(1))) typedef uint64 unaligned_uint64;
#else
typedef uint16 unaligned_uint16;
typedef uint32 unaligned_uint32;
typedef uint64 unaligned_uint64;
#endif /* __GNUC__ || __clang__ */
void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2); void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2); void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
void NORETURN CDECL assert_msg_error(int line, const char *file, const char *expr, const char *str, ...) WARN_FORMAT(4, 5); void NORETURN CDECL assert_msg_error(int line, const char *file, const char *expr, const char *str, ...) WARN_FORMAT(4, 5);