-
-
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,15 +93,50 @@ pub fn from_union(env: &Env, union: &Union) -> Fields { | |
fn analyze_fields(env: &Env, unsafe_access: bool, fields: &[Field]) -> (Vec<FieldInfo>, Option<String>) { | ||
let mut truncated = None; | ||
let mut infos = Vec::with_capacity(fields.len()); | ||
let mut skip_bits = false; | ||
|
||
for field in fields { | ||
let typ = match field_ffi_type(env, field) { | ||
e @ Err(..) => { | ||
truncated = Some(e.into_string()); | ||
break; | ||
for (i, field) in fields.iter().enumerate() { | ||
let typ = | ||
if field.bits.is_some() { | ||
if skip_bits { | ||
continue; | ||
} | ||
skip_bits = true; | ||
let mut bits = 0; | ||
for i in i..fields.len() { | ||
if let Some(bs) = fields[i].bits { | ||
bits += bs; | ||
} | ||
} | ||
let typ = | ||
if bits <= 8 { | ||
"u8" | ||
} | ||
else if bits <= 16 { | ||
"u16" | ||
} | ||
else if bits <= 32 { | ||
"u32" | ||
} | ||
else if bits <= 64 { | ||
"u64" | ||
} | ||
else { | ||
truncated = Some("Bit fields too large".to_string()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
break; | ||
}; | ||
typ.to_string() | ||
} | ||
Ok(typ) => typ, | ||
}; | ||
else { | ||
skip_bits = false; | ||
match field_ffi_type(env, field) { | ||
Err(e) => { | ||
truncated = Some(e.into_string()); | ||
break; | ||
} | ||
Ok(typ) => typ, | ||
} | ||
}; | ||
// Skip private fields from Debug impl. Ignore volatile as well, | ||
// they are usually used as synchronization primites, | ||
// so we wouldn't want to introduce additional reads. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.