| ... | ... | @@ -970,12 +970,15 @@ fn castPtr(comptime DestType: type, target: anytype) DestType { |
| 970 | 970 | |
| 971 | 971 | if (source.is_const and !dest.is_const or source.is_volatile and !dest.is_volatile) |
| 972 | 972 | return @intToPtr(DestType, @ptrToInt(target)) |
| 973 | else if (@typeInfo(dest.child) == .Opaque) |
| 974 | // dest.alignment would error out |
| 975 | return @ptrCast(DestType, target) |
| 973 | 976 | else |
| 974 | 977 | return @ptrCast(DestType, @alignCast(dest.alignment, target)); |
| 975 | 978 | } |
| 976 | 979 | |
| 977 | 980 | fn ptrInfo(comptime PtrType: type) TypeInfo.Pointer { |
| 978 | | return switch(@typeInfo(PtrType)){ |
| 981 | return switch (@typeInfo(PtrType)) { |
| 979 | 982 | .Optional => |opt_info| @typeInfo(opt_info.child).Pointer, |
| 980 | 983 | .Pointer => |ptr_info| ptr_info, |
| 981 | 984 | else => unreachable, |
| ... | ... | @@ -1010,6 +1013,8 @@ test "std.meta.cast" { |
| 1010 | 1013 | |
| 1011 | 1014 | testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2))); |
| 1012 | 1015 | 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))); |
| 1013 | 1018 | } |
| 1014 | 1019 | |
| 1015 | 1020 | /// Given a value returns its size as C's sizeof operator would. |
| ... | ... | @@ -1328,4 +1333,4 @@ test "shuffleVectorIndex" { |
| 1328 | 1333 | testing.expect(shuffleVectorIndex(5, vector_len) == -2); |
| 1329 | 1334 | testing.expect(shuffleVectorIndex(6, vector_len) == -3); |
| 1330 | 1335 | testing.expect(shuffleVectorIndex(7, vector_len) == -4); |
| 1331 | | } |
| | \ No newline at end of file |
| 1336 | } |