lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d264de17-acc2-4345-96be-d5f4bcd3cffc@proton.me>
Date: Mon, 29 Apr 2024 17:44:13 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Gary Guo <gary@...yguo.net>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Wedson Almeida Filho <wedsonaf@...il.com>, Boqun Feng <boqun.feng@...il.com>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Andreas Hindborg <a.hindborg@...sung.com>, Alice Ryhl <aliceryhl@...gle.com>, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] rust: init: add re-initialization functions

On 29.04.24 14:24, Gary Guo wrote:
> On Thu, 25 Apr 2024 21:34:44 +0000
> Benno Lossin <benno.lossin@...ton.me> wrote:
> 
>> Sometimes it is necessary to split allocation and initialization into
>> two steps. One such situation is when reusing existing allocations
>> obtained via `Box::drop_contents`. See [1] for an example.
>> In order to support this use case add `re_[pin_]init` functions to the
>> pin-init API. These functions operate on already allocated smart
>> pointers that contain `MaybeUninit<T>`.
>>
>> Signed-off-by: Benno Lossin <benno.lossin@...ton.me>
>> Link: https://lore.kernel.org/rust-for-linux/f026532f-8594-4f18-9aa5-57ad3f5bc592@proton.me/ [1]
> 
> 
> I don't find the re_init name very intuitive. From the name I would
> imagine these functions be taking a `Box<T>` and a `impl Init<T, E>`,
> dropping the content and produces a `Box<T>` again.

I see your point, but if you look at the link [1] from above, you will
see that there such a function wouldn't be helpful.

> Would it make more to rename the existing functions to have `new` in
> their name to indiciate that they allocate, e.g. `pin_new`, and have
> these functions that only does initialisation `init`/`pin_init`?

Since we now have full control over `Box::new` (via `BoxExt`), we could
also make it take a `impl Init<T, E>` instead of just `T`.
And we could also provide `fn pin(impl PinInit<T>) -> Pin<Box<T>>`.

I would happily rename the `re_init` functions to `init` in that case.
But if we don't want to do the other rename, then I think it would be
confusing to have the functions `new(T)`, `pin(T)`,
`pin_new(impl PinInit<T, E>)` and `new_in_place(impl Init<T, E>)`...

--
Cheers,
Benno


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ