summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Vukicevic <vladimir@pobox.com>2016-05-27 19:27:49 -0400
committerVladimir Vukicevic <vladimir@pobox.com>2016-07-18 17:12:14 -0400
commit644589c7fe75c2f1aa1568d80d60c30687b698be (patch)
treee859843cb637ee9a16fe9fca4e1b962b443684fe
parentdca0f897684a6ee6651561f6c2c55058c0279dfe (diff)
Support MSVC mangled names (which have @ symbols in them) when generating bindings
-rw-r--r--.gitignore5
-rw-r--r--src/gen.rs13
2 files changed, 15 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index bcc3a4e0..f54aca98 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,7 @@ libbindgen*
# Cargo
target/
-Cargo.lock \ No newline at end of file
+Cargo.lock
+*~
+#*#
+
diff --git a/src/gen.rs b/src/gen.rs
index 4d296386..e046ea12 100644
--- a/src/gen.rs
+++ b/src/gen.rs
@@ -70,8 +70,16 @@ fn ref_eq<T>(thing: &T, other: &T) -> bool {
fn rust_id(ctx: &mut GenCtx, name: &str) -> (String, bool) {
let token = parse::token::Ident(ctx.ext_cx.ident_of(name));
- if token.is_any_keyword() || "bool" == name {
+ if token.is_any_keyword() ||
+ name.contains("@") ||
+ name.contains("?") ||
+ name.contains("$") ||
+ "bool" == name
+ {
let mut s = name.to_owned();
+ s = s.replace("@", "_");
+ s = s.replace("?", "_");
+ s = s.replace("$", "_");
s.push_str("_");
(s, true)
} else {
@@ -214,6 +222,7 @@ fn gen_unmangle_method(ctx: &mut GenCtx,
constness: ast::Constness::NotConst,
};
+ let mangled_rs = first(rust_id(ctx, &v.mangled));
let call = P(ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Call(
@@ -223,7 +232,7 @@ fn gen_unmangle_method(ctx: &mut GenCtx,
span: ctx.span,
global: false,
segments: vec![ast::PathSegment {
- identifier: ctx.ext_cx.ident_of(&v.mangled),
+ identifier: ctx.ext_cx.ident_of(&mangled_rs),
parameters: ast::PathParameters::none()
}]
}),