diff options
author | Vladimir Vukicevic <vladimir@pobox.com> | 2016-05-27 19:27:49 -0400 |
---|---|---|
committer | Vladimir Vukicevic <vladimir@pobox.com> | 2016-07-18 17:12:14 -0400 |
commit | 644589c7fe75c2f1aa1568d80d60c30687b698be (patch) | |
tree | e859843cb637ee9a16fe9fca4e1b962b443684fe | |
parent | dca0f897684a6ee6651561f6c2c55058c0279dfe (diff) |
Support MSVC mangled names (which have @ symbols in them) when generating bindings
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | src/gen.rs | 13 |
2 files changed, 15 insertions, 3 deletions
@@ -3,4 +3,7 @@ libbindgen* # Cargo target/ -Cargo.lock
\ No newline at end of file +Cargo.lock +*~ +#*# + @@ -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() }] }), |