Skip to content

Commit 2da7622

Browse files
committed
---
yaml --- r: 6275 b: refs/heads/master c: eae478c h: refs/heads/master i: 6273: cd7736c 6271: ea279e1 v: v3
1 parent aac1c55 commit 2da7622

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
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: 0898d441cb42e09092be7772f4c24fd10e36fa72
2+
refs/heads/master: eae478cd74e9d80e2e9d2557c53e7ad2b9090240

trunk/src/comp/middle/trans.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5805,9 +5805,15 @@ fn item_path(item: @ast::item) -> [str] { ret [item.ident]; }
58055805
fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
58065806
_v: vt<[str]>) {
58075807
alt i.node {
5808-
ast::native_item_fn(_, _, _) {
5808+
ast::native_item_fn(link_name, _, _) {
58095809
if !ccx.obj_methods.contains_key(i.id) {
5810-
register_native_fn(ccx, i.span, pt, i.ident, i.id);
5810+
let name =
5811+
if option::is_some(link_name) {
5812+
option::get(link_name)
5813+
} else {
5814+
i.ident
5815+
};
5816+
register_native_fn(ccx, i.span, pt, name, i.id);
58115817
}
58125818
}
58135819
_ { }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std;
2+
3+
import std::vec;
4+
import std::str;
5+
6+
native "cdecl" mod libc = "" {
7+
fn my_strlen(str: *u8) -> uint = "strlen";
8+
}
9+
10+
fn strlen(str: str) -> uint unsafe {
11+
// C string is terminated with a zero
12+
let bytes = str::bytes(str) + [0u8];
13+
ret libc::my_strlen(vec::unsafe::to_ptr(bytes));
14+
}
15+
16+
fn main(_args: [str]) {
17+
let len = strlen("Rust");
18+
assert(len == 4u);
19+
}

0 commit comments

Comments
 (0)