as_ptr() returns a *mut _ pointer. This isn't an error by itself, but under Rust's memory model, this pointer is derived from shared/immutable &self, and therefore doesn't have permission to mutate self, so the mut of the pointer is misleading.
|
fn as_ptr(&self) -> *mut Self::CType { |
I assume this is for convenience, because C APIs aren't diligent about const vs mut distinction. However, this is a gotcha, because C APIs that take *mut may actually mutate the object, and that is UB from Rust's perspective.
Could you add .as_mut_ptr() that takes &mut self to provide a pointer safe for mutation?
as_ptr()returns a*mut _pointer. This isn't an error by itself, but under Rust's memory model, this pointer is derived from shared/immutable&self, and therefore doesn't have permission to mutateself, so themutof the pointer is misleading.foreign-types/foreign-types-shared/src/lib.rs
Line 89 in 393f6ab
I assume this is for convenience, because C APIs aren't diligent about
constvsmutdistinction. However, this is a gotcha, because C APIs that take*mutmay actually mutate the object, and that is UB from Rust's perspective.Could you add
.as_mut_ptr()that takes&mut selfto provide a pointer safe for mutation?