parent
0898d441cb
commit
eae478cd74
2 changed files with 27 additions and 2 deletions
|
@ -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],
|
fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
|
||||||
_v: vt<[str]>) {
|
_v: vt<[str]>) {
|
||||||
alt i.node {
|
alt i.node {
|
||||||
ast::native_item_fn(_, _, _) {
|
ast::native_item_fn(link_name, _, _) {
|
||||||
if !ccx.obj_methods.contains_key(i.id) {
|
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…
Add table
Add a link
Reference in a new issue