Re: [PATCH v3 09/10] rust: list: support heterogeneous lists
From: Alice Ryhl
Date: Thu Aug 01 2024 - 08:34:04 EST
On Thu, Aug 1, 2024 at 12:50 PM Benno Lossin <benno.lossin@xxxxxxxxx> wrote:
>
> On 01.08.24 11:38, Alice Ryhl wrote:
> > On Thu, Aug 1, 2024 at 11:24 AM Benno Lossin <benno.lossin@xxxxxxxxx> wrote:
> >>
> >> On 23.07.24 10:22, Alice Ryhl wrote:
> >>> @@ -181,6 +185,47 @@ unsafe fn from_fields(me: *mut ListLinksFields) -> *mut Self {
> >>> }
> >>> }
> >>>
> >>> +/// Similar to [`ListLinks`], but also contains a pointer to the full value.
> >>> +///
> >>> +/// This type can be used instead of [`ListLinks`] to support lists with trait objects.
> >>> +#[repr(C)]
> >>> +pub struct ListLinksSelfPtr<T: ?Sized, const ID: u64 = 0> {
> >>> + /// The `ListLinks` field inside this value.
> >>> + ///
> >>> + /// This is public so that it can be used with `impl_has_list_links!`.
> >>> + pub inner: ListLinks<ID>,
> >>> + self_ptr: UnsafeCell<MaybeUninit<*const T>>,
> >>
> >> Why do you need `MaybeUninit`?
> >
> > Right now the constructor initializes it to MaybeUninit::zeroed().
> > What would you initialize it to without MaybeUninit? Remember that the
> > vtable pointer in a fat pointer has strict validity requirements.
>
> Oh... I forgot about that, can you add a comment about that? Also why
> not use `Opaque` in that case then?
It used to just be UnsafeCell, but then I tried it in miri and found
out about the issue and added MaybeUninit. But I can make it use
Opaque instead.
Alice