Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// bindgen-flags: --opaque-type WINDOW --opaque-type-alias-as-c-void

typedef struct _WINDOW WINDOW;

int wgetch(WINDOW *win);
6 changes: 5 additions & 1 deletion bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,11 @@ impl CodeGenerator for Type {
let is_opaque = item.is_opaque(ctx, &());
let inner_rust_type = if is_opaque {
outer_params = vec![];
self.to_opaque(ctx, item)
if ctx.options().opaque_type_alias_as_c_void {
helpers::ast_ty::c_void(ctx)
} else {
self.to_opaque(ctx, item)
}
} else {
// Its possible that we have better layout information than
// the inner type does, so fall back to an opaque blob based
Expand Down
5 changes: 5 additions & 0 deletions bindgen/options/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ struct BindgenCommand {
/// Mark TYPE as opaque.
#[arg(long, value_name = "TYPE")]
opaque_type: Vec<String>,
/// Emit opaque type aliases as `c_void` instead of a sized byte blob.
#[arg(long)]
opaque_type_alias_as_c_void: bool,
/// Write Rust bindings to OUTPUT.
#[arg(long, short, value_name = "OUTPUT")]
output: Option<String>,
Expand Down Expand Up @@ -649,6 +652,7 @@ where
no_include_path_detection,
fit_macro_constant_types,
opaque_type,
opaque_type_alias_as_c_void,
output,
raw_line,
module_raw_line,
Expand Down Expand Up @@ -964,6 +968,7 @@ where
generate_cstr,
block_extern_crate,
opaque_type,
opaque_type_alias_as_c_void,
raw_line,
use_core => |b, _| b.use_core(),
distrust_clang_mangling => |b, _| b.trust_clang_mangling(false),
Expand Down
18 changes: 18 additions & 0 deletions bindgen/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,24 @@ options! {
},
as_args: "--opaque-type",
},
/// Whether to emit opaque type aliases as `c_void` instead of a sized byte blob.
opaque_type_alias_as_c_void: bool {
methods: {
/// Set whether opaque type aliases should be emitted as `c_void` instead of a
/// sized byte blob (e.g. `[u64; 11usize]`).
///
/// This is useful for types that are only ever handled behind a pointer (e.g.
/// `WINDOW` in curses), where communicating "this can't be read from or written to
/// directly" is more valuable than preserving the type's size and alignment.
///
/// This option is disabled by default.
pub fn opaque_type_alias_as_c_void(mut self, doit: bool) -> Self {
self.options.opaque_type_alias_as_c_void = doit;
self
}
},
as_args: "--opaque-type-alias-as-c-void",
},
/// The explicit `rustfmt` path.
rustfmt_path: Option<PathBuf> {
methods: {
Expand Down
Loading