mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
parent
0898d441cb
commit
eae478cd74
@ -5805,9 +5805,15 @@ fn item_path(item: @ast::item) -> [str] { ret [item.ident]; }
|
||||
fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
|
||||
_v: vt<[str]>) {
|
||||
alt i.node {
|
||||
ast::native_item_fn(_, _, _) {
|
||||
ast::native_item_fn(link_name, _, _) {
|
||||
if !ccx.obj_methods.contains_key(i.id) {
|
||||
register_native_fn(ccx, i.span, pt, i.ident, i.id);
|
||||
let name =
|
||||
if option::is_some(link_name) {
|
||||
option::get(link_name)
|
||||
} else {
|
||||
i.ident
|
||||
};
|
||||
register_native_fn(ccx, i.span, pt, name, i.id);
|
||||
}
|
||||
}
|
||||
_ { }
|
||||
|
19
src/test/run-pass/native-fn-linkname.rs
Normal file
19
src/test/run-pass/native-fn-linkname.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use std;
|
||||
|
||||
import std::vec;
|
||||
import std::str;
|
||||
|
||||
native "cdecl" mod libc = "" {
|
||||
fn my_strlen(str: *u8) -> uint = "strlen";
|
||||
}
|
||||
|
||||
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(_args: [str]) {
|
||||
let len = strlen("Rust");
|
||||
assert(len == 4u);
|
||||
}
|
Loading…
Reference in New Issue
Block a user