-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for bitfields #585
Conversation
"u64" | ||
} | ||
else { | ||
truncated = Some("Bit fields too large".to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inconsistency between this case and IsIncomplete implementation will cause problems for any other struct that contains truncated one. But if such large bitfields don't happen in practice then LGTM.
I'm not sure this is correct with all C compilers, but I guess for the majority of cases it will work. We have the ABI tests for checking struct sizes at least. You can remove the hack that is currently in gir for (IIRC) GClosure then. Or GHookList or something :) |
Yes, this definitely needs some ABI checks. Sadly, those run on AppVeyor don't have any bitfields, but I can later test this with x86_64-unknown-linux-gnu target. |
Using large integer types may increase alignment:
#[repr(C)]
#[derive(Copy, Clone)]
pub struct GDate {
pub julian_days: u64,
} struct _GDate
{
guint julian_days : 32; /* julian days representation - we use a
* bitfield hoping that 64 bit platforms
* will pack this whole struct in one big
* int
*/
guint julian : 1; /* julian is valid */
guint dmy : 1; /* dmy is valid */
/* DMY representation */
guint day : 6;
guint month : 4;
guint year : 16;
}; |
} | ||
else if bits <= 64 { | ||
"u64" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better stop on 8, 16, 32 bit and create field?
Not sure how you plan decombining it actually.
Further mismatches in Gtk+:
#[repr(C)]
#[derive(Copy, Clone)]
pub struct GtkTableRowCol {
pub requisition: u16,
pub allocation: u16,
pub spacing: u16,
pub need_expand: u8,
} struct _GtkTableRowCol
{
guint16 requisition;
guint16 allocation;
guint16 spacing;
guint need_expand : 1;
guint need_shrink : 1;
guint expand : 1;
guint shrink : 1;
guint empty : 1;
}; The case GtkTextAppearance and GtkTextAttributes is much more complicated. |
I would expect the size/alignment to also differ between compilers, especially MSVC. What did you test @tmiasko? I also don't understand why the alignment for Someone please read what the C standard has to say about this in bitfields, but from my memory all this is implementation defined. |
I tested this with x86_64-unknown-linux-gnu. I could probably test further From System V Application Binary Interface AMD64 Architecture Processor Supplement:
Yes, all this is implementation defined, so in case there are differences |
Probably have to wait for rust-lang/rfcs#314 before we can do something meaningful here |
I started the work to compute the alignment. |
I think you have linked to what will become Gtk+4. In Gtk+3 they are indeed This does pose some additional challenges as you say, but we can also make some For example, assuming that first bitfield is always placed in a new storage |
I'll close this for now. |
No description provided.