Skip to content

Commit 83dd5ae

Browse files
authored
Merge pull request rust-lang#19 from sfackler/master
ABI fixes
2 parents 5e60924 + a1f3249 commit 83dd5ae

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

ctest/src/lib.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,15 +1054,7 @@ impl<'a> Generator<'a> {
10541054
.connect(", ") + if variadic {", ..."} else {""}
10551055
};
10561056
let cret = self.rust_ty_to_c_ty(ret);
1057-
let abi = match abi {
1058-
Abi::C => "",
1059-
Abi::Stdcall => "__stdcall ",
1060-
Abi::System if self.target.contains("i686-pc-windows") => {
1061-
"__stdcall "
1062-
}
1063-
Abi::System => "",
1064-
a => panic!("unknown ABI: {}", a),
1065-
};
1057+
let abi = self.abi2str(abi);
10661058
t!(writeln!(self.c, r#"
10671059
{ret} ({abi}*__test_fn_{name}(void))({args}) {{
10681060
return {cname};
@@ -1176,12 +1168,13 @@ impl<'a> Generator<'a> {
11761168
ast::TyKind::BareFn(ref t) => {
11771169
assert!(t.lifetimes.len() == 0);
11781170
let (ret, mut args, variadic) = self.decl2rust(&t.decl);
1171+
let abi = self.abi2str(t.abi);
11791172
if variadic {
11801173
args.push("...".to_string());
11811174
} else if args.len() == 0 {
11821175
args.push("void".to_string());
11831176
}
1184-
format!("{}(**{})({})", ret, sig, args.connect(", "))
1177+
format!("{}({}**{})({})", ret, abi, sig, args.connect(", "))
11851178
}
11861179
ast::TyKind::FixedLengthVec(ref t, ref e) => {
11871180
format!("{}(*{})[{}]", self.ty2name(t, false), sig,
@@ -1207,6 +1200,18 @@ impl<'a> Generator<'a> {
12071200
}
12081201
}
12091202

1203+
fn abi2str(&self, abi: Abi) -> &'static str {
1204+
match abi {
1205+
Abi::C => "",
1206+
Abi::Stdcall => "__stdcall ",
1207+
Abi::System if self.target.contains("i686-pc-windows") => {
1208+
"__stdcall "
1209+
}
1210+
Abi::System => "",
1211+
a => panic!("unknown ABI: {}", a),
1212+
}
1213+
}
1214+
12101215
fn decl2rust(&self, decl: &ast::FnDecl) -> (String, Vec<String>, bool) {
12111216
let args = decl.inputs.iter().map(|arg| {
12121217
self.ty2name(&arg.ty, false)
@@ -1260,7 +1265,7 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
12601265
self.test_const(&i.ident.to_string(), &ty);
12611266
}
12621267

1263-
ast::ItemKind::ForeignMod(ref fm) if public => {
1268+
ast::ItemKind::ForeignMod(ref fm) => {
12641269
self.abi = fm.abi;
12651270
}
12661271

0 commit comments

Comments
 (0)