Change to &raw#102
Conversation
examples/tlsf_integration_test.rs
Outdated
| let mut heap_mem: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE]; | ||
| let local_heap: Heap = Heap::empty(); | ||
| unsafe { local_heap.init(heap_mem.as_ptr() as usize, HEAP_SIZE) } | ||
| unsafe { local_heap.init(&raw mut heap_mem as usize, HEAP_SIZE) } |
There was a problem hiding this comment.
this one doesn't need &raw because it's not a static mut, it's just a plain old array.
Arguably the old code is wrong as well because it used .as_ptr() which gives you a pointer that you're not allowed to use for writing. Could you change this to .as_mut_ptr()?
(and why is heap init taking the address as usize 😭 it should take a pointer. maybe we should change it)
There was a problem hiding this comment.
Updated this, I agree that this should take a pointer.
To give some background on how I came across this issue, I used .as_ptr() and the resulting code ended up being optimized in such a way that it was broken. When using .as_mut_ptr() it would compile and run no problem. I suspect this is to do with provenance and LLVM pulling some tricks because it thinks that memory will never be modified.
Requiring that the pointer be mutable using the type system would remove this kind of issue but it would obviously alter the API.
Docs for .as_ptr() and .as_mut_ptr(). Note the return types of both and that .as_ptr() explicitly returns a const.
Related RFC:
https://rust-lang.github.io/rfcs/3559-rust-has-provenance.html
Thanks for the review!
Closes #101
Replaces macro usage and updates docs.
Note this does not touch the crate itself, just docs and examples.
Thanks.