authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2021-04-07 17:30:12+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-04-08 08:33:26+03:00
log2d2316f5c0087a610127883f0593e8e9c0e939b7
tree9de2f7e6233a65312d40be6e849704bd84ad2f48
parentd4f61f9842da9025a4eb57e7a0fbb3298a4c01f6

translate-c: fix meta.cast to ?*c_void


1 files changed, 7 insertions(+), 2 deletions(-)

lib/std/meta.zig+7-2
......@@ -970,12 +970,15 @@ fn castPtr(comptime DestType: type, target: anytype) DestType {
970970
971971 if (source.is_const and !dest.is_const or source.is_volatile and !dest.is_volatile)
972972 return @intToPtr(DestType, @ptrToInt(target))
973 else if (@typeInfo(dest.child) == .Opaque)
974 // dest.alignment would error out
975 return @ptrCast(DestType, target)
973976 else
974977 return @ptrCast(DestType, @alignCast(dest.alignment, target));
975978}
976979
977980fn ptrInfo(comptime PtrType: type) TypeInfo.Pointer {
978 return switch(@typeInfo(PtrType)){
981 return switch (@typeInfo(PtrType)) {
979982 .Optional => |opt_info| @typeInfo(opt_info.child).Pointer,
980983 .Pointer => |ptr_info| ptr_info,
981984 else => unreachable,
......@@ -1010,6 +1013,8 @@ test "std.meta.cast" {
10101013
10111014 testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
10121015 testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
1016
1017 testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));
10131018}
10141019
10151020/// Given a value returns its size as C's sizeof operator would.
......@@ -1328,4 +1333,4 @@ test "shuffleVectorIndex" {
13281333 testing.expect(shuffleVectorIndex(5, vector_len) == -2);
13291334 testing.expect(shuffleVectorIndex(6, vector_len) == -3);
13301335 testing.expect(shuffleVectorIndex(7, vector_len) == -4);
1331}
\ No newline at end of file
1336}