diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 38c5849776..f042fe9380 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 { + 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 1299337bdc..a20cf4b7ad 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 diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 8374e2084a..45cf9bca5d 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::()) +} diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index cc9b8b41dd..026c2ff948 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 {