Skip to content

Permit IntKind::Custom to represent Paths instead of just Idents #1800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion bindgen-integration/build.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions bindgen-integration/cpp/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
8 changes: 8 additions & 0 deletions bindgen-integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
Expand Down Expand Up @@ -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>())
}
5 changes: 1 addition & 4 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down