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

From: Alice Ryhl
Date: Mon Sep 23 2024 - 09:56:54 EST


On Sat, Sep 21, 2024 at 5:33 PM Danilo Krummrich <dakr@xxxxxxxxxx> 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