Re: [RFC PATCH] rust: alloc: pass `old_layout` to `Allocator`

Alice Ryhl
2024-09-23T13:56:43Z

On Sat, Sep 21, 2024 at 5:33 PM Danilo Krummrich <dakr@kernel.org> wrote:
> @@ -84,11 +92,18 @@ unsafe fn call(
> &self,
> ptr: Option<NonNull<u8>>,
> layout: Layout,
> + old_layout: Layout,
> flags: Flags,
> ) -> Result<NonNull<[u8]>, AllocError> {
> let size = aligned_size(layout);
> let ptr = match ptr {
> - Some(ptr) => ptr.as_ptr(),
> + Some(ptr) => {
> + if old_layout.size() == 0 {
> + ptr::null()
> + } else {
> + ptr.as_ptr()
> + }
> + }

This is making Allocator work with zero-sized types, which deviates
from std. We should not do that without a reason. What is the reason?

Alice