Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: unaligned read for Metal buffers (#882)
After Rust 1.77 `u128` starts requiring 16 bytes aligned values. This breaks Metal, where `retrieve_contents` assumed it could just cast the pointer and treat it as a slice. Instead, we need to assume no alignment by doing the following: 1. Read the `i-th` element from the buffer with `ptr.add(i).read_unaligned()`; 2. `clone` the read value, as the bitwise copy may cause aliasing otherwise; 3. `push` the `clone`d value into the vector; 4. `mem::forget` the element we read to avoid calling its `drop` implementation twice, one for the copy and one for the `Buffer`.
- Loading branch information