@@ -15,7 +15,8 @@ OpenSSL libraries installed, it should 'just work'.
15
15
use std;
16
16
import std::{vec, str};
17
17
18
- native "cdecl" mod crypto {
18
+ #[abi = "cdecl"]
19
+ native mod crypto {
19
20
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
20
21
}
21
22
@@ -41,7 +42,8 @@ OpenSSL libraries installed, it should 'just work'.
41
42
Before we can call ` SHA1 ` , we have to declare it. That is what this
42
43
part of the program is responsible for:
43
44
44
- native "cdecl" mod crypto {
45
+ #[abi = "cdecl"]
46
+ native mod crypto {
45
47
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
46
48
}
47
49
@@ -52,12 +54,17 @@ of functions are available in that library.
52
54
In this case, it'll change the name ` crypto ` to a shared library name
53
55
in a platform-specific way (` libcrypto.so ` on Linux, for example), and
54
56
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:
57
58
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
61
68
instead.
62
69
63
70
FIXME: Mention c-stack variants? Are they going to change?
@@ -164,7 +171,9 @@ microsecond-resolution timer.
164
171
use std;
165
172
type timeval = {mutable tv_sec: u32,
166
173
mutable tv_usec: u32};
167
- native "cdecl" mod libc = "" {
174
+ #[abi = "cdecl"]
175
+ #[link_name = ""]
176
+ native mod libc {
168
177
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
169
178
}
170
179
fn unix_time_in_microseconds() -> u64 unsafe {
@@ -173,9 +182,9 @@ microsecond-resolution timer.
173
182
ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
174
183
}
175
184
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.
179
188
180
189
A ` timeval ` , in C, is a struct with two 32-bit integers. Thus, we
181
190
define a record type with the same contents, and declare
0 commit comments