summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2020-06-20 18:53:37 +0200
committerGitHub <noreply@github.com>2020-06-20 18:53:37 +0200
commit2ba27bf996e81319385c1b55a09cd4bdd562d353 (patch)
tree070a94b766071ff2f7ec935a1a654db33af4c1f6
parented8d21558009e631323c7d39d86d22b41f007c86 (diff)
parentac17fc0f98d865d31f6b6a0417d5ce36cb14a6d3 (diff)
Permit IntKind::Custom to represent Paths instead of just Idents (#1800)
-rw-r--r--bindgen-integration/build.rs13
-rw-r--r--bindgen-integration/cpp/Test.h1
-rwxr-xr-xbindgen-integration/src/lib.rs8
-rw-r--r--src/codegen/mod.rs5
4 files changed, 22 insertions, 5 deletions
diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs
index 38c58497..f042fe93 100644
--- a/bindgen-integration/build.rs
+++ b/bindgen-integration/build.rs
@@ -1,7 +1,7 @@
extern crate bindgen;
extern crate cc;
-use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks};
+use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks, IntKind};
use bindgen::Builder;
use std::collections::HashSet;
use std::env;
@@ -59,6 +59,17 @@ impl ParseCallbacks for MacroCallback {
_ => {}
}
}
+
+ fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
+ match name {
+ "TESTMACRO_CUSTOMINTKIND_PATH" => Some(IntKind::Custom {
+ name: "crate::MacroInteger",
+ is_signed: true,
+ }),
+
+ _ => None,
+ }
+ }
}
impl Drop for MacroCallback {
diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h
index 1299337b..a20cf4b7 100644
--- a/bindgen-integration/cpp/Test.h
+++ b/bindgen-integration/cpp/Test.h
@@ -5,6 +5,7 @@
#define TESTMACRO_INTEGER 42
#define TESTMACRO_STRING "Hello Preprocessor!"
#define TESTMACRO_STRING_EXPANDED TESTMACRO_STRING
+#define TESTMACRO_CUSTOMINTKIND_PATH 123
#include <cwchar>
diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs
index 8374e208..45cf9bca 100755
--- a/bindgen-integration/src/lib.rs
+++ b/bindgen-integration/src/lib.rs
@@ -11,6 +11,8 @@ use std::os::raw::c_int;
#[allow(unused)]
use bindings::testing::Bar; // This type is generated from module_raw_line.
+type MacroInteger = isize;
+
#[test]
fn test_static_array() {
let mut test = unsafe { bindings::Test_COUNTDOWN.as_ptr() };
@@ -242,3 +244,9 @@ fn test_item_rename() {
member: bindings::bar { foo: 2 },
};
}
+
+#[test]
+fn test_macro_customintkind_path() {
+ let v: &std::any::Any = &bindings::TESTMACRO_CUSTOMINTKIND_PATH;
+ assert!(v.is::<MacroInteger>())
+}
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index cc9b8b41..026c2ff9 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -3328,10 +3328,7 @@ impl TryToRustTy for Type {
IntKind::I64 => Ok(quote! { i64 }),
IntKind::U64 => Ok(quote! { u64 }),
IntKind::Custom { name, .. } => {
- let ident = ctx.rust_ident_raw(name);
- Ok(quote! {
- #ident
- })
+ Ok(proc_macro2::TokenStream::from_str(name).unwrap())
}
IntKind::U128 => {
Ok(if ctx.options().rust_features.i128_and_u128 {