@@ -15,7 +15,6 @@ OpenSSL libraries installed, it should 'just work'.
15
15
use std;
16
16
import std::{vec, str};
17
17
18
- #[abi = "cdecl"]
19
18
native mod crypto {
20
19
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
21
20
}
@@ -42,7 +41,6 @@ OpenSSL libraries installed, it should 'just work'.
42
41
Before we can call ` SHA1 ` , we have to declare it. That is what this
43
42
part of the program is responsible for:
44
43
45
- #[abi = "cdecl"]
46
44
native mod crypto {
47
45
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
48
46
}
@@ -56,18 +54,27 @@ in a platform-specific way (`libcrypto.so` on Linux, for example), and
56
54
link that in. If you want the module to have a different name from the
57
55
actual library, you can use the ` "link_name" ` attribute, like:
58
56
59
- #[abi = "cdecl"]
60
57
#[link_name = "crypto"]
61
58
native mod something {
62
59
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
63
60
}
64
61
65
- The ` #[abi = "cdecl"] ` attribute indicates the calling convention to
66
- use for functions in this module. Most C libraries use cdecl as their
67
- calling convention. You can also specify ` "x86stdcall" ` to use stdcall
68
- instead.
62
+ ## Native calling conventions
69
63
70
- FIXME: Mention c-stack variants? Are they going to change?
64
+ Most native C code use the cdecl calling convention, so that is what
65
+ Rust uses by default when calling native functions. Some native functions,
66
+ most notably the Windows API, use other calling conventions, so Rust
67
+ provides a way to to hint to the compiler which is expected by using
68
+ the ` "abi" ` attribute:
69
+
70
+ #[abi = "stdcall"]
71
+ native mod kernel32 {
72
+ fn SetEnvironmentVariableA(n: *u8, v: *u8) -> int;
73
+ }
74
+
75
+ The ` "abi" ` attribute applies to a native mod (it can not be applied
76
+ to a single function within a module), and must be either ` "cdecl" `
77
+ or ` "stdcall" ` . Other conventions may be defined in the future.
71
78
72
79
## Unsafe pointers
73
80
@@ -171,7 +178,6 @@ microsecond-resolution timer.
171
178
use std;
172
179
type timeval = {mutable tv_sec: u32,
173
180
mutable tv_usec: u32};
174
- #[abi = "cdecl"]
175
181
#[link_name = ""]
176
182
native mod libc {
177
183
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
0 commit comments