diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-11-02 13:37:24 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-02 13:37:24 -0500 |
| commit | 061ff11b2b8aca33fec0d5d381855d5bd3aa6ff9 (patch) | |
| tree | 43488e010c69f136e7d7a91535ad477ecafcc6fb /lib | |
| parent | ecdd6366052ec815466db0c64b2a5abe59267393 (diff) | |
| parent | dc872a221d8301cfac4b9ead09196c5b18cf63b2 (diff) | |
| download | zig-061ff11b2b8aca33fec0d5d381855d5bd3aa6ff9.tar.gz zig-061ff11b2b8aca33fec0d5d381855d5bd3aa6ff9.zip | |
Merge pull request #6927 from LemonBoy/mipsbe-std
Fixes for stdlib for mips BE targets
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/array_hash_map.zig | 3 | ||||
| -rw-r--r-- | lib/std/io/test.zig | 3 | ||||
| -rw-r--r-- | lib/std/json.zig | 24 | ||||
| -rw-r--r-- | lib/std/json/test.zig | 69 | ||||
| -rw-r--r-- | lib/std/os/linux.zig | 68 | ||||
| -rw-r--r-- | lib/std/unicode.zig | 29 |
6 files changed, 77 insertions, 119 deletions
diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig index 649c1e1055..e5ad26cb45 100644 --- a/lib/std/array_hash_map.zig +++ b/lib/std/array_hash_map.zig @@ -930,9 +930,6 @@ test "basic hash map usage" { } test "iterator hash map" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - var reset_map = AutoArrayHashMap(i32, i32).init(std.testing.allocator); defer reset_map.deinit(); diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig index ecad26a448..ad519a9199 100644 --- a/lib/std/io/test.zig +++ b/lib/std/io/test.zig @@ -140,9 +140,6 @@ test "File seek ops" { } test "setEndPos" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - var tmp = tmpDir(.{}); defer tmp.cleanup(); diff --git a/lib/std/json.zig b/lib/std/json.zig index f3594bc3eb..b64216b2d4 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -2125,7 +2125,11 @@ fn unescapeString(output: []u8, input: []const u8) !void { const secondCodeUnit = std.fmt.parseInt(u16, input[inIndex + 8 .. inIndex + 12], 16) catch unreachable; - if (std.unicode.utf16leToUtf8(output[outIndex..], &[2]u16{ firstCodeUnit, secondCodeUnit })) |byteCount| { + const utf16le_seq = [2]u16{ + mem.littleToNative(u16, firstCodeUnit), + mem.littleToNative(u16, secondCodeUnit), + }; + if (std.unicode.utf16leToUtf8(output[outIndex..], &utf16le_seq)) |byteCount| { outIndex += byteCount; inIndex += 12; } else |_| { @@ -2265,9 +2269,6 @@ test "integer after float has proper type" { } test "escaped characters" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_allocator.deinit(); const input = @@ -2300,9 +2301,6 @@ test "escaped characters" { } test "string copy option" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - const input = \\{ \\ "noescape": "aą😂", @@ -2721,9 +2719,9 @@ test "stringify struct with indentation" { \\} , struct { - foo: u32, - bar: [3]u32, - }{ + foo: u32, + bar: [3]u32, + }{ .foo = 42, .bar = .{ 1, 2, 3 }, }, @@ -2734,9 +2732,9 @@ test "stringify struct with indentation" { try teststringify( "{\n\t\"foo\":42,\n\t\"bar\":[\n\t\t1,\n\t\t2,\n\t\t3\n\t]\n}", struct { - foo: u32, - bar: [3]u32, - }{ + foo: u32, + bar: [3]u32, + }{ .foo = 42, .bar = .{ 1, 2, 3 }, }, diff --git a/lib/std/json/test.zig b/lib/std/json/test.zig index 3a7c25e383..bce9ed448d 100644 --- a/lib/std/json/test.zig +++ b/lib/std/json/test.zig @@ -337,18 +337,12 @@ test "y_string_1_2_3_bytes_UTF-8_sequences" { } test "y_string_accepted_surrogate_pair" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\uD801\udc37"] ); } test "y_string_accepted_surrogate_pairs" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\ud83d\ude39\ud83d\udc8d"] ); @@ -415,9 +409,6 @@ test "y_string_in_array_with_leading_space" { } test "y_string_last_surrogates_1_and_2" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\uDBFF\uDFFF"] ); @@ -478,9 +469,6 @@ test "y_string_space" { } test "y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\uD834\uDd1e"] ); @@ -523,90 +511,60 @@ test "y_string_unescaped_char_delete" { } test "y_string_unicode_2" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["⍂㈴⍂"] ); } test "y_string_unicodeEscapedBackslash" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\u005C"] ); } test "y_string_unicode_escaped_double_quote" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\u0022"] ); } test "y_string_unicode" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\uA66D"] ); } test "y_string_unicode_U+10FFFE_nonchar" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\uDBFF\uDFFE"] ); } test "y_string_unicode_U+1FFFE_nonchar" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\uD83F\uDFFE"] ); } test "y_string_unicode_U+200B_ZERO_WIDTH_SPACE" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\u200B"] ); } test "y_string_unicode_U+2064_invisible_plus" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\u2064"] ); } test "y_string_unicode_U+FDD0_nonchar" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\uFDD0"] ); } test "y_string_unicode_U+FFFE_nonchar" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - ok( \\["\uFFFE"] ); @@ -1858,63 +1816,42 @@ test "i_object_key_lone_2nd_surrogate" { } test "i_string_1st_surrogate_but_2nd_missing" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - anyStreamingErrNonStreaming( \\["\uDADA"] ); } test "i_string_1st_valid_surrogate_2nd_invalid" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - anyStreamingErrNonStreaming( \\["\uD888\u1234"] ); } test "i_string_incomplete_surrogate_and_escape_valid" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - anyStreamingErrNonStreaming( \\["\uD800\n"] ); } test "i_string_incomplete_surrogate_pair" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - anyStreamingErrNonStreaming( \\["\uDd1ea"] ); } test "i_string_incomplete_surrogates_escape_valid" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - anyStreamingErrNonStreaming( \\["\uD800\uD800\n"] ); } test "i_string_invalid_lonely_surrogate" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - anyStreamingErrNonStreaming( \\["\ud800"] ); } test "i_string_invalid_surrogate" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - anyStreamingErrNonStreaming( \\["\ud800abc"] ); @@ -1927,9 +1864,6 @@ test "i_string_invalid_utf-8" { } test "i_string_inverted_surrogates_U+1D11E" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - anyStreamingErrNonStreaming( \\["\uDd1e\uD834"] ); @@ -1942,9 +1876,6 @@ test "i_string_iso_latin_1" { } test "i_string_lone_second_surrogate" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - anyStreamingErrNonStreaming( \\["\uDFAA"] ); diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 96e8a5edf4..c5fbd0bcfe 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -48,13 +48,27 @@ pub fn getauxval(index: usize) usize { return 0; } -// Some architectures require 64bit parameters for some syscalls to be passed in -// even-aligned register pair +// Some architectures (and some syscalls) require 64bit parameters to be passed +// in a even-aligned register pair. const require_aligned_register_pair = // std.Target.current.cpu.arch.isMIPS() or std.Target.current.cpu.arch.isARM() or std.Target.current.cpu.arch.isThumb(); +// Split a 64bit value into a {LSB,MSB} pair. +fn splitValue64(val: u64) [2]u32 { + switch (builtin.endian) { + .Little => return [2]u32{ + @truncate(u32, val), + @truncate(u32, val >> 32), + }, + .Big => return [2]u32{ + @truncate(u32, val >> 32), + @truncate(u32, val), + }, + } +} + /// Get the errno from a syscall return value, or 0 for no error. pub fn getErrno(r: usize) u12 { const signed_r = @bitCast(isize, r); @@ -263,24 +277,26 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize { } pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { + const offset_halves = splitValue64(offset); return syscall5( .preadv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count, - @truncate(usize, offset), - @truncate(usize, offset >> 32), + offset_halves[0], + offset_halves[1], ); } pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize { + const offset_halves = splitValue64(offset); return syscall6( .preadv2, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count, - @truncate(usize, offset), - @truncate(usize, offset >> 32), + offset_halves[0], + offset_halves[1], flags, ); } @@ -294,24 +310,26 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { } pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize { + const offset_halves = splitValue64(offset); return syscall5( .pwritev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count, - @truncate(usize, offset), - @truncate(usize, offset >> 32), + offset_halves[0], + offset_halves[1], ); } pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize { + const offset_halves = splitValue64(offset); return syscall6( .pwritev2, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count, - @truncate(usize, offset), - @truncate(usize, offset >> 32), + offset_halves[0], + offset_halves[1], flags, ); } @@ -338,6 +356,7 @@ pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) us pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { if (@hasField(SYS, "pread64")) { + const offset_halves = splitValue64(offset); if (require_aligned_register_pair) { return syscall6( .pread64, @@ -345,8 +364,8 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { @ptrToInt(buf), count, 0, - @truncate(usize, offset), - @truncate(usize, offset >> 32), + offset_halves[0], + offset_halves[1], ); } else { return syscall5( @@ -354,8 +373,8 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, - @truncate(usize, offset), - @truncate(usize, offset >> 32), + offset_halves[0], + offset_halves[1], ); } } else { @@ -401,20 +420,21 @@ pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { pub fn ftruncate(fd: i32, length: u64) usize { if (@hasField(SYS, "ftruncate64")) { + const length_halves = splitValue64(length); if (require_aligned_register_pair) { return syscall4( .ftruncate64, @bitCast(usize, @as(isize, fd)), 0, - @truncate(usize, length), - @truncate(usize, length >> 32), + length_halves[0], + length_halves[1], ); } else { return syscall3( .ftruncate64, @bitCast(usize, @as(isize, fd)), - @truncate(usize, length), - @truncate(usize, length >> 32), + length_halves[0], + length_halves[1], ); } } else { @@ -428,6 +448,8 @@ pub fn ftruncate(fd: i32, length: u64) usize { pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize { if (@hasField(SYS, "pwrite64")) { + const offset_halves = splitValue64(offset); + if (require_aligned_register_pair) { return syscall6( .pwrite64, @@ -435,8 +457,8 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize { @ptrToInt(buf), count, 0, - @truncate(usize, offset), - @truncate(usize, offset >> 32), + offset_halves[0], + offset_halves[1], ); } else { return syscall5( @@ -444,8 +466,8 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize { @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, - @truncate(usize, offset), - @truncate(usize, offset >> 32), + offset_halves[0], + offset_halves[1], ); } } else { @@ -540,6 +562,8 @@ pub fn close(fd: i32) usize { /// Can only be called on 32 bit systems. For 64 bit see `lseek`. pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { + // NOTE: The offset parameter splitting is independent from the target + // endianness. return syscall5( ._llseek, @bitCast(usize, @as(isize, fd)), diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index 86b805b892..18bd5ab0e2 100644 --- a/lib/std/unicode.zig +++ b/lib/std/unicode.zig @@ -706,41 +706,52 @@ fn calcUtf16LeLen(utf8: []const u8) usize { } test "utf8ToUtf16LeStringLiteral" { - // https://github.com/ziglang/zig/issues/5127 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - { - const bytes = [_:0]u16{0x41}; + const bytes = [_:0]u16{ + mem.nativeToLittle(u16, 0x41), + }; const utf16 = utf8ToUtf16LeStringLiteral("A"); testing.expectEqualSlices(u16, &bytes, utf16); testing.expect(utf16[1] == 0); } { - const bytes = [_:0]u16{ 0xD801, 0xDC37 }; + const bytes = [_:0]u16{ + mem.nativeToLittle(u16, 0xD801), + mem.nativeToLittle(u16, 0xDC37), + }; const utf16 = utf8ToUtf16LeStringLiteral("𐐷"); testing.expectEqualSlices(u16, &bytes, utf16); testing.expect(utf16[2] == 0); } { - const bytes = [_:0]u16{0x02FF}; + const bytes = [_:0]u16{ + mem.nativeToLittle(u16, 0x02FF), + }; const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}"); testing.expectEqualSlices(u16, &bytes, utf16); testing.expect(utf16[1] == 0); } { - const bytes = [_:0]u16{0x7FF}; + const bytes = [_:0]u16{ + mem.nativeToLittle(u16, 0x7FF), + }; const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}"); testing.expectEqualSlices(u16, &bytes, utf16); testing.expect(utf16[1] == 0); } { - const bytes = [_:0]u16{0x801}; + const bytes = [_:0]u16{ + mem.nativeToLittle(u16, 0x801), + }; const utf16 = utf8ToUtf16LeStringLiteral("\u{801}"); testing.expectEqualSlices(u16, &bytes, utf16); testing.expect(utf16[1] == 0); } { - const bytes = [_:0]u16{ 0xDBFF, 0xDFFF }; + const bytes = [_:0]u16{ + mem.nativeToLittle(u16, 0xDBFF), + mem.nativeToLittle(u16, 0xDFFF), + }; const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}"); testing.expectEqualSlices(u16, &bytes, utf16); testing.expect(utf16[2] == 0); |
