From 12854834f67af0c00b1ed7742aee9fcd79f95d22 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sat, 20 Apr 2019 20:49:21 +0200 Subject: [PATCH] Fix tests that fail on version (BigEndian) --- std/outbuffer.d | 10 ++++++++-- std/uni.d | 22 +++++++++++++++++----- std/xml.d | 12 ++++++++---- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/std/outbuffer.d b/std/outbuffer.d index 7564586e9..e964255fc 100644 --- a/std/outbuffer.d +++ b/std/outbuffer.d @@ -408,11 +408,17 @@ class OutBuffer { OutBuffer buf = new OutBuffer(); "hello"w.copy(buf); - assert(buf.toBytes() == "h\x00e\x00l\x00l\x00o\x00"); + version (LittleEndian) + assert(buf.toBytes() == "h\x00e\x00l\x00l\x00o\x00"); + version (BigEndian) + assert(buf.toBytes() == "\x00h\x00e\x00l\x00l\x00o"); } { OutBuffer buf = new OutBuffer(); "hello"d.copy(buf); - assert(buf.toBytes() == "h\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00"); + version (LittleEndian) + assert(buf.toBytes() == "h\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00"); + version (BigEndian) + assert(buf.toBytes() == "\x00\x00\x00h\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o"); } } diff --git a/std/uni.d b/std/uni.d index e6025ce9a..d934a067e 100644 --- a/std/uni.d +++ b/std/uni.d @@ -762,6 +762,8 @@ version (X86) enum hasUnalignedReads = true; else version (X86_64) enum hasUnalignedReads = true; +else version (SystemZ) + enum hasUnalignedReads = true; else enum hasUnalignedReads = false; // better be safe then sorry @@ -1237,8 +1239,13 @@ pure nothrow: T opIndex(size_t idx) inout { - return __ctfe ? simpleIndex(idx) : - cast(inout(T))(cast(U*) origin)[idx]; + T ret; + version (LittleEndian) + ret = __ctfe ? simpleIndex(idx) : + cast(inout(T))(cast(U*) origin)[idx]; + else + ret = simpleIndex(idx); + return ret; } static if (isBitPacked!T) // lack of user-defined implicit conversion @@ -1251,10 +1258,15 @@ pure nothrow: void opIndexAssign(TypeOfBitPacked!T val, size_t idx) { - if (__ctfe) - simpleWrite(val, idx); + version (LittleEndian) + { + if (__ctfe) + simpleWrite(val, idx); + else + (cast(U*) origin)[idx] = cast(U) val; + } else - (cast(U*) origin)[idx] = cast(U) val; + simpleWrite(val, idx); } } else diff --git a/std/xml.d b/std/xml.d index 6b01b137e..743cd8e5e 100644 --- a/std/xml.d +++ b/std/xml.d @@ -2201,8 +2201,10 @@ private mixin Check!("Chars"); dchar c; - int n = -1; - foreach (int i,dchar d; s) + ptrdiff_t n = -1; + // 'i' must not be smaller than size_t because size_t is used internally in + // aApply.d and it will be cast e.g to (int *) which fails on BigEndian targets. + foreach (size_t i, dchar d; s) { if (!isChar(d)) { @@ -2238,8 +2240,10 @@ private mixin Check!("Name"); if (s.length == 0) fail(); - int n; - foreach (int i,dchar c;s) + ptrdiff_t n; + // 'i' must not be smaller than size_t because size_t is used internally in + // aApply.d and it will be cast e.g to (int *) which fails on BigEndian targets. + foreach (size_t i, dchar c; s) { if (c == '_' || c == ':' || isLetter(c)) continue; if (i == 0) fail();