From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: Obei Sideg <linux@obei.io>
Cc: "a.hindborg@samsung.com" <a.hindborg@samsung.com>,
"alex.gaynor@gmail.com" <alex.gaynor@gmail.com>,
"aliceryhl@google.com" <aliceryhl@google.com>,
"benno.lossin@proton.me" <benno.lossin@proton.me>,
"bjorn3_gh@protonmail.com" <bjorn3_gh@protonmail.com>,
"boqun.feng@gmail.com" <boqun.feng@gmail.com>,
"gary@garyguo.net" <gary@garyguo.net>,
"ojeda@kernel.org" <ojeda@kernel.org>,
"rust-for-linux@vger.kernel.org"
<rust-for-linux@vger.kernel.org>,
"wedsonaf@gmail.com" <wedsonaf@gmail.com>,
Trevor Gross <tmgross@umich.edu>
Subject: Re: [PATCH v6] rust: types: Add `try_from_foreign()` method
Date: Sun, 25 Feb 2024 21:28:12 +0100 [thread overview]
Message-ID: <CANiq72kTNd=CehhvfFWUJFZP-J9KcfTi95+=_3KLLyk7xpX_Tg@mail.gmail.com> (raw)
In-Reply-To: <0100018d73205a53-b7739657-2731-4164-b940-c633200a221c-000000@email.amazonses.com>
On Sun, Feb 4, 2024 at 8:58 AM Obei Sideg <linux@obei.io> wrote:
>
> Currently `ForeignOwnable::from_foreign()` only works for non-null
> pointers for the existing impls (e.g. Box, Arc). It may create a few
> duplicate code like:
>
> ```rust
> // `p` is a maybe null pointer
> if p.is_null() {
> None
> } else {
> unsafe { Some(Self::from_foreign(ptr)) }
> }
> ```
>
> Add a `try_from_foreign()` method that will return `None` if `ptr`
> is null, otherwise return `Some(from_foreign(ptr))`.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1057
> Signed-off-by: Obei Sideg <linux@obei.io>
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
> Reviewed-by: Trevor Gross <tmgross@umich.edu>
Applied to `rust-next` -- thanks everyone!
[ Fixed intra-doc links, improved `SAFETY` comment and reworded commit. ]
Cheers,
Miguel
next prev parent reply other threads:[~2024-02-25 20:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240129064519.7137-1-linux@obei.io>
2024-01-29 6:45 ` [PATCH v6] rust: types: Add `try_from_foreign()` method Obei Sideg
2024-01-29 15:19 ` Greg KH
2024-02-01 1:54 ` Trevor Gross
[not found] ` <20240204075827.10747-1-linux@obei.io>
2024-02-04 7:58 ` Obei Sideg
2024-02-04 8:20 ` Boqun Feng
2024-02-25 20:28 ` Miguel Ojeda [this message]
[not found] ` <20240204101049.41101-1-linux@obei.io>
2024-02-04 10:10 ` Obei Sideg
2024-02-04 16:34 ` Miguel Ojeda
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='CANiq72kTNd=CehhvfFWUJFZP-J9KcfTi95+=_3KLLyk7xpX_Tg@mail.gmail.com' \
--to=miguel.ojeda.sandonis@gmail.com \
--cc=a.hindborg@samsung.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux@obei.io \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=wedsonaf@gmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).