[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZqulDQx8Rid0F6fu@pollux>
Date: Thu, 1 Aug 2024 17:09:01 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: ojeda@...nel.org, alex.gaynor@...il.com, wedsonaf@...il.com,
boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me, a.hindborg@...sung.com,
akpm@...ux-foundation.org, daniel.almeida@...labora.com,
faith.ekstrand@...labora.com, boris.brezillon@...labora.com,
lina@...hilina.net, mcanal@...lia.com, zhiw@...dia.com,
acurrid@...dia.com, cjia@...dia.com, jhubbard@...dia.com,
airlied@...hat.com, ajanulgu@...hat.com, lyude@...hat.com,
linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org,
linux-mm@...ck.org
Subject: Re: [PATCH v3 01/25] rust: alloc: add `Allocator` trait
On Thu, Aug 01, 2024 at 04:25:25PM +0200, Alice Ryhl wrote:
> On Thu, Aug 1, 2024 at 2:27 PM Danilo Krummrich <dakr@...nel.org> wrote:
> >
> > On Thu, Aug 01, 2024 at 10:19:41AM +0200, Alice Ryhl wrote:
> > > On Thu, Aug 1, 2024 at 2:07 AM Danilo Krummrich <dakr@...nel.org> wrote:
> > > > + /// Free an existing memory allocation.
> > > > + ///
> > > > + /// # Safety
> > > > + ///
> > > > + /// `ptr` must point to an existing and valid memory allocation created by this `Allocator`
> > > > + /// instance.
> > > > + unsafe fn free(ptr: NonNull<u8>) {
> > > > + // SAFETY: `ptr` is guaranteed to be previously allocated with this `Allocator` or NULL.
> > > > + // Calling `realloc` with a buffer size of zero, frees the buffer `ptr` points to.
> > > > + let _ = unsafe { Self::realloc(Some(ptr), Layout::new::<()>(), Flags(0)) };
> > > > + }
> > >
> > > At the very least, the provided implementation of `free` changes the
> > > alignment when it calls `realloc`.
> >
> > Yes, I think that's fine though. Hopefully no one attempts to use the memory
> > anymore once `free` is being called.
>
> Sure, but if you require the alignment to remain constant throughout
> calls to realloc, then you have to word it in a way that allows a
> different alignment when the new size is zero.
Agreed, this case should be covered once I documented that the new alignment
must be equal to or smaller than the old alignment.
>
> Alice
>
Powered by blists - more mailing lists