@@ -1054,15 +1054,7 @@ impl<'a> Generator<'a> {
1054
1054
. connect ( ", " ) + if variadic { ", ..." } else { "" }
1055
1055
} ;
1056
1056
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) ;
1066
1058
t ! ( writeln!( self . c, r#"
1067
1059
{ret} ({abi}*__test_fn_{name}(void))({args}) {{
1068
1060
return {cname};
@@ -1176,12 +1168,13 @@ impl<'a> Generator<'a> {
1176
1168
ast:: TyKind :: BareFn ( ref t) => {
1177
1169
assert ! ( t. lifetimes. len( ) == 0 ) ;
1178
1170
let ( ret, mut args, variadic) = self . decl2rust ( & t. decl ) ;
1171
+ let abi = self . abi2str ( t. abi ) ;
1179
1172
if variadic {
1180
1173
args. push ( "..." . to_string ( ) ) ;
1181
1174
} else if args. len ( ) == 0 {
1182
1175
args. push ( "void" . to_string ( ) ) ;
1183
1176
}
1184
- format ! ( "{}(**{})({})" , ret, sig, args. connect( ", " ) )
1177
+ format ! ( "{}({} **{})({})" , ret, abi , sig, args. connect( ", " ) )
1185
1178
}
1186
1179
ast:: TyKind :: FixedLengthVec ( ref t, ref e) => {
1187
1180
format ! ( "{}(*{})[{}]" , self . ty2name( t, false ) , sig,
@@ -1207,6 +1200,18 @@ impl<'a> Generator<'a> {
1207
1200
}
1208
1201
}
1209
1202
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
+
1210
1215
fn decl2rust ( & self , decl : & ast:: FnDecl ) -> ( String , Vec < String > , bool ) {
1211
1216
let args = decl. inputs . iter ( ) . map ( |arg| {
1212
1217
self . ty2name ( & arg. ty , false )
@@ -1260,7 +1265,7 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
1260
1265
self . test_const ( & i. ident . to_string ( ) , & ty) ;
1261
1266
}
1262
1267
1263
- ast:: ItemKind :: ForeignMod ( ref fm) if public => {
1268
+ ast:: ItemKind :: ForeignMod ( ref fm) => {
1264
1269
self . abi = fm. abi ;
1265
1270
}
1266
1271
0 commit comments