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);
}
}
_ { }
--- /dev/null
+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);
+}