Skip to content

Make mangled name available to generated_xxx_override. Link name override no longer affected by generated name override. #3108

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions bindgen-tests/tests/headers/generated_link_name_override.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// bindgen-parse-callbacks: prefix-link-name-
// bindgen-parse-callbacks: remove-function-prefix-prefix_kept_in_link_name_only_
// prefix-link-name- with no value just ensures that the items are always given the link_name attribute.

extern const int prefix_kept_in_link_name_only_var_coolConstVariable_name;

extern int prefix_kept_in_link_name_only_var_coolVariable_name;

void prefix_kept_in_link_name_only_function_coolFunction_name(const int x);

2 changes: 2 additions & 0 deletions bindgen/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ pub enum TypeKind {
pub struct ItemInfo<'a> {
/// The name of the item
pub name: &'a str,
/// The mangled name of the item, if available
pub mangled_name: Option<&'a str>,
/// The kind of item
pub kind: ItemKind,
}
Expand Down
20 changes: 11 additions & 9 deletions bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,25 +784,27 @@ impl ClangSubItemParser for Function {
// but seems easy enough to handle it here.
name.push_str("_destructor");
}
let mangled_name = cursor_mangling(context, &cursor);

let link_name = context.options().last_callback(|callbacks| {
callbacks.generated_link_name_override(ItemInfo {
name: name.as_str(),
mangled_name: mangled_name.as_deref(),
kind: ItemKind::Function,
})
});

if let Some(nm) = context.options().last_callback(|callbacks| {
callbacks.generated_name_override(ItemInfo {
name: name.as_str(),
mangled_name: mangled_name.as_deref(),
kind: ItemKind::Function,
})
}) {
name = nm;
}
assert!(!name.is_empty(), "Empty function name.");

let mangled_name = cursor_mangling(context, &cursor);

let link_name = context.options().last_callback(|callbacks| {
callbacks.generated_link_name_override(ItemInfo {
name: name.as_str(),
kind: ItemKind::Function,
})
});

let function = Self::new(
name.clone(),
mangled_name,
Expand Down
19 changes: 11 additions & 8 deletions bindgen/ir/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,21 @@ impl ClangSubItemParser for Var {
}
CXCursor_VarDecl => {
let mut name = cursor.spelling();
let mangling = cursor_mangling(ctx, &cursor);

let link_name = ctx.options().last_callback(|callbacks| {
callbacks.generated_link_name_override(ItemInfo {
name: name.as_str(),
mangled_name: mangling.as_deref(),
kind: ItemKind::Var,
})
});

if cursor.linkage() == CXLinkage_External {
if let Some(nm) = ctx.options().last_callback(|callbacks| {
callbacks.generated_name_override(ItemInfo {
name: name.as_str(),
mangled_name: mangling.as_deref(),
kind: ItemKind::Var,
})
}) {
Expand All @@ -289,13 +300,6 @@ impl ClangSubItemParser for Var {
return Err(ParseError::Continue);
}

let link_name = ctx.options().last_callback(|callbacks| {
callbacks.generated_link_name_override(ItemInfo {
name: name.as_str(),
kind: ItemKind::Var,
})
});

let ty = cursor.cur_type();

// TODO(emilio): do we have to special-case constant arrays in
Expand Down Expand Up @@ -364,7 +368,6 @@ impl ClangSubItemParser for Var {
.map(VarType::String)
};

let mangling = cursor_mangling(ctx, &cursor);
let var =
Var::new(name, mangling, link_name, ty, value, is_const);

Expand Down