authorgravatar for emekankurumeh@outlook.comEmeka Nkurumeh <emekankurumeh@outlook.com> 2019-10-16 17:15:52-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-16 18:15:52-04:00
log700bb19a9053e236df6a9f15d435c427391e3ecf
tree2a968a224e481e62dbf0ffc30dc87d30753532a2
parent45e5841281e0adf7924f0931dff219bf38f74622

fix std.mem.AsBytesReturnType (#3442)

closes #3334

1 files changed, 10 insertions(+), 0 deletions(-)

lib/std/mem.zig+10
...@@ -1325,6 +1325,12 @@ fn AsBytesReturnType(comptime P: type) type {...@@ -1325,6 +1325,12 @@ fn AsBytesReturnType(comptime P: type) type {
1325 const size = usize(@sizeOf(meta.Child(P)));1325 const size = usize(@sizeOf(meta.Child(P)));
1326 const alignment = comptime meta.alignment(P);1326 const alignment = comptime meta.alignment(P);
13271327
1328 if (alignment == 0) {
1329 if (comptime trait.isConstPtr(P))
1330 return *const [size]u8;
1331 return *[size]u8;
1332 }
1333
1328 if (comptime trait.isConstPtr(P))1334 if (comptime trait.isConstPtr(P))
1329 return *align(alignment) const [size]u8;1335 return *align(alignment) const [size]u8;
1330 return *align(alignment) [size]u8;1336 return *align(alignment) [size]u8;
...@@ -1364,6 +1370,10 @@ test "asBytes" {...@@ -1364,6 +1370,10 @@ test "asBytes" {
1364 .d = 0xA1,1370 .d = 0xA1,
1365 };1371 };
1366 testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));1372 testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
1373
1374 const ZST = struct {};
1375 const zero = ZST{};
1376 testing.expect(eql(u8, asBytes(&zero), ""));
1367}1377}
13681378
1369///Given any value, returns a copy of its bytes in an array.1379///Given any value, returns a copy of its bytes in an array.