Skip to content

Commit 2ba27bf

Browse files
authored
Permit IntKind::Custom to represent Paths instead of just Idents (#1800)
2 parents ed8d215 + ac17fc0 commit 2ba27bf

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

bindgen-integration/build.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate bindgen;
22
extern crate cc;
33

4-
use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks};
4+
use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks, IntKind};
55
use bindgen::Builder;
66
use std::collections::HashSet;
77
use std::env;
@@ -59,6 +59,17 @@ impl ParseCallbacks for MacroCallback {
5959
_ => {}
6060
}
6161
}
62+
63+
fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
64+
match name {
65+
"TESTMACRO_CUSTOMINTKIND_PATH" => Some(IntKind::Custom {
66+
name: "crate::MacroInteger",
67+
is_signed: true,
68+
}),
69+
70+
_ => None,
71+
}
72+
}
6273
}
6374

6475
impl Drop for MacroCallback {

bindgen-integration/cpp/Test.h

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define TESTMACRO_INTEGER 42
66
#define TESTMACRO_STRING "Hello Preprocessor!"
77
#define TESTMACRO_STRING_EXPANDED TESTMACRO_STRING
8+
#define TESTMACRO_CUSTOMINTKIND_PATH 123
89

910
#include <cwchar>
1011

bindgen-integration/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use std::os::raw::c_int;
1111
#[allow(unused)]
1212
use bindings::testing::Bar; // This type is generated from module_raw_line.
1313

14+
type MacroInteger = isize;
15+
1416
#[test]
1517
fn test_static_array() {
1618
let mut test = unsafe { bindings::Test_COUNTDOWN.as_ptr() };
@@ -242,3 +244,9 @@ fn test_item_rename() {
242244
member: bindings::bar { foo: 2 },
243245
};
244246
}
247+
248+
#[test]
249+
fn test_macro_customintkind_path() {
250+
let v: &std::any::Any = &bindings::TESTMACRO_CUSTOMINTKIND_PATH;
251+
assert!(v.is::<MacroInteger>())
252+
}

src/codegen/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3328,10 +3328,7 @@ impl TryToRustTy for Type {
33283328
IntKind::I64 => Ok(quote! { i64 }),
33293329
IntKind::U64 => Ok(quote! { u64 }),
33303330
IntKind::Custom { name, .. } => {
3331-
let ident = ctx.rust_ident_raw(name);
3332-
Ok(quote! {
3333-
#ident
3334-
})
3331+
Ok(proc_macro2::TokenStream::from_str(name).unwrap())
33353332
}
33363333
IntKind::U128 => {
33373334
Ok(if ctx.options().rust_features.i128_and_u128 {

0 commit comments

Comments
 (0)