diff options
-rw-r--r-- | .github/ISSUE_TEMPLATE.md | 26 | ||||
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/ir/context.rs | 15 | ||||
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | tests/expectations/tests/issue-677-nested-ns-specifier.rs | 20 | ||||
-rw-r--r-- | tests/headers/issue-677-nested-ns-specifier.hpp | 5 |
7 files changed, 49 insertions, 20 deletions
diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 68dfb68e..33b65a20 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,14 +1,12 @@ ### Input C/C++ Header ```C++ -// Insert your (minimal) C/C++ header here +// Insert your (minimal) C/C++ header here. ``` ### Bindgen Invokation -<!-- - -Place either the `bindgen::Builder` **OR** the command line flags used here. +<!-- Place either the `bindgen::Builder` or the command line flags used here. --> ```Rust bindgen::Builder::default() @@ -17,26 +15,22 @@ bindgen::Builder::default() .unwrap() ``` -OR +or ``` $ bindgen input.h --whatever --flags ``` ---> - ### Actual Results -<!-- - ``` -Insert panic message and backtrace here. +Insert panic message and backtrace (set the `RUST_BACKTRACE=1` env var) here. ``` and/or ```rust -// Insert the (incorrect) generated bindings here +// Insert the (incorrect/buggy) generated bindings here ``` and/or @@ -45,19 +39,21 @@ and/or Insert compilation errors generated when compiling the bindings with rustc here ``` ---> - ### Expected Results <!-- Replace this with a description of what you expected instead of the actual results. The more precise, the better! For example, if a struct in the generated -bindings is missing a field that exists in the C/C++ struct, not that here. +bindings is missing a field that exists in the C/C++ struct, note that here. --> ### `RUST_LOG=bindgen` Output +<details> + ``` -Insert debug logging when running bindgen with the RUST_LOG=bindgen environment +Insert debug logging when running bindgen with the `RUST_LOG=bindgen` environment variable set. ``` + +</details> @@ -14,7 +14,6 @@ dependencies = [ "quasi 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "quasi_codegen 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", "shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -46,7 +46,6 @@ cexpr = "0.2" cfg-if = "0.1.0" clang-sys = { version = "0.15", features = ["runtime", "clang_3_9"] } lazy_static = "0.2.1" -rustc-serialize = "0.3.19" syntex_syntax = "0.58" regex = "0.2" # This kinda sucks: https://github.com/rust-lang/cargo/issues/1982 diff --git a/src/ir/context.rs b/src/ir/context.rs index 4d4a78d2..3d3e9fcd 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1264,7 +1264,7 @@ impl<'ctx> BindgenContext<'ctx> { } /// Tokenizes a namespace cursor in order to get the name and kind of the - /// namespace, + /// namespace. fn tokenize_namespace(&self, cursor: &clang::Cursor) -> (Option<String>, ModuleKind) { @@ -1280,6 +1280,7 @@ impl<'ctx> BindgenContext<'ctx> { let mut kind = ModuleKind::Normal; let mut found_namespace_keyword = false; let mut module_name = None; + while let Some(token) = iter.next() { match &*token.spelling { "inline" => { @@ -1287,7 +1288,17 @@ impl<'ctx> BindgenContext<'ctx> { assert!(kind != ModuleKind::Inline); kind = ModuleKind::Inline; } - "namespace" => { + // The double colon allows us to handle nested namespaces like + // namespace foo::bar { } + // + // libclang still gives us two namespace cursors, which is cool, + // but the tokenization of the second begins with the double + // colon. That's ok, so we only need to handle the weird + // tokenization here. + // + // Fortunately enough, inline nested namespace specifiers aren't + // a thing, and are invalid C++ :) + "namespace" | "::" => { found_namespace_keyword = true; } "{" => { diff --git a/src/main.rs b/src/main.rs index 2ba2b139..603a6555 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ extern crate env_logger; extern crate log; extern crate clang_sys; extern crate clap; -extern crate rustc_serialize; use bindgen::clang_version; use std::env; diff --git a/tests/expectations/tests/issue-677-nested-ns-specifier.rs b/tests/expectations/tests/issue-677-nested-ns-specifier.rs new file mode 100644 index 00000000..44d9904a --- /dev/null +++ b/tests/expectations/tests/issue-677-nested-ns-specifier.rs @@ -0,0 +1,20 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub mod root { + #[allow(unused_imports)] + use self::super::root; + pub mod foo { + #[allow(unused_imports)] + use self::super::super::root; + pub mod bar { + #[allow(unused_imports)] + use self::super::super::super::root; + pub type bar = ::std::os::raw::c_int; + } + } +} diff --git a/tests/headers/issue-677-nested-ns-specifier.hpp b/tests/headers/issue-677-nested-ns-specifier.hpp new file mode 100644 index 00000000..ef2cea82 --- /dev/null +++ b/tests/headers/issue-677-nested-ns-specifier.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --enable-cxx-namespaces -- -std=c++14 + +namespace foo::bar { + typedef int bar; +} |