From 844d99d0fb524e3f2494c88250e8574d66ec95d8 Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Fri, 16 Oct 2020 12:47:55 -0400 Subject: [PATCH] Make size_t_is_usize default to true This addresses the first part of #1901. If size_t_is_usize is manually set to false, and bindgen encounters any size_t, then we should also probably test to confirm that size_t is congruent to uintptr_t on the current platform. I'm not sure of the best way to do this check. --- src/lib.rs | 2 +- src/options.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 08b9381785..10ad8a12e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1869,7 +1869,7 @@ impl Default for BindgenOptions { time_phases: false, record_matches: true, rustfmt_bindings: true, - size_t_is_usize: false, + size_t_is_usize: true, rustfmt_configuration_file: None, no_partialeq_types: Default::default(), no_copy_types: Default::default(), diff --git a/src/options.rs b/src/options.rs index a850dbbbfe..cefe6c03be 100644 --- a/src/options.rs +++ b/src/options.rs @@ -408,7 +408,10 @@ where ), Arg::with_name("size_t-is-usize") .long("size_t-is-usize") - .help("Translate size_t to usize."), + .help("Translate size_t to usize. (this is the default)"), + Arg::with_name("size_t-is-not-usize") + .long("size_t-is-not-usize") + .help("Translate size_t to platform-specific lengths."), Arg::with_name("no-rustfmt-bindings") .long("no-rustfmt-bindings") .help("Do not format the generated bindings with rustfmt."), @@ -815,6 +818,16 @@ where if matches.is_present("size_t-is-usize") { builder = builder.size_t_is_usize(true); + if matches.is_present("size_t-is-not-usize") { + return Err(Error::new( + ErrorKind::Other, + "Cannot supply both --size_t-is-usize and --size_t-is-not-usize", + )); + } + } + + if matches.is_present("size_t-is-not-usize") { + builder = builder.size_t_is_usize(false); } let no_rustfmt_bindings = matches.is_present("no-rustfmt-bindings");