You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the alloc crate documentation, Arc::from_raw must be paired with a call to Arc::into_raw, otherwise pointer provenance may be violated (due to the ArcInner layout), and a slightly different issue with Box.
Regarding Arc, it could be solved by imitating Arc::from_raw and using Arc::as_ptr, as using the Deref::deref/AsRef::as_ref implementation might be problematic, but according to this comment, there's some extra ceremony required for Box due to the uniqueness requirement.
I'm proposing to switch the as_ptr method to into_ptr and take Self. With that, Box::into_raw and Arc::into_raw could be used directly. This requires a small extra step to avoid a partial move, and incompatible with !Sized, but the fat pointer metadata can't be stored in *mut c_void anyway, and would require double boxing anyway (e.g. Box<Box<dyn Trait>>).
The text was updated successfully, but these errors were encountered:
…472)
See #471
For Arc, an alternative that doesn't break the existing code would be to leave as_ptr as is and use Arc::as_ptr(self), but the relevant Box methods take by self, so a more thorough analysis is required.
According to the
alloc
crate documentation,Arc::from_raw
must be paired with a call toArc::into_raw
, otherwise pointer provenance may be violated (due to theArcInner
layout), and a slightly different issue withBox
.Regarding
Arc
, it could be solved by imitatingArc::from_raw
and usingArc::as_ptr
, as using theDeref::deref
/AsRef::as_ref
implementation might be problematic, but according to this comment, there's some extra ceremony required forBox
due to the uniqueness requirement.I'm proposing to switch the
as_ptr
method tointo_ptr
and takeSelf
. With that,Box::into_raw
andArc::into_raw
could be used directly. This requires a small extra step to avoid a partial move, and incompatible with!Sized
, but the fat pointer metadata can't be stored in*mut c_void
anyway, and would require double boxing anyway (e.g.Box<Box<dyn Trait>>
).The text was updated successfully, but these errors were encountered: