Skip to content

Commit f55ad72

Browse files
committed
---
yaml --- r: 6291 b: refs/heads/master c: 9b89b0c h: refs/heads/master i: 6289: b9daa74 6287: f3f88a8 v: v3
1 parent a715747 commit f55ad72

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a362d8532900054e18f1723060bb4960ec3f5821
2+
refs/heads/master: 9b89b0cffddced063bfb46671b69aba81956e553

trunk/doc/tutorial/ffi.md

+15-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ OpenSSL libraries installed, it should 'just work'.
1515
use std;
1616
import std::{vec, str};
1717

18-
#[abi = "cdecl"]
1918
native mod crypto {
2019
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
2120
}
@@ -42,7 +41,6 @@ OpenSSL libraries installed, it should 'just work'.
4241
Before we can call `SHA1`, we have to declare it. That is what this
4342
part of the program is responsible for:
4443

45-
#[abi = "cdecl"]
4644
native mod crypto {
4745
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
4846
}
@@ -56,18 +54,27 @@ in a platform-specific way (`libcrypto.so` on Linux, for example), and
5654
link that in. If you want the module to have a different name from the
5755
actual library, you can use the `"link_name"` attribute, like:
5856

59-
#[abi = "cdecl"]
6057
#[link_name = "crypto"]
6158
native mod something {
6259
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
6360
}
6461

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
6963

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.
7178

7279
## Unsafe pointers
7380

@@ -171,7 +178,6 @@ microsecond-resolution timer.
171178
use std;
172179
type timeval = {mutable tv_sec: u32,
173180
mutable tv_usec: u32};
174-
#[abi = "cdecl"]
175181
#[link_name = ""]
176182
native mod libc {
177183
fn gettimeofday(tv: *timeval, tz: *()) -> i32;

0 commit comments

Comments
 (0)