Skip to content

Commit fd0eabd

Browse files
d-e-s-odanielocfb
authored andcommitted
Make padding fields of generated types pub
It arguably makes very little sense for all "regular" fields in libbpf-cargo generated types to be publicly accessible, while padding fields are not. Mark them as public as well. That's similar to what cbindgen does, with its named padding members. Closes: #421 Signed-off-by: Daniel Müller <deso@posteo.net>
1 parent 96c5957 commit fd0eabd

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

libbpf-cargo/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Unreleased
2+
----------
3+
- Adjusted named padding members in generated types to have `pub` visibility
4+
5+
16
0.21.0
27
------
38
- Adjusted skeleton generation code to ensure implementation of `libbpf-rs`'s

libbpf-cargo/src/gen/btf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl<'s> GenBtf<'s> {
345345
)?;
346346

347347
if padding != 0 {
348-
agg_content.push(format!(r#" __pad_{offset}: [u8; {padding}],"#,));
348+
agg_content.push(format!(r#" pub __pad_{offset}: [u8; {padding}],"#,));
349349

350350
impl_default.push(format!(
351351
r#" __pad_{offset}: [u8::default(); {padding}]"#,
@@ -395,7 +395,7 @@ impl<'s> GenBtf<'s> {
395395
let struct_size = t.size();
396396
let padding = self.required_padding(offset, struct_size, &t, packed)?;
397397
if padding != 0 {
398-
agg_content.push(format!(r#" __pad_{offset}: [u8; {padding}],"#,));
398+
agg_content.push(format!(r#" pub __pad_{offset}: [u8; {padding}],"#,));
399399
impl_default.push(format!(
400400
r#" __pad_{offset}: [u8::default(); {padding}]"#,
401401
));

libbpf-cargo/src/test.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ struct Foo foo = {1};
12061206
#[repr(C)]
12071207
pub struct Foo {
12081208
pub x: i32,
1209-
__pad_4: [u8; 12],
1209+
pub __pad_4: [u8; 12],
12101210
}
12111211
"#;
12121212

@@ -1307,7 +1307,7 @@ pub struct Foo {
13071307
pub ip: *mut i32,
13081308
pub ipp: *mut *mut i32,
13091309
pub bar: Bar,
1310-
__pad_18: [u8; 6],
1310+
pub __pad_18: [u8; 6],
13111311
pub pb: *mut Bar,
13121312
pub v: u64,
13131313
pub cv: i64,
@@ -1362,7 +1362,7 @@ pub struct Foo {
13621362
pub ip: *mut i32,
13631363
pub ipp: *mut *mut i32,
13641364
pub bar: Bar,
1365-
__pad_84: [u8; 4],
1365+
pub __pad_84: [u8; 4],
13661366
pub pb: *mut Bar,
13671367
pub v: u64,
13681368
pub cv: i64,
@@ -1880,10 +1880,10 @@ struct Foo foo;
18801880
pub struct Foo {
18811881
pub x: i32,
18821882
pub bar: __anon_1,
1883-
__pad_36: [u8; 4],
1883+
pub __pad_36: [u8; 4],
18841884
pub baz: __anon_2,
18851885
pub w: i32,
1886-
__pad_52: [u8; 4],
1886+
pub __pad_52: [u8; 4],
18871887
}
18881888
#[derive(Copy, Clone)]
18891889
#[repr(C)]
@@ -1962,7 +1962,7 @@ pub struct Foo {
19621962
pub bar: __anon_1,
19631963
pub baz: __anon_2,
19641964
pub w: i32,
1965-
__pad_68: [u8; 4],
1965+
pub __pad_68: [u8; 4],
19661966
}
19671967
#[derive(Debug, Default, Copy, Clone)]
19681968
#[repr(C)]
@@ -1974,7 +1974,7 @@ pub struct __anon_1 {
19741974
#[repr(C)]
19751975
pub struct __anon_2 {
19761976
pub w: u32,
1977-
__pad_4: [u8; 4],
1977+
pub __pad_4: [u8; 4],
19781978
pub u: *mut u64,
19791979
}
19801980
"#;
@@ -2027,7 +2027,7 @@ pub struct Foo {
20272027
pub zerg: __anon_2,
20282028
pub baz: __anon_3,
20292029
pub w: i32,
2030-
__pad_76: [u8; 4],
2030+
pub __pad_76: [u8; 4],
20312031
pub flarg: __anon_4,
20322032
}
20332033
#[derive(Debug, Default, Copy, Clone)]
@@ -2058,7 +2058,7 @@ impl Default for __anon_2 {
20582058
#[repr(C)]
20592059
pub struct __anon_3 {
20602060
pub w: u32,
2061-
__pad_4: [u8; 4],
2061+
pub __pad_4: [u8; 4],
20622062
pub u: *mut u64,
20632063
}
20642064
#[derive(Copy, Clone)]
@@ -2202,7 +2202,7 @@ struct bpf_sock_tuple_5_15 tup;
22022202
#[repr(C)]
22032203
pub struct bpf_sock_tuple_5_15 {
22042204
pub __anon_1: __anon_1,
2205-
__pad_36: [u8; 4],
2205+
pub __pad_36: [u8; 4],
22062206
pub __anon_2: __anon_2,
22072207
}
22082208
#[derive(Copy, Clone)]

0 commit comments

Comments
 (0)