From e443bcb44a0ac34c9a64b6c4d9efc9684ee5e31c Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Wed, 16 Nov 2022 16:14:31 -0500 Subject: [PATCH 1/8] Allow generated_name_override for extern variables --- .../tests/issue-1375-prefixed-functions.rs | 4 ++++ .../headers/issue-1375-prefixed-functions.h | 2 ++ bindgen-tests/tests/parse_callbacks/mod.rs | 14 +++++++++----- bindgen/callbacks.rs | 14 +++++++++++++- bindgen/ir/function.rs | 8 ++++---- bindgen/ir/var.rs | 18 ++++++++++++++++-- 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs index 835b75790d..4ec85f716b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs @@ -5,6 +5,10 @@ non_upper_case_globals )] +extern "C" { + #[link_name = "\u{1}my_custom_prefix_const_name"] + pub static const_name: ::std::os::raw::c_int; +} extern "C" { #[link_name = "\u{1}my_custom_prefix_function_name"] pub fn function_name(x: ::std::os::raw::c_int); diff --git a/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h b/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h index 4264e52d65..088760b1b4 100644 --- a/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h +++ b/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h @@ -1,4 +1,6 @@ // bindgen-parse-callbacks: remove-function-prefix-my_custom_prefix_ +extern const int my_custom_prefix_const_name; + void my_custom_prefix_function_name(const int x); diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 6ade71c27c..cea3954eec 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -2,21 +2,25 @@ use bindgen::callbacks::*; #[derive(Debug)] pub struct RemoveFunctionPrefixParseCallback { - pub remove_function_prefix: Option, + pub remove_prefix: Option, } impl RemoveFunctionPrefixParseCallback { pub fn new(prefix: &str) -> Self { RemoveFunctionPrefixParseCallback { - remove_function_prefix: Some(prefix.to_string()), + remove_prefix: Some(prefix.to_string()), } } } impl ParseCallbacks for RemoveFunctionPrefixParseCallback { - fn generated_name_override(&self, function_name: &str) -> Option { - if let Some(prefix) = &self.remove_function_prefix { - if let Some(name) = function_name.strip_prefix(prefix) { + fn generated_name_override( + &self, + item_name: &str, + _item_kind: CallbackItemKind, + ) -> Option { + if let Some(prefix) = &self.remove_prefix { + if let Some(name) = item_name.strip_prefix(prefix) { return Some(name.to_string()); } } diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index fb84c8c331..a56b935939 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -6,6 +6,14 @@ pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue}; pub use crate::ir::int::IntKind; use std::fmt; +/// An enum to identify the type of item being passed to `ParseCallbacks::generated_name_override`. +pub enum CallbackItemKind { + /// A Function + Function, + /// A Variable + Var, +} + /// An enum to allow ignoring parsing of macros. #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum MacroParsingBehavior { @@ -32,7 +40,11 @@ pub trait ParseCallbacks: fmt::Debug { /// This function will run for every function. The returned value determines the name visible /// in the bindings. - fn generated_name_override(&self, _function_name: &str) -> Option { + fn generated_name_override( + &self, + _item_name: &str, + _item_kind: CallbackItemKind, + ) -> Option { None } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 7dbbb8f849..1bae4accd0 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -6,6 +6,7 @@ use super::dot::DotAttributes; use super::item::Item; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; +use crate::callbacks::CallbackItemKind; use crate::clang::{self, Attribute}; use crate::parse::{ ClangItemParser, ClangSubItemParser, ParseError, ParseResult, @@ -714,10 +715,9 @@ impl ClangSubItemParser for Function { // but seems easy enough to handle it here. name.push_str("_destructor"); } - if let Some(nm) = context - .options() - .last_callback(|callbacks| callbacks.generated_name_override(&name)) - { + if let Some(nm) = context.options().last_callback(|callbacks| { + callbacks.generated_name_override(&name, CallbackItemKind::Function) + }) { name = nm; } assert!(!name.is_empty(), "Empty function name."); diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index c86742ff69..a74398ee78 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -7,7 +7,7 @@ use super::function::cursor_mangling; use super::int::IntKind; use super::item::Item; use super::ty::{FloatKind, TypeKind}; -use crate::callbacks::MacroParsingBehavior; +use crate::callbacks::{CallbackItemKind, MacroParsingBehavior}; use crate::clang; use crate::clang::ClangToken; use crate::parse::{ @@ -274,12 +274,26 @@ impl ClangSubItemParser for Var { )) } CXCursor_VarDecl => { - let name = cursor.spelling(); + let mut name = cursor.spelling(); if name.is_empty() { warn!("Empty constant name?"); return Err(ParseError::Continue); } + if cursor.linkage() == CXLinkage_External { + if let Some(nm) = ctx.options().last_callback(|callbacks| { + callbacks.generated_name_override( + &name, + CallbackItemKind::Var, + ) + }) { + name = nm; + } + } + assert!(!name.is_empty(), "Empty constant name."); + // The name should not change again + let name = name; + let ty = cursor.cur_type(); // TODO(emilio): do we have to special-case constant arrays in From a970bfbf6dee680120d62ceb9cba29a4a6eb465e Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Wed, 16 Nov 2022 16:44:05 -0500 Subject: [PATCH 2/8] Improve testing --- .../tests/issue-1375-prefixed-functions.rs | 8 ++++++-- .../tests/headers/issue-1375-prefixed-functions.h | 4 +++- bindgen-tests/tests/parse_callbacks/mod.rs | 11 ++++++++++- bindgen/callbacks.rs | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs index 4ec85f716b..edcca46d8a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs @@ -6,8 +6,12 @@ )] extern "C" { - #[link_name = "\u{1}my_custom_prefix_const_name"] - pub static const_name: ::std::os::raw::c_int; + #[link_name = "\u{1}my_custom_prefix_var_const_name"] + pub static var_const_name: ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}my_custom_prefix_var_mut_name"] + pub static mut var_mut_name: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}my_custom_prefix_function_name"] diff --git a/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h b/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h index 088760b1b4..cc37c8ad80 100644 --- a/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h +++ b/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h @@ -1,6 +1,8 @@ // bindgen-parse-callbacks: remove-function-prefix-my_custom_prefix_ -extern const int my_custom_prefix_const_name; +extern const int my_custom_prefix_var_const_name; + +extern int my_custom_prefix_var_mut_name; void my_custom_prefix_function_name(const int x); diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index cea3954eec..40bef830fb 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -17,10 +17,19 @@ impl ParseCallbacks for RemoveFunctionPrefixParseCallback { fn generated_name_override( &self, item_name: &str, - _item_kind: CallbackItemKind, + item_kind: CallbackItemKind, ) -> Option { if let Some(prefix) = &self.remove_prefix { if let Some(name) = item_name.strip_prefix(prefix) { + match item_kind { + CallbackItemKind::Function => { + assert!(name.starts_with("function_")); + } + CallbackItemKind::Var => { + assert!(name.starts_with("var_")); + } + } + assert!(name.ends_with("_name")); return Some(name.to_string()); } } diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index a56b935939..95ae3c3999 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -6,7 +6,7 @@ pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue}; pub use crate::ir::int::IntKind; use std::fmt; -/// An enum to identify the type of item being passed to `ParseCallbacks::generated_name_override`. +/// An enum to identify the kind of item being passed to `ParseCallbacks::generated_name_override`. pub enum CallbackItemKind { /// A Function Function, From 8608d629a540c770e60de2d506de7f011d0c5f30 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Wed, 16 Nov 2022 16:52:07 -0500 Subject: [PATCH 3/8] Empty names produce Err --- bindgen/ir/var.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index a74398ee78..8cf00c337d 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -275,11 +275,6 @@ impl ClangSubItemParser for Var { } CXCursor_VarDecl => { let mut name = cursor.spelling(); - if name.is_empty() { - warn!("Empty constant name?"); - return Err(ParseError::Continue); - } - if cursor.linkage() == CXLinkage_External { if let Some(nm) = ctx.options().last_callback(|callbacks| { callbacks.generated_name_override( @@ -290,10 +285,14 @@ impl ClangSubItemParser for Var { name = nm; } } - assert!(!name.is_empty(), "Empty constant name."); - // The name should not change again + // No more changes to name let name = name; + if name.is_empty() { + warn!("Empty constant name?"); + return Err(ParseError::Continue); + } + let ty = cursor.cur_type(); // TODO(emilio): do we have to special-case constant arrays in From 16ed5b9ae2c50b17c217efdc9503543714f3575b Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Wed, 16 Nov 2022 18:09:19 -0500 Subject: [PATCH 4/8] Update test struct name --- bindgen-tests/tests/parse_callbacks/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 40bef830fb..bc063fb00f 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -1,19 +1,19 @@ use bindgen::callbacks::*; #[derive(Debug)] -pub struct RemoveFunctionPrefixParseCallback { +pub struct RemovePrefixParseCallback { pub remove_prefix: Option, } -impl RemoveFunctionPrefixParseCallback { +impl RemovePrefixParseCallback { pub fn new(prefix: &str) -> Self { - RemoveFunctionPrefixParseCallback { + RemovePrefixParseCallback { remove_prefix: Some(prefix.to_string()), } } } -impl ParseCallbacks for RemoveFunctionPrefixParseCallback { +impl ParseCallbacks for RemovePrefixParseCallback { fn generated_name_override( &self, item_name: &str, @@ -81,7 +81,7 @@ pub fn lookup(cb: &str) -> Box { .last() .to_owned(); let lnopc = - RemoveFunctionPrefixParseCallback::new(prefix.unwrap()); + RemovePrefixParseCallback::new(prefix.unwrap()); Box::new(lnopc) } else { panic!("Couldn't find name ParseCallbacks: {}", cb) From d25bb7d12674c055605ed3cb289b7add75a75478 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Wed, 16 Nov 2022 18:31:00 -0500 Subject: [PATCH 5/8] Fix formatting --- bindgen-tests/tests/parse_callbacks/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index bc063fb00f..e4ad94ccf9 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -80,8 +80,7 @@ pub fn lookup(cb: &str) -> Box { .split("remove-function-prefix-") .last() .to_owned(); - let lnopc = - RemovePrefixParseCallback::new(prefix.unwrap()); + let lnopc = RemovePrefixParseCallback::new(prefix.unwrap()); Box::new(lnopc) } else { panic!("Couldn't find name ParseCallbacks: {}", cb) From 15a7f473ccfc3545f7c60b851a91e12e72e089b0 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Mon, 28 Nov 2022 10:18:16 -0500 Subject: [PATCH 6/8] ItemInfo enum for use in callbacks --- bindgen-tests/tests/parse_callbacks/mod.rs | 22 +++++++---------- bindgen/callbacks.rs | 28 ++++++++++++---------- bindgen/ir/function.rs | 6 +++-- bindgen/ir/var.rs | 9 ++++--- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index e4ad94ccf9..22aa520c37 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -14,22 +14,16 @@ impl RemovePrefixParseCallback { } impl ParseCallbacks for RemovePrefixParseCallback { - fn generated_name_override( - &self, - item_name: &str, - item_kind: CallbackItemKind, - ) -> Option { + fn generated_name_override(&self, item_info: ItemInfo) -> Option { if let Some(prefix) = &self.remove_prefix { + let (item_name, expected_prefix, expected_suffix) = match item_info + { + ItemInfo::Function { name } => (name, "function_", "_name"), + ItemInfo::Var { name } => (name, "var_", "_name"), + }; if let Some(name) = item_name.strip_prefix(prefix) { - match item_kind { - CallbackItemKind::Function => { - assert!(name.starts_with("function_")); - } - CallbackItemKind::Var => { - assert!(name.starts_with("var_")); - } - } - assert!(name.ends_with("_name")); + assert!(name.starts_with(expected_prefix)); + assert!(name.ends_with(expected_suffix)); return Some(name.to_string()); } } diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 8eb7f0fa3a..ad9531217c 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -6,14 +6,6 @@ pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue}; pub use crate::ir::int::IntKind; use std::fmt; -/// An enum to identify the kind of item being passed to `ParseCallbacks::generated_name_override`. -pub enum CallbackItemKind { - /// A Function - Function, - /// A Variable - Var, -} - /// An enum to allow ignoring parsing of macros. #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum MacroParsingBehavior { @@ -40,11 +32,7 @@ pub trait ParseCallbacks: fmt::Debug { /// This function will run for every function. The returned value determines the name visible /// in the bindings. - fn generated_name_override( - &self, - _item_name: &str, - _item_kind: CallbackItemKind, - ) -> Option { + fn generated_name_override(&self, _item_info: ItemInfo) -> Option { None } @@ -134,3 +122,17 @@ pub struct DeriveInfo<'a> { /// The name of the type. pub name: &'a str, } + +/// An enum providing information about the item being passed to `ParseCallbacks::generated_name_override`. +pub enum ItemInfo<'a> { + /// A Function + Function { + /// The name of the function + name: &'a str, + }, + /// A Variable + Var { + /// The name of the variable + name: &'a str, + }, +} diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index baf9cd71f5..fcdc768c0a 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -6,7 +6,7 @@ use super::dot::DotAttributes; use super::item::Item; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; -use crate::callbacks::CallbackItemKind; +use crate::callbacks::ItemInfo; use crate::clang::{self, Attribute}; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use clang_sys::{self, CXCallingConv}; @@ -714,7 +714,9 @@ impl ClangSubItemParser for Function { name.push_str("_destructor"); } if let Some(nm) = context.options().last_callback(|callbacks| { - callbacks.generated_name_override(&name, CallbackItemKind::Function) + callbacks.generated_name_override(ItemInfo::Function { + name: name.as_str(), + }) }) { name = nm; } diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 87365e1233..bdf294c0c9 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -7,7 +7,7 @@ use super::function::cursor_mangling; use super::int::IntKind; use super::item::Item; use super::ty::{FloatKind, TypeKind}; -use crate::callbacks::{CallbackItemKind, MacroParsingBehavior}; +use crate::callbacks::{ItemInfo, MacroParsingBehavior}; use crate::clang; use crate::clang::ClangToken; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; @@ -275,10 +275,9 @@ impl ClangSubItemParser for Var { let mut name = cursor.spelling(); if cursor.linkage() == CXLinkage_External { if let Some(nm) = ctx.options().last_callback(|callbacks| { - callbacks.generated_name_override( - &name, - CallbackItemKind::Var, - ) + callbacks.generated_name_override(ItemInfo::Var { + name: name.as_str(), + }) }) { name = nm; } From f64baea67811421e2d00e603bc0928227fde722c Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Mon, 28 Nov 2022 10:38:29 -0500 Subject: [PATCH 7/8] Update doc-comment for generated_name_override --- bindgen/callbacks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index ad9531217c..102ba75ba7 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -30,8 +30,8 @@ pub trait ParseCallbacks: fmt::Debug { MacroParsingBehavior::Default } - /// This function will run for every function. The returned value determines the name visible - /// in the bindings. + /// This function will run for every extern variable and function. The returned value determines + /// the name visible in the bindings. fn generated_name_override(&self, _item_info: ItemInfo) -> Option { None } From 1a395080fcb856d88cbdb4a61db1a24ade1b5d59 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Mon, 28 Nov 2022 13:08:04 -0500 Subject: [PATCH 8/8] Separate ItemInfo struct from ItemKind --- bindgen-tests/tests/parse_callbacks/mod.rs | 10 ++++----- bindgen/callbacks.rs | 24 +++++++++++++--------- bindgen/ir/function.rs | 5 +++-- bindgen/ir/var.rs | 5 +++-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 22aa520c37..00967fe8d7 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -16,12 +16,12 @@ impl RemovePrefixParseCallback { impl ParseCallbacks for RemovePrefixParseCallback { fn generated_name_override(&self, item_info: ItemInfo) -> Option { if let Some(prefix) = &self.remove_prefix { - let (item_name, expected_prefix, expected_suffix) = match item_info - { - ItemInfo::Function { name } => (name, "function_", "_name"), - ItemInfo::Var { name } => (name, "var_", "_name"), + let (expected_prefix, expected_suffix) = match item_info.kind { + ItemKind::Function => ("function_", "_name"), + ItemKind::Var => ("var_", "_name"), + _ => todo!(), }; - if let Some(name) = item_name.strip_prefix(prefix) { + if let Some(name) = item_info.name.strip_prefix(prefix) { assert!(name.starts_with(expected_prefix)); assert!(name.ends_with(expected_suffix)); return Some(name.to_string()); diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 102ba75ba7..1e48a30259 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -123,16 +123,20 @@ pub struct DeriveInfo<'a> { pub name: &'a str, } -/// An enum providing information about the item being passed to `ParseCallbacks::generated_name_override`. -pub enum ItemInfo<'a> { +/// An struct providing information about the item being passed to `ParseCallbacks::generated_name_override`. +#[non_exhaustive] +pub struct ItemInfo<'a> { + /// The name of the item + pub name: &'a str, + /// The kind of item + pub kind: ItemKind, +} + +/// An enum indicating the kind of item for an ItemInfo. +#[non_exhaustive] +pub enum ItemKind { /// A Function - Function { - /// The name of the function - name: &'a str, - }, + Function, /// A Variable - Var { - /// The name of the variable - name: &'a str, - }, + Var, } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index fcdc768c0a..8e83d980bc 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -6,7 +6,7 @@ use super::dot::DotAttributes; use super::item::Item; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; -use crate::callbacks::ItemInfo; +use crate::callbacks::{ItemInfo, ItemKind}; use crate::clang::{self, Attribute}; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use clang_sys::{self, CXCallingConv}; @@ -714,8 +714,9 @@ impl ClangSubItemParser for Function { name.push_str("_destructor"); } if let Some(nm) = context.options().last_callback(|callbacks| { - callbacks.generated_name_override(ItemInfo::Function { + callbacks.generated_name_override(ItemInfo { name: name.as_str(), + kind: ItemKind::Function, }) }) { name = nm; diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index bdf294c0c9..903e1ff549 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -7,7 +7,7 @@ use super::function::cursor_mangling; use super::int::IntKind; use super::item::Item; use super::ty::{FloatKind, TypeKind}; -use crate::callbacks::{ItemInfo, MacroParsingBehavior}; +use crate::callbacks::{ItemInfo, ItemKind, MacroParsingBehavior}; use crate::clang; use crate::clang::ClangToken; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; @@ -275,8 +275,9 @@ impl ClangSubItemParser for Var { let mut name = cursor.spelling(); if cursor.linkage() == CXLinkage_External { if let Some(nm) = ctx.options().last_callback(|callbacks| { - callbacks.generated_name_override(ItemInfo::Var { + callbacks.generated_name_override(ItemInfo { name: name.as_str(), + kind: ItemKind::Var, }) }) { name = nm;