Skip to content

Commit

Permalink
Introduce btf::types::Enum::is_signed() method
Browse files Browse the repository at this point in the history
Add the btf::types::Enum::is_signed() method exposing the fact whether
an enum is signed or not. This is similar to other existing methods such
as btf::types::Func::linkage().

Signed-off-by: Daniel Müller <deso@posteo.net>
  • Loading branch information
d-e-s-o committed Dec 11, 2024
1 parent 2fc9d4f commit e1bdb6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 1 addition & 9 deletions libbpf-cargo/src/gen/btf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,15 +797,7 @@ impl<'s> GenBtf<'s> {
};

let enum_name = self.anon_types.type_name_or_anon(&t);

let mut signed = "u";
for value in t.iter() {
if value.value < 0 {
signed = "i";
break;
}
}

let signed = if t.is_signed() { "i" } else { "u" };
let mut first_field = None;

writeln!(def, r#"#[derive(Debug, Copy, Clone, Eq, PartialEq)]"#)?;
Expand Down
9 changes: 9 additions & 0 deletions libbpf-rs/src/btf/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ gen_collection_concrete_type! {
}
}

impl Enum<'_> {
/// Check whether the enum is signed or not.
#[inline]
pub fn is_signed(&self) -> bool {
self.kind_flag()
}
}


// Fwd
gen_fieldless_concrete_type! {
/// A forward declared C type.
Expand Down

0 comments on commit e1bdb6a

Please sign in to comment.