Commit 07657e9
authored
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`.1 parent 2a68c19 commit 07657e9
1 file changed
+11
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
106 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
107 | 114 | | |
108 | 115 | | |
0 commit comments