Skip to content

Commit b9daa74

Browse files
lhtbrson
authored andcommitted
---
yaml --- r: 6289 b: refs/heads/master c: 5665308 h: refs/heads/master i: 6287: f3f88a8 v: v3
1 parent badf8c6 commit b9daa74

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 88f29aab27bf56bda4cf7062cb53af0be4b5c251
2+
refs/heads/master: 5665308d8cc02d43865db2e2336ed98c9d944a59

trunk/doc/tutorial/ffi.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ OpenSSL libraries installed, it should 'just work'.
1515
use std;
1616
import std::{vec, str};
1717

18-
native "cdecl" mod crypto {
18+
#[abi = "cdecl"]
19+
native mod crypto {
1920
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
2021
}
2122

@@ -41,7 +42,8 @@ OpenSSL libraries installed, it should 'just work'.
4142
Before we can call `SHA1`, we have to declare it. That is what this
4243
part of the program is responsible for:
4344

44-
native "cdecl" mod crypto {
45+
#[abi = "cdecl"]
46+
native mod crypto {
4547
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
4648
}
4749

@@ -52,12 +54,17 @@ of functions are available in that library.
5254
In this case, it'll change the name `crypto` to a shared library name
5355
in a platform-specific way (`libcrypto.so` on Linux, for example), and
5456
link that in. If you want the module to have a different name from the
55-
actual library, you can say `native "cdecl" mod something = "crypto" {
56-
... }`.
57+
actual library, you can use the `"link_name"` attribute, like:
5758

58-
The `"cdecl"` word indicates the calling convention to use for
59-
functions in this module. Most C libraries use cdecl as their calling
60-
convention. You can also specify `"x86stdcall"` to use stdcall
59+
#[abi = "cdecl"]
60+
#[link_name = "crypto"]
61+
native mod something {
62+
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
63+
}
64+
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
6168
instead.
6269

6370
FIXME: Mention c-stack variants? Are they going to change?
@@ -164,7 +171,9 @@ microsecond-resolution timer.
164171
use std;
165172
type timeval = {mutable tv_sec: u32,
166173
mutable tv_usec: u32};
167-
native "cdecl" mod libc = "" {
174+
#[abi = "cdecl"]
175+
#[link_name = ""]
176+
native mod libc {
168177
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
169178
}
170179
fn unix_time_in_microseconds() -> u64 unsafe {
@@ -173,9 +182,9 @@ microsecond-resolution timer.
173182
ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
174183
}
175184

176-
The `libc = ""` sets the name of the native module to the empty string
177-
to prevent the rust compiler from trying to link it. The standard C
178-
library is already linked with Rust programs.
185+
The `#[link_name = ""]` sets the name of the native module to the
186+
empty string to prevent the rust compiler from trying to link it.
187+
The standard C library is already linked with Rust programs.
179188

180189
A `timeval`, in C, is a struct with two 32-bit integers. Thus, we
181190
define a record type with the same contents, and declare

0 commit comments

Comments
 (0)