From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: Alice Ryhl <aliceryhl@google.com>,
akpm@linux-foundation.org, ojeda@kernel.org,
alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu,
abdiel.janulgue@gmail.com, acourbot@nvidia.com, jgg@ziepe.ca,
lyude@redhat.com, robin.murphy@arm.com,
daniel.almeida@collabora.com, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] rust: dma: implement DataDirection
Date: Mon, 18 Aug 2025 13:56:33 +0200 [thread overview]
Message-ID: <CANiq72ncROtm8Qkv_W95_Gigb1aVhq85zZ37itN-jHGDgTUJMA@mail.gmail.com> (raw)
In-Reply-To: <DC5INEG2DXU5.DM4JIICEQ2PC@kernel.org>
On Mon, Aug 18, 2025 at 1:27 PM Danilo Krummrich <dakr@kernel.org> wrote:
>
> Does bindgen ever pick another type than i32 for C enums? If so, it'd be a
> downside that we'd have to mess with the type either in the `repr` or by casting
> the variants.
Yes, it can easily pick `u32` -- the variants are always `int` in C,
but the actual enum can be a type compatible with int, unsigned or
char; and `bindgen` generates each variant with a type alias to the
underlying type of the `enum`, not `int`.
So e.g. for
enum uint_enum { uint_enum_a, uint_enum_b };
enum int_enum { int_enum_a = -1, int_enum_b };
_Static_assert(_Generic(uint_enum_a, int: 1, default: 0), "");
_Static_assert(_Generic(uint_enum_b, int: 1, default: 0), "");
_Static_assert(_Generic(int_enum_a, int: 1, default: 0), "");
_Static_assert(_Generic(int_enum_b, int: 1, default: 0), "");
_Static_assert(_Generic((enum uint_enum)0, unsigned: 1, default: 0), "");
_Static_assert(_Generic((enum int_enum)0, int: 1, default: 0), "");
you get:
pub const uint_enum_uint_enum_a: uint_enum = 0;
pub const uint_enum_uint_enum_b: uint_enum = 1;
pub type uint_enum = ffi::c_uint;
pub const int_enum_int_enum_a: int_enum = -1;
pub const int_enum_int_enum_b: int_enum = 0;
pub type int_enum = ffi::c_int;
Then there is this issue I reported to be careful about, which can
change it back to `i32` if there is a forward reference:
https://github.com/rust-lang/rust-bindgen/issues/3179
I hope that helps.
Cheers,
Miguel
next prev parent reply other threads:[~2025-08-18 11:56 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-15 17:10 [PATCH 0/4] Rust infrastructure for sg_table and scatterlist Danilo Krummrich
2025-08-15 17:10 ` [PATCH 1/4] rust: dma: implement DataDirection Danilo Krummrich
2025-08-18 9:34 ` Alice Ryhl
2025-08-18 11:27 ` Danilo Krummrich
2025-08-18 11:56 ` Miguel Ojeda [this message]
2025-08-18 12:24 ` Miguel Ojeda
2025-08-18 20:42 ` Danilo Krummrich
2025-08-18 12:22 ` Alice Ryhl
2025-08-18 12:57 ` Danilo Krummrich
2025-08-18 14:00 ` Alice Ryhl
2025-08-18 17:23 ` Danilo Krummrich
2025-08-18 18:47 ` Alice Ryhl
2025-08-18 21:03 ` Danilo Krummrich
2025-08-20 13:17 ` Daniel Almeida
2025-08-20 13:40 ` Danilo Krummrich
2025-08-15 17:10 ` [PATCH 2/4] rust: scatterlist: Add type-state abstraction for sg_table Danilo Krummrich
2025-08-18 9:52 ` Alice Ryhl
2025-08-18 11:16 ` Danilo Krummrich
2025-08-18 12:21 ` Danilo Krummrich
2025-08-18 13:12 ` Danilo Krummrich
2025-08-18 12:27 ` Alice Ryhl
2025-08-18 12:37 ` Danilo Krummrich
2025-08-20 17:08 ` Daniel Almeida
2025-08-20 18:59 ` Danilo Krummrich
2025-08-15 17:10 ` [PATCH 3/4] samples: rust: dma: add sample code for SGTable Danilo Krummrich
2025-08-15 17:10 ` [PATCH 4/4] MAINTAINERS: rust: dma: add scatterlist files Danilo Krummrich
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=CANiq72ncROtm8Qkv_W95_Gigb1aVhq85zZ37itN-jHGDgTUJMA@mail.gmail.com \
--to=miguel.ojeda.sandonis@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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 NNTP newsgroup(s).