On Thu, Feb 15, 2024 at 12:23:12PM -0500, Brian Foster wrote:
> I can't really comment on the Rust context, but could you add a comment
> to explain why the ifdef is here? I.e., even something as simple as
> "Rust disallows packed and aligned on ..." is useful.
> 
> Brian

I'll work on a v2 with an explanatory comment.

> Also out of curiosity, is there some reason these two attributes
> together presumably isn't a problem for LE?

The root of the problem is that rustc won't compile types with both
packed and align attributes. However, rust-bindgen tries to be helpful
and when generating Rust bindings for C types with both attrs, will
avoid placing one or the other attribute if it can do so without
changing the type's layout.

For LE, the "packed" attr is unneeded because the struct is "naturally
packed", but the "align(8)" attr is needed because the struct's natural
alignment is 4.

For BE, the "packed" attr is needed because there are some members that
are not aligned (e.g., `size` has as offset of 23 but wants to be at
24), so rust-bindgen cannot omit it. Thus we have to remove "align(8)"
to get a type that rustc can compile.

- Thomas Bertschinger

Reply via email to