From: Boqun Feng <boqun.feng@gmail.com>
To: Benno Lossin <y86-dev@protonmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
patches@lists.linux.dev
Subject: Re: [PATCH v2 3/5] rust: add pin-init API
Date: Wed, 22 Mar 2023 23:30:35 -0700 [thread overview]
Message-ID: <ZBvyCwPcpTnk2R7h@Boquns-Mac-mini.local> (raw)
In-Reply-To: <20230321194934.908891-4-y86-dev@protonmail.com>
On Tue, Mar 21, 2023 at 07:50:00PM +0000, Benno Lossin wrote:
[...]
> +/// # Syntax
> +///
> +/// As already mentioned in the examples above, inside of `pin_init!` a `struct` initializer with
> +/// the following modifications is expected:
> +/// - Fields that you want to initialize in-place have to use `<-` instead of `:`.
> +/// - In front of the initializer you can write `&this in` to have access to a [`NonNull<Self>`]
> +/// pointer named `this` inside of the initializer.
> +///
> +/// For instance:
> +///
> +/// ```rust
> +/// # use kernel::pin_init;
> +/// # use macros::pin_data;
> +/// # use core::{ptr::addr_of_mut, marker::PhantomPinned};
> +/// #[pin_data]
> +/// struct Buf {
> +/// ptr: *mut u8,
> +/// buf: [u8; 64],
Say we have an extra field,
a: u8,
> +/// #[pin]
> +/// pin: PhantomPinned,
> +/// }
> +/// pin_init!(&this in Buf {
> +/// buf: [0; 64],
> +/// ptr: unsafe { addr_of_mut!((*this.as_ptr()).buf).cast() },
And I think we want to disallow:
a: unsafe { (*addr_of!(*this.as_ptr().buf))[0] }
, right? Because we don't want `pin_init!` to provide any initialization
order guarantee? If so, maybe add one or two sentences to call it out.
If not sure, I think we can leave it as it is, until someone really uses
this pattern ;-)
Regards,
Boqun
> +/// pin: PhantomPinned,
> +/// });
> +/// ```
> +///
> +/// [`try_pin_init!`]: kernel::try_pin_init
> +/// [`NonNull<Self>`]: core::ptr::NonNull
> +#[macro_export]
> +macro_rules! pin_init {
> + ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
> + $($fields:tt)*
> + }) => {
> + $crate::try_pin_init!(
> + @this($($this)?),
> + @type_name($t),
> + @typ($t $(<$($generics),*>)?),
> + @fields($($fields)*),
> + @error(::core::convert::Infallible),
> + )
> + };
> +}
> +
[...]
next prev parent reply other threads:[~2023-03-23 6:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 19:49 [PATCH v2 0/5] Rust pin-init API for pinned initialization of structs Benno Lossin
2023-03-21 19:49 ` [PATCH v2 1/5] rust: macros: add `quote!` macro Benno Lossin
2023-03-21 19:49 ` [PATCH v2 2/5] rust: sync: add `assume_init` to `UniqueArc` Benno Lossin
2023-03-21 19:50 ` [PATCH v2 3/5] rust: add pin-init API Benno Lossin
2023-03-23 6:30 ` Boqun Feng [this message]
2023-03-24 8:39 ` Benno Lossin
2023-03-21 19:50 ` [PATCH v2 4/5] rust: init: add common init-helper functions for `Opaque` Benno Lossin
2023-03-21 20:06 ` Boqun Feng
2023-03-22 16:18 ` Benno Lossin
2023-03-21 19:50 ` [PATCH v2 5/5] rust: sync: reduce stack usage of `UniqueArc::try_new_uninit` Benno Lossin
2023-03-22 16:13 ` [PATCH v2 0/5] Rust pin-init API for pinned initialization of structs Benno Lossin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZBvyCwPcpTnk2R7h@Boquns-Mac-mini.local \
--to=boqun.feng@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=patches@lists.linux.dev \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
--cc=y86-dev@protonmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®