@@ -932,7 +932,7 @@ impl<'a> Generator<'a> {
932
932
"i16" => "int16_t" . to_string ( ) ,
933
933
"i32" => "int32_t" . to_string ( ) ,
934
934
"i64" => "int64_t" . to_string ( ) ,
935
-
935
+ "( )" => "void" . to_string ( ) ,
936
936
s => ( self . opts . type_name ) ( s, self . structs . contains ( s) , self . unions . contains ( s) ) ,
937
937
}
938
938
}
@@ -1198,17 +1198,43 @@ impl<'a> Generator<'a> {
1198
1198
self . tests . push ( format ! ( "fn_{}" , name) ) ;
1199
1199
}
1200
1200
1201
- fn test_extern_static ( & mut self , name : & str , rust_ty : & str , mutbl : bool ) {
1201
+ fn test_extern_static ( & mut self , name : & str , cname : Option < String > ,
1202
+ rust_ty : & str , c_ty : & str , mutbl : bool ) {
1202
1203
if ( self . opts . skip_static ) ( name) {
1203
1204
return
1204
1205
}
1205
- let c_ty = self . rust_ty_to_c_ty ( rust_ty) ;
1206
+
1207
+ let cname = cname. unwrap_or_else ( || name. to_string ( ) ) ;
1208
+
1209
+ if rust_ty. contains ( "extern fn" ) {
1210
+ let c_ty = c_ty. replacen ( "(*)" , & format ! ( "(* __test_static_{}(void))" , name) , 1 ) ;
1211
+ t ! ( writeln!( self . c, r#"
1212
+ {ty} {{
1213
+ return {cname};
1214
+ }}
1215
+ "# , ty = c_ty, cname = cname) ) ;
1216
+ t ! ( writeln!( self . rust, r#"
1217
+ #[inline(never)]
1218
+ fn static_{name}() {{
1219
+ extern {{
1220
+ fn __test_static_{name}() -> {ty};
1221
+ }}
1222
+ unsafe {{
1223
+ same({name} as usize,
1224
+ __test_static_{name}() as usize,
1225
+ "{name} static");
1226
+ }}
1227
+ }}
1228
+ "# , name = name, ty = rust_ty) ) ;
1229
+ } else {
1230
+ let c_ty = self . rust_ty_to_c_ty ( rust_ty) ;
1206
1231
t ! ( writeln!( self . c, r#"
1207
1232
{mutbl}{ty}* __test_static_{name}(void) {{
1208
- return &{name };
1233
+ return &{cname };
1209
1234
}}
1210
- "# , mutbl = if mutbl { "" } else { "const " } , ty = c_ty, name = name) ) ;
1211
- t ! ( writeln!( self . rust, r#"
1235
+ "# , mutbl = if mutbl { "" } else { "const " } , ty = c_ty,
1236
+ name = name, cname = cname) ) ;
1237
+ t ! ( writeln!( self . rust, r#"
1212
1238
#[inline(never)]
1213
1239
fn static_{name}() {{
1214
1240
extern {{
@@ -1221,6 +1247,7 @@ impl<'a> Generator<'a> {
1221
1247
}}
1222
1248
}}
1223
1249
"# , name = name, mutbl = if mutbl { "mut" } else { "const" } , ty = rust_ty) ) ;
1250
+ } ;
1224
1251
self . tests . push ( format ! ( "static_{}" , name) ) ;
1225
1252
}
1226
1253
@@ -1290,7 +1317,13 @@ impl<'a> Generator<'a> {
1290
1317
if args. len ( ) == 0 {
1291
1318
args. push ( "void" . to_string ( ) ) ;
1292
1319
}
1293
- format ! ( "{}(*)({})" , ret, args. join( ", " ) )
1320
+
1321
+ let s = if ret. contains ( "(*)" ) {
1322
+ ret. replace ( "(*)" , & format ! ( "(*(*)({}))" , args. join( ", " ) ) )
1323
+ } else {
1324
+ format ! ( "{}(*)({})" , ret, args. join( ", " ) )
1325
+ } ;
1326
+ s
1294
1327
}
1295
1328
}
1296
1329
ast:: TyKind :: Array ( ref t, ref e) => {
@@ -1329,6 +1362,7 @@ impl<'a> Generator<'a> {
1329
1362
format ! ( "char*" )
1330
1363
}
1331
1364
}
1365
+ ast:: TyKind :: Tup ( ref v) if v. is_empty ( ) => if rust { "()" . to_string ( ) } else { "void" . to_string ( ) } ,
1332
1366
_ => panic ! ( "unknown ty {:?}" , ty) ,
1333
1367
}
1334
1368
}
@@ -1518,8 +1552,11 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
1518
1552
variadic, abi) ;
1519
1553
}
1520
1554
ast:: ForeignItemKind :: Static ( ref ty, mutbl) => {
1521
- let ty = self . ty2name ( & ty, true ) ;
1522
- self . test_extern_static ( & i. ident . to_string ( ) , & ty, mutbl) ;
1555
+ let rust_ty = self . ty2name ( & ty, true ) ;
1556
+ let c_ty = self . ty2name ( & ty, false ) ;
1557
+ let cname = attr:: first_attr_value_str_by_name ( & i. attrs , "link_name" )
1558
+ . map ( |i| i. to_string ( ) ) ;
1559
+ self . test_extern_static ( & i. ident . to_string ( ) , cname, & rust_ty, & c_ty, mutbl) ;
1523
1560
}
1524
1561
}
1525
1562
visit:: walk_foreign_item ( self , i)
0 commit comments