| ... | ... | @@ -181,9 +181,13 @@ fn rawCAlloc( |
| 181 | 181 | ) ?[*]u8 { |
| 182 | 182 | _ = ret_addr; |
| 183 | 183 | assert(log2_ptr_align <= comptime std.math.log2_int(usize, @alignOf(std.c.max_align_t))); |
| 184 | | // TODO: change the language to make @ptrCast also do alignment cast |
| 185 | | const ptr = @alignCast(@alignOf(std.c.max_align_t), c.malloc(len)); |
| 186 | | return @ptrCast(?[*]align(@alignOf(std.c.max_align_t)) u8, ptr); |
| 184 | // Note that this pointer cannot be aligncasted to max_align_t because if |
| 185 | // len is < max_align_t then the alignment can be smaller. For example, if |
| 186 | // max_align_t is 16, but the user requests 8 bytes, there is no built-in |
| 187 | // type in C that is size 8 and has 16 byte alignment, so the alignment may |
| 188 | // be 8 bytes rather than 16. Similarly if only 1 byte is requested, malloc |
| 189 | // is allowed to return a 1-byte aligned pointer. |
| 190 | return @ptrCast(?[*]u8, c.malloc(len)); |
| 187 | 191 | } |
| 188 | 192 | |
| 189 | 193 | fn rawCResize( |