Skip to content

Commit

Permalink
Allow blocklisting anonymous enums
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwe committed Jan 6, 2025
1 parent 59a43e1 commit 05c2885
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions bindgen-tests/tests/headers/blocklist-anon-enum.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: --blocklist-item 'SHOULD_BE_BLOCKED.*'

enum {
SHOULD_BE_BLOCKED_1,
SHOULD_BE_BLOCKED_2,
SHOULD_BE_BLOCKED_3
};
6 changes: 6 additions & 0 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3595,6 +3595,12 @@ impl CodeGenerator for Enum {
let layout = enum_ty.layout(ctx);
let variation = self.computed_enum_variation(ctx, item);

// blocklist anonymous enums based on variants.
if enum_ty.name().is_none() && self.is_matching_enum(ctx, &ctx.options().blocklisted_items, item) {
debug!("Blocklisting anonymous enum.");
return;
}

let repr_translated;
let repr = match self.repr().map(|repr| ctx.resolve_type(repr)) {
Some(repr)
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/enum_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl Enum {
Ok(Enum::new(repr, variants))
}

fn is_matching_enum(
pub(crate) fn is_matching_enum(
&self,
ctx: &BindgenContext,
enums: &RegexSet,
Expand Down

0 comments on commit 05c2885

Please sign in to comment.