Skip to content

Commit dd7eb05

Browse files
committed
move input_header_contents to BindgenOptions
1 parent 179f4e6 commit dd7eb05

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

bindgen/clang.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ pub struct UnsavedFile {
18231823

18241824
impl UnsavedFile {
18251825
/// Construct a new unsaved file with the given `name` and `contents`.
1826-
pub fn new(name: &str, contents: &str) -> UnsavedFile {
1826+
pub fn new(name: String, contents: String) -> UnsavedFile {
18271827
let name = CString::new(name).unwrap();
18281828
let contents = CString::new(contents).unwrap();
18291829
let x = CXUnsavedFile {

bindgen/lib.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ impl Default for CodegenConfig {
225225
#[derive(Debug, Default)]
226226
pub struct Builder {
227227
options: BindgenOptions,
228-
// Tuples of unsaved file contents of the form (name, contents).
229-
input_header_contents: Vec<(String, String)>,
230228
}
231229

232230
/// Construct a new [`Builder`](./struct.Builder.html).
@@ -690,7 +688,8 @@ impl Builder {
690688
.to_str()
691689
.expect("Cannot convert current directory name to string")
692690
.to_owned();
693-
self.input_header_contents
691+
self.options
692+
.input_header_contents
694693
.push((absolute_path, contents.into()));
695694
self
696695
}
@@ -1572,11 +1571,11 @@ impl Builder {
15721571
.flat_map(|header| ["-include".into(), header.to_string()]),
15731572
);
15741573

1575-
let input_unsaved_files = self
1576-
.input_header_contents
1577-
.into_iter()
1578-
.map(|(name, contents)| clang::UnsavedFile::new(&name, &contents))
1579-
.collect::<Vec<_>>();
1574+
let input_unsaved_files =
1575+
std::mem::take(&mut self.options.input_header_contents)
1576+
.into_iter()
1577+
.map(|(name, contents)| clang::UnsavedFile::new(name, contents))
1578+
.collect::<Vec<_>>();
15801579

15811580
Bindings::generate(self.options, input_unsaved_files)
15821581
}
@@ -1613,7 +1612,7 @@ impl Builder {
16131612

16141613
// For each input header content, add a prefix line of `#line 0 "$name"`
16151614
// followed by the contents.
1616-
for &(ref name, ref contents) in &self.input_header_contents {
1615+
for &(ref name, ref contents) in &self.options.input_header_contents {
16171616
is_cpp |= file_is_cpp(name);
16181617

16191618
wrapper_contents.push_str("#line 0 \"");
@@ -1970,6 +1969,9 @@ struct BindgenOptions {
19701969
/// The input header files.
19711970
input_headers: Vec<String>,
19721971

1972+
/// Tuples of unsaved file contents of the form (name, contents).
1973+
input_header_contents: Vec<(String, String)>,
1974+
19731975
/// A user-provided visitor to allow customizing different kinds of
19741976
/// situations.
19751977
parse_callbacks: Option<Rc<dyn callbacks::ParseCallbacks>>,
@@ -2219,6 +2221,7 @@ impl Default for BindgenOptions {
22192221
module_lines: HashMap::default(),
22202222
clang_args: vec![],
22212223
input_headers: vec![],
2224+
input_header_contents: Default::default(),
22222225
parse_callbacks: None,
22232226
codegen_config: CodegenConfig::all(),
22242227
conservative_inline_namespaces: false,

0 commit comments

Comments
 (0)