88f29aab27
This patch changes how to specify ABI and link name of a native module. Before: native "cdecl" mod llvm = "rustllvm" {...} After: #[abi = "cdecl"] #[link_name = "rustllvm"] native mod llvm {...} The old optional syntax for ABI and link name is no longer supported. Fixes issue #547
23 lines
408 B
Rust
23 lines
408 B
Rust
use std;
|
|
|
|
import std::vec;
|
|
import std::str;
|
|
|
|
#[link_name = ""]
|
|
#[abi = "cdecl"]
|
|
native mod libc {
|
|
#[link_name = "strlen"]
|
|
fn my_strlen(str: *u8) -> uint;
|
|
}
|
|
|
|
fn strlen(str: str) -> uint unsafe {
|
|
// C string is terminated with a zero
|
|
let bytes = str::bytes(str) + [0u8];
|
|
ret libc::my_strlen(vec::unsafe::to_ptr(bytes));
|
|
}
|
|
|
|
fn main() {
|
|
let len = strlen("Rust");
|
|
assert(len == 4u);
|
|
}
|