Commit 192fd6a
Support nested flexible array members
Add support for structs where the last field is itself a struct
containing a flexible array member (FAM). For example:
struct Name {
int count;
char name[];
};
struct Field {
int id;
struct Name name; // Last field has a FAM
};
The Name struct is generated with a generic FAM parameter:
pub struct Name<FAM: ?Sized = [c_char; 0]> {
pub count: c_int,
pub name: FAM,
}
And Field propagates this parameter to its nested field:
pub struct Field<FAM: ?Sized = [c_char; 0]> {
pub id: c_int,
pub name: Name<FAM>,
}
For packed structs, the nested FAM field is wrapped in ManuallyDrop
since packed structs cannot directly contain DST fields:
#[repr(C, packed)]
pub struct FieldPacked<FAM: ?Sized = [c_char; 0]> {
pub id: c_int,
pub name: ::std::mem::ManuallyDrop<Name<FAM>>,
}
Implementation:
- Enhanced flex_array_member() in ir/comp.rs to recursively detect
when a struct's last field is a compound type with its own FAM
- Updated field code generation to parameterize nested FAM field
types with <FAM> and wrap in ManuallyDrop for packed structs
- Added test cases for nested FAMs in both regular and packed structs
Related to #29361 parent ac3bc6e commit 192fd6a
File tree
4 files changed
+333
-4
lines changed- bindgen-tests/tests
- expectations/tests
- headers
- bindgen
- codegen
- ir
4 files changed
+333
-4
lines changedLines changed: 271 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1592 | 1592 | | |
1593 | 1593 | | |
1594 | 1594 | | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
1595 | 1617 | | |
1596 | 1618 | | |
1597 | 1619 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
790 | 790 | | |
791 | 791 | | |
792 | 792 | | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
793 | 797 | | |
794 | 798 | | |
795 | 799 | | |
| |||
799 | 803 | | |
800 | 804 | | |
801 | 805 | | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
806 | 823 | | |
807 | 824 | | |
808 | 825 | | |
| |||
0 commit comments