]>
Commit | Line | Data |
---|---|---|
136023e0 XL |
1 | #![feature(raw_dylib)] |
2 | ||
3 | #[repr(C)] | |
4 | #[derive(Clone)] | |
5 | struct S { | |
6 | x: u8, | |
7 | y: i32, | |
8 | } | |
9 | ||
10 | #[repr(C)] | |
11 | #[derive(Clone)] | |
12 | struct S2 { | |
13 | x: i32, | |
14 | y: u8, | |
15 | } | |
16 | ||
17 | #[repr(C)] | |
18 | #[derive(Clone)] | |
19 | struct S3 { | |
20 | x: [u8; 5], | |
21 | } | |
22 | ||
23 | #[link(name = "extern", kind = "raw-dylib")] | |
24 | extern "stdcall" { | |
25 | fn stdcall_fn_1(i: i32); | |
26 | fn stdcall_fn_2(c: u8, f: f32); | |
27 | fn stdcall_fn_3(d: f64); | |
28 | fn stdcall_fn_4(i: u8, j: u8, f: f32); | |
29 | fn stdcall_fn_5(a: S, b: i32); | |
30 | fn stdcall_fn_6(a: Option<&S>); | |
31 | fn stdcall_fn_7(a: S2, b: i32); | |
32 | fn stdcall_fn_8(a: S3, b: S3); | |
33 | fn stdcall_fn_9(x: u8, y: f64); | |
34 | } | |
35 | ||
36 | #[link(name = "extern", kind = "raw-dylib")] | |
37 | extern "fastcall" { | |
38 | fn fastcall_fn_1(i: i32); | |
39 | fn fastcall_fn_2(c: u8, f: f32); | |
40 | fn fastcall_fn_3(d: f64); | |
41 | fn fastcall_fn_4(i: u8, j: u8, f: f32); | |
42 | fn fastcall_fn_5(a: S, b: i32); | |
43 | fn fastcall_fn_6(a: Option<&S>); | |
44 | fn fastcall_fn_7(a: S2, b: i32); | |
45 | fn fastcall_fn_8(a: S3, b: S3); | |
46 | fn fastcall_fn_9(x: u8, y: f64); | |
47 | } | |
48 | ||
49 | pub fn library_function() { | |
50 | unsafe { | |
51 | stdcall_fn_1(14); | |
52 | stdcall_fn_2(16, 3.5); | |
53 | stdcall_fn_3(3.5); | |
54 | stdcall_fn_4(1, 2, 3.0); | |
55 | stdcall_fn_5(S { x: 1, y: 2 }, 16); | |
56 | stdcall_fn_6(Some(&S { x: 10, y: 12 })); | |
57 | stdcall_fn_7(S2 { x: 15, y: 16 }, 3); | |
58 | stdcall_fn_8(S3 { x: [1, 2, 3, 4, 5] }, S3 { x: [6, 7, 8, 9, 10] }); | |
59 | stdcall_fn_9(1, 3.0); | |
60 | ||
61 | fastcall_fn_1(14); | |
62 | fastcall_fn_2(16, 3.5); | |
63 | fastcall_fn_3(3.5); | |
64 | fastcall_fn_4(1, 2, 3.0); | |
5099ac24 FG |
65 | // FIXME: 91167 |
66 | // rustc generates incorrect code for the calls to fastcall_fn_5 and fastcall_fn_7 | |
67 | // on i686-pc-windows-gnu; commenting these out until the indicated issue is fixed. | |
68 | //fastcall_fn_5(S { x: 1, y: 2 }, 16); | |
136023e0 | 69 | fastcall_fn_6(Some(&S { x: 10, y: 12 })); |
5099ac24 | 70 | //fastcall_fn_7(S2 { x: 15, y: 16 }, 3); |
136023e0 XL |
71 | fastcall_fn_8(S3 { x: [1, 2, 3, 4, 5] }, S3 { x: [6, 7, 8, 9, 10] }); |
72 | fastcall_fn_9(1, 3.0); | |
73 | } | |
74 | } |