let dangerous_patterns =
~["xfail-test",
"import", // espeically fs, run
- "native",
+ "extern",
"unsafe",
"log"]; // python --> rust pipe deadlock?
export exclusive, methods;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
#[rust_stack]
fn rust_atomic_increment(p: &mut libc::intptr_t)
-> libc::intptr_t;
#[link_name = "m"]
#[abi = "cdecl"]
-native mod c_double {
+extern mod c_double {
// Alpabetically sorted by link_name
#[link_name = "m"]
#[abi = "cdecl"]
-native mod c_float {
+extern mod c_float {
// Alpabetically sorted by link_name
type port_id = int;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn rust_port_id_send(target_port: port_id, data: *()) -> libc::uintptr_t;
fn new_port(unit_sz: libc::size_t) -> *rust_port;
}
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn init<T>() -> T;
}
type fd_t = c_int;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn rust_get_stdin() -> *libc::FILE;
fn rust_get_stdout() -> *libc::FILE;
fn rust_get_stderr() -> *libc::FILE;
}
}
fn seek(_offset: int, _whence: seek_style) {
- #error("need 64-bit native calls for seek, sorry");
+ #error("need 64-bit foreign calls for seek, sorry");
fail;
}
fn tell() -> uint {
- #error("need 64-bit native calls for tell, sorry");
+ #error("need 64-bit foreign calls for tell, sorry");
fail;
}
fn flush() -> int { 0 }
#[nolink]
#[abi = "cdecl"]
- native mod ctype {
+ extern mod ctype {
fn isalnum(c: c_int) -> c_int;
fn isalpha(c: c_int) -> c_int;
fn iscntrl(c: c_int) -> c_int;
#[nolink]
#[abi = "cdecl"]
- native mod stdio {
+ extern mod stdio {
fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
fn freopen(filename: *c_char, mode: *c_char,
#[nolink]
#[abi = "cdecl"]
- native mod stdlib {
+ extern mod stdlib {
fn abs(i: c_int) -> c_int;
fn labs(i: c_long) -> c_long;
// Omitted: div, ldiv (return type incomplete).
#[nolink]
#[abi = "cdecl"]
- native mod string {
+ extern mod string {
fn strcpy(dst: *c_char, src: *c_char) -> *c_char;
fn strncpy(dst: *c_char, src: *c_char, n: size_t) -> *c_char;
#[nolink]
#[abi = "cdecl"]
- native mod stat {
+ extern mod stat {
#[link_name = "_chmod"]
fn chmod(path: *c_char, mode: c_int) -> c_int;
#[nolink]
#[abi = "cdecl"]
- native mod stdio {
+ extern mod stdio {
#[link_name = "_popen"]
fn popen(command: *c_char, mode: *c_char) -> *FILE;
#[nolink]
#[abi = "cdecl"]
- native mod fcntl {
+ extern mod fcntl {
#[link_name = "_open"]
fn open(path: *c_char, oflag: c_int, mode: c_int) -> c_int;
#[nolink]
#[abi = "cdecl"]
- native mod dirent {
+ extern mod dirent {
// Not supplied at all.
}
#[nolink]
#[abi = "cdecl"]
- native mod unistd {
+ extern mod unistd {
#[link_name = "_access"]
fn access(path: *c_char, amode: c_int) -> c_int;
#[nolink]
#[abi = "cdecl"]
- native mod stat {
+ extern mod stat {
fn chmod(path: *c_char, mode: mode_t) -> c_int;
fn fchmod(fd: c_int, mode: mode_t) -> c_int;
fn mkdir(path: *c_char, mode: mode_t) -> c_int;
#[nolink]
#[abi = "cdecl"]
- native mod stdio {
+ extern mod stdio {
fn popen(command: *c_char, mode: *c_char) -> *FILE;
fn pclose(stream: *FILE) -> c_int;
fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
#[nolink]
#[abi = "cdecl"]
- native mod fcntl {
+ extern mod fcntl {
fn open(path: *c_char, oflag: c_int, mode: c_int) -> c_int;
fn creat(path: *c_char, mode: mode_t) -> c_int;
fn fcntl(fd: c_int, cmd: c_int) -> c_int;
#[nolink]
#[abi = "cdecl"]
- native mod dirent {
+ extern mod dirent {
fn opendir(dirname: *c_char) -> *DIR;
fn closedir(dirp: *DIR) -> c_int;
fn readdir(dirp: *DIR) -> *dirent;
#[nolink]
#[abi = "cdecl"]
- native mod unistd {
+ extern mod unistd {
fn access(path: *c_char, amode: c_int) -> c_int;
fn alarm(seconds: c_uint) -> c_uint;
fn chdir(dir: *c_char) -> c_int;
#[nolink]
#[abi = "cdecl"]
- native mod unistd {
+ extern mod unistd {
fn readlink(path: *c_char, buf: *mut c_char,
bufsz: size_t) -> ssize_t;
#[nolink]
#[abi = "cdecl"]
- native mod wait {
+ extern mod wait {
fn waitpid(pid: pid_t, status: *mut c_int,
options: c_int) -> pid_t;
}
#[cfg(target_os = "win32")]
mod posix01 {
#[nolink]
- native mod unistd { }
+ extern mod unistd { }
}
#[cfg(target_os = "freebsd")]
mod posix08 {
#[nolink]
- native mod unistd { }
+ extern mod unistd { }
}
#[cfg(target_os = "freebsd")]
#[nolink]
#[abi = "cdecl"]
- native mod bsd44 {
+ extern mod bsd44 {
fn sysctl(name: *c_int, namelen: c_uint,
oldp: *mut c_void, oldlenp: *mut size_t,
#[cfg(target_os = "macos")]
#[nolink]
#[abi = "cdecl"]
- native mod extra {
+ extern mod extra {
fn _NSGetExecutablePath(buf: *mut c_char,
bufsize: *mut u32) -> c_int;
}
import types::os::arch::extra::*;
#[abi = "stdcall"]
- native mod kernel32 {
+ extern mod kernel32 {
fn GetEnvironmentVariableW(n: LPCWSTR,
v: LPWSTR,
nsize: DWORD) -> DWORD;
#[abi = "cdecl"]
#[nolink]
- native mod msvcrt {
+ extern mod msvcrt {
#[link_name = "_commit"]
fn commit(fd: c_int) -> c_int;
}
export console_on, console_off;
#[nolink]
-native mod rustrt {
+extern mod rustrt {
fn rust_log_console_on();
fn rust_log_console_off();
}
// FIXME: move these to str perhaps? #2620
export as_c_charp, fill_charp_buf;
-native mod rustrt {
+extern mod rustrt {
fn rust_env_pairs() -> ~[str];
fn rust_getcwd() -> str;
fn rust_path_is_dir(path: *libc::c_char) -> c_int;
export getenv;
export setenv;
- native mod rustrt {
+ extern mod rustrt {
fn rust_global_env_chan_ptr() -> *libc::uintptr_t;
}
type rust_port_id = uint;
-native mod rustrt {
+extern mod rustrt {
fn rust_compare_and_swap_ptr(address: *libc::uintptr_t,
oldval: libc::uintptr_t,
newval: libc::uintptr_t) -> bool;
#[nolink]
#[abi = "cdecl"]
-native mod libc_ {
+extern mod libc_ {
#[rust_stack]
fn memcpy(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void;
#[rust_stack]
}
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn addr_of<T>(val: T) -> *T;
}
enum rctx {}
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn rand_seed() -> ~[u8];
fn rand_new() -> *rctx;
fn rand_new_seeded(seed: ~[u8]) -> *rctx;
export waitpid;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn rust_run_program(argv: **libc::c_char, envp: *c_void,
dir: *libc::c_char,
in_fd: c_int, out_fd: c_int, err_fd: c_int)
if *frame_address == 0u {
#debug("encountered task_start_wrapper. ending walk");
// This is the task_start_wrapper_frame. There is
- // no stack beneath it and it is a native frame.
+ // no stack beneath it and it is a foreign frame.
break;
}
}
rusti::frame_address(f)
}
-native mod rustrt {
+extern mod rustrt {
fn rust_dbg_breakpoint();
}
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn frame_address(f: fn(*u8));
}
extensions;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn rust_str_push(&s: str, ch: u8);
fn str_reserve_shared(&ss: str, nn: libc::size_t);
}
#[doc = "
Work with the byte buffer of a string.
-Allows for unsafe manipulation of strings, which is useful for native
+Allows for unsafe manipulation of strings, which is useful for foreign
interop.
# Example
#[doc = "
Work with the byte buffer of a string.
-Allows for unsafe manipulation of strings, which is useful for native
+Allows for unsafe manipulation of strings, which is useful for foreign
interop.
"]
pure fn as_buf<T>(s: str, f: fn(*u8) -> T) -> T {
#[doc = "
Work with the byte buffer of a string as a null-terminated C string.
-Allows for unsafe manipulation of strings, which is useful for native
+Allows for unsafe manipulation of strings, which is useful for foreign
interop, without copying the original string.
# Example
type rust_cond_lock = *libc::c_void;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn unsupervise();
pure fn shape_log_str(t: *sys::type_desc, data: *()) -> str;
}
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn get_tydesc<T>() -> *();
fn size_of<T>() -> uint;
fn pref_align_of<T>() -> uint;
// We use dvec because it's the best data structure in core. If TLS is used
// heavily in future, this could be made more efficient with a proper map.
type task_local_element = (*libc::c_void, *libc::c_void, fn@(+*libc::c_void));
-// Has to be a pointer at the outermost layer; the native call returns void *.
+// Has to be a pointer at outermost layer; the foreign call returns void *.
type task_local_map = @dvec::dvec<option<task_local_element>>;
crust fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe {
local_modify(rustrt::rust_get_task(), key, modify_fn)
}
-native mod rustrt {
+extern mod rustrt {
#[rust_stack]
fn rust_task_yield(task: *rust_task, &killed: bool);
#[nolink]
#[cfg(test)]
-native mod testrt {
+extern mod testrt {
fn rust_dbg_lock_create() -> *libc::c_void;
fn rust_dbg_lock_destroy(lock: *libc::c_void);
fn rust_dbg_lock_lock(lock: *libc::c_void);
export reinterpret_cast, forget, bump_box_refcount, transmute;
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn forget<T>(-x: T);
fn reinterpret_cast<T, U>(e: T) -> U;
}
export extensions;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn vec_reserve_shared(++t: *sys::type_desc,
++v: **unsafe::vec_repr,
++n: libc::size_t);
}
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn move_val_init<T>(&dst: T, -src: T);
}
#[doc = "
Work with the buffer of a vector.
-Allows for unsafe manipulation of vector contents, which is useful for native
-interop.
+Allows for unsafe manipulation of vector contents, which is useful for
+foreign interop.
"]
fn as_buf<E,T>(v: &[E], f: fn(*E) -> T) -> T {
unpack_slice(v, |buf, _len| f(buf))
export ptr;
#[doc = "
-The type representing a native chunk of memory
+The type representing a foreign chunk of memory
Wrapped in a enum for opacity; FIXME #818 when it is possible to have
truly opaque types, this should be revisited.
*/
#[doc = "
-Create a `c_vec` from a native buffer with a given length.
+Create a `c_vec` from a foreign buffer with a given length.
# Arguments
-* base - A native pointer to a buffer
+* base - A foreign pointer to a buffer
* len - The number of elements in the buffer
"]
unsafe fn c_vec<T>(base: *mut T, len: uint) -> c_vec<T> {
}
#[doc = "
-Create a `c_vec` from a native buffer, with a given length,
+Create a `c_vec` from a foreign buffer, with a given length,
and a function to run upon destruction.
# Arguments
-* base - A native pointer to a buffer
+* base - A foreign pointer to a buffer
* len - The number of elements in the buffer
* dtor - A function to run when the value is destructed, useful
for freeing the buffer, etc.
export breakpoint;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn debug_tydesc(td: *sys::type_desc);
fn debug_opaque(td: *sys::type_desc, x: *());
fn debug_box(td: *sys::type_desc, x: *());
export connect;
#[nolink]
-native mod rustrt {
+extern mod rustrt {
fn rust_uv_current_kernel_malloc(size: libc::c_uint) -> *libc::c_void;
fn rust_uv_current_kernel_free(mem: *libc::c_void);
fn rust_uv_helper_uv_tcp_t_size() -> libc::c_uint;
export run_tests_console;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn sched_threads() -> libc::size_t;
}
strptime;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn get_time(&sec: i64, &nsec: i32);
fn precise_time_ns(&ns: u64);
#[link_name = "icuuc"]
#[abi = "cdecl"]
- native mod libicu {
+ extern mod libicu {
pure fn u_hasBinaryProperty(c: UChar32, which: UProperty) -> UBool;
pure fn u_isdigit(c: UChar32) -> UBool;
pure fn u_islower(c: UChar32) -> UBool;
import comm::{port, chan, methods, select2, listen};
import either::{left, right};
-native mod rustrt {
+extern mod rustrt {
fn rust_uv_get_kernel_global_chan_ptr() -> *libc::uintptr_t;
}
}
#[nolink]
-native mod rustrt {
+extern mod rustrt {
// libuv public API
fn rust_uv_loop_new() -> *libc::c_void;
fn rust_uv_loop_delete(lp: *libc::c_void);
addr_ptr: *sockaddr_in,
++after_connect_cb: *u8)
-> libc::c_int {
- log(debug, #fmt("b4 native tcp_connect--addr port: %u cb: %u",
+ log(debug, #fmt("b4 foreign tcp_connect--addr port: %u cb: %u",
(*addr_ptr).sin_port as uint, after_connect_cb as uint));
ret rustrt::rust_uv_tcp_connect(connect_ptr, tcp_handle_ptr,
after_connect_cb, addr_ptr);
fn test_uv_ll_struct_size_uv_tcp_t() {
let foreign_handle_size = rustrt::rust_uv_helper_uv_tcp_t_size();
let rust_handle_size = sys::size_of::<uv_tcp_t>();
- let output = #fmt("uv_tcp_t -- native: %u rust: %u",
+ let output = #fmt("uv_tcp_t -- foreign: %u rust: %u",
foreign_handle_size as uint, rust_handle_size);
log(debug, output);
assert foreign_handle_size as uint == rust_handle_size;
let foreign_handle_size =
rustrt::rust_uv_helper_uv_connect_t_size();
let rust_handle_size = sys::size_of::<uv_connect_t>();
- let output = #fmt("uv_connect_t -- native: %u rust: %u",
+ let output = #fmt("uv_connect_t -- foreign: %u rust: %u",
foreign_handle_size as uint, rust_handle_size);
log(debug, output);
assert foreign_handle_size as uint == rust_handle_size;
let foreign_handle_size =
rustrt::rust_uv_helper_uv_buf_t_size();
let rust_handle_size = sys::size_of::<uv_buf_t>();
- let output = #fmt("uv_buf_t -- native: %u rust: %u",
+ let output = #fmt("uv_buf_t -- foreign: %u rust: %u",
foreign_handle_size as uint, rust_handle_size);
log(debug, output);
assert foreign_handle_size as uint == rust_handle_size;
let foreign_handle_size =
rustrt::rust_uv_helper_uv_write_t_size();
let rust_handle_size = sys::size_of::<uv_write_t>();
- let output = #fmt("uv_write_t -- native: %u rust: %u",
+ let output = #fmt("uv_write_t -- foreign: %u rust: %u",
foreign_handle_size as uint, rust_handle_size);
log(debug, output);
assert foreign_handle_size as uint == rust_handle_size;
let foreign_handle_size =
rustrt::rust_uv_helper_sockaddr_in_size();
let rust_handle_size = sys::size_of::<sockaddr_in>();
- let output = #fmt("sockaddr_in -- native: %u rust: %u",
+ let output = #fmt("sockaddr_in -- foreign: %u rust: %u",
foreign_handle_size as uint, rust_handle_size);
log(debug, output);
assert foreign_handle_size as uint == rust_handle_size;
let native_handle_size =
rustrt::rust_uv_helper_sockaddr_in6_size();
let rust_handle_size = sys::size_of::<sockaddr_in6>();
- let output = #fmt("sockaddr_in6 -- native: %u rust: %u",
+ let output = #fmt("sockaddr_in6 -- foreign: %u rust: %u",
native_handle_size as uint, rust_handle_size);
log(debug, output);
// FIXME #1645 .. rust appears to pad structs to the nearest byte..?
let native_handle_size =
rustrt::rust_uv_helper_addr_in_size();
let rust_handle_size = sys::size_of::<addr_in>();
- let output = #fmt("addr_in -- native: %u rust: %u",
+ let output = #fmt("addr_in -- foreign: %u rust: %u",
native_handle_size as uint, rust_handle_size);
log(debug, output);
// FIXME #1645 .. see note above about struct padding
let foreign_handle_size =
rustrt::rust_uv_helper_uv_async_t_size();
let rust_handle_size = sys::size_of::<uv_async_t>();
- let output = #fmt("uv_async_t -- native: %u rust: %u",
+ let output = #fmt("uv_async_t -- foreign: %u rust: %u",
foreign_handle_size as uint, rust_handle_size);
log(debug, output);
assert foreign_handle_size as uint == rust_handle_size;
let foreign_handle_size =
rustrt::rust_uv_helper_uv_timer_t_size();
let rust_handle_size = sys::size_of::<uv_timer_t>();
- let output = #fmt("uv_timer_t -- native: %u rust: %u",
+ let output = #fmt("uv_timer_t -- foreign: %u rust: %u",
foreign_handle_size as uint, rust_handle_size);
log(debug, output);
assert foreign_handle_size as uint == rust_handle_size;
let native_handle_size =
rustrt::rust_uv_helper_uv_getaddrinfo_t_size();
let rust_handle_size = sys::size_of::<uv_getaddrinfo_t>();
- let output = #fmt("uv_getaddrinfo_t -- native: %u rust: %u",
+ let output = #fmt("uv_getaddrinfo_t -- foreign: %u rust: %u",
native_handle_size as uint, rust_handle_size);
log(debug, output);
assert native_handle_size as uint == rust_handle_size;
let native_handle_size =
rustrt::rust_uv_helper_addrinfo_size();
let rust_handle_size = sys::size_of::<addrinfo>();
- let output = #fmt("addrinfo -- native: %u rust: %u",
+ let output = #fmt("addrinfo -- foreign: %u rust: %u",
native_handle_size as uint, rust_handle_size);
log(debug, output);
assert native_handle_size as uint == rust_handle_size;
#[auto_serialize]
enum proto {
- proto_bare, // native fn
+ proto_bare, // foreign fn
proto_any, // fn
proto_uniq, // fn~
proto_box, // fn@
#fmt["item %s (id=%?)", path_ident_to_str(*path, item.ident), id]
}
some(node_foreign_item(item, abi, path)) {
- #fmt["native item %s with abi %? (id=%?)",
+ #fmt["foreign item %s with abi %? (id=%?)",
path_ident_to_str(*path, item.ident), abi, id]
}
some(node_method(m, impl_did, path)) {
let ula = cstore::get_used_link_args(cstore);
for ula.each |arg| { vec::push(cc_args, arg); }
- // # Native library linking
+ // # Extern library linking
// User-supplied library search paths (-L on the cammand line) These are
// the same paths used to find Rust crates, so some of them may have been
let addl_paths = sess.opts.addl_lib_search_paths;
for addl_paths.each |path| { vec::push(cc_args, "-L" + path); }
- // The names of the native libraries
+ // The names of the extern libraries
let used_libs = cstore::get_used_libraries(cstore);
for used_libs.each |l| { vec::push(cc_args, "-l" + l); }
vec::push(cc_args, "-lmorestack");
// FIXME (#2397): At some point we want to rpath our guesses as to where
- // native libraries might live, based on the addl_lib_search_paths
+ // extern libraries might live, based on the addl_lib_search_paths
vec::push_all(cc_args, rpath::get_rpath_flags(sess, output));
#debug("%s link args: %s", cc_prog, str::connect(cc_args, " "));
let sysroot = sess.filesearch.sysroot();
let output = out_filename;
let libs = cstore::get_used_crate_files(sess.cstore);
- // We don't currently rpath native libraries, but we know
+ // We don't currently rpath extern libraries, but we know
// where rustrt is and we know every rust program needs it
let libs = vec::append_one(libs, get_sysroot_absolute_rt_lib(sess));
}
#[abi = "rust-intrinsic"]
- native mod rusti {
+ extern mod rusti {
fn visit_ty<T>(&&tv: ty_visitor);
}
}
#[link_args = "-Lrustllvm"]
#[link_name = "rustllvm"]
#[abi = "cdecl"]
-native mod llvm {
+extern mod llvm {
/* Create and destroy contexts. */
fn LLVMContextCreate() -> ContextRef;
fn LLVMGetGlobalContext() -> ContextRef;
#[doc = "
-Validates all used crates and native libraries and loads their metadata
+Validates all used crates and extern libraries and loads their metadata
"];
export read_crates;
-// Traverses an AST, reading all the information about use'd crates and native
+// Traverses an AST, reading all the information about use'd crates and extern
// libraries necessary for later resolving, typechecking, linking, etc.
fn read_crates(diag: span_handler, crate: ast::crate,
cstore: cstore::cstore, filesearch: filesearch,
'f' { ret "fn"; }
'u' { ret "unsafe fn"; }
'p' { ret "pure fn"; }
- 'F' { ret "native fn"; }
- 'U' { ret "unsafe native fn"; }
- 'P' { ret "pure native fn"; }
+ 'F' { ret "foreign fn"; }
+ 'U' { ret "unsafe foreign fn"; }
+ 'P' { ret "pure foreign fn"; }
'y' { ret "type"; }
- 'T' { ret "native type"; }
+ 'T' { ret "foreign type"; }
't' { ret "type"; }
'm' { ret "mod"; }
- 'n' { ret "native mod"; }
+ 'n' { ret "foreign mod"; }
'v' { ret "enum"; }
'i' { ret "impl"; }
'I' { ret "iface"; }
let v = ~[
("ctypes",
@{lint: ctypes,
- desc: "proper use of core::libc types in native modules",
+ desc: "proper use of core::libc types in foreign modules",
default: warn}),
("unused_imports",
cx.sess.span_lint(
ctypes, id, fn_id,
ty.span,
- "found rust type `int` in native module, while \
+ "found rust type `int` in foreign module, while \
libc::c_int or libc::c_long should be used");
}
ast::def_prim_ty(ast::ty_uint(ast::ty_u)) {
cx.sess.span_lint(
ctypes, id, fn_id,
ty.span,
- "found rust type `uint` in native module, while \
+ "found rust type `uint` in foreign module, while \
libc::c_uint or libc::c_ulong should be used");
}
_ { }
path: str
};
-/* native modules can't contain enums, and we don't store their ASTs because
+/* foreign modules can't contain enums, and we don't store their ASTs because
we only need to look at them to determine exports, which they can't
control.*/
module %d not in mod_map", node_id)); }
};
if dr == outside && !is_exported(e, id, inf) {
- // if we're in a native mod, then dr==inside, so inf.m is some _mod
+ // if we're in a foreign mod, then dr==inside, so inf.m is some _mod
ret none; // name is not visible
}
alt inf.index.find(id) {
ast::item_fn(decl, tps, body) {
if decl.purity == ast::extern_fn {
let llfndecl = get_item_val(ccx, item.id);
- foreign::trans_extern_fn(ccx,
+ foreign::trans_foreign_fn(ccx,
vec::append(
*path,
~[path_name(item.ident)]),
let llfn = if decl.purity != ast::extern_fn {
register_fn(ccx, i.span, my_path, i.id)
} else {
- foreign::register_extern_fn(ccx, i.span, my_path, i.id)
+ foreign::register_foreign_fn(ccx, i.span, my_path, i.id)
};
set_inline_hint_if_appr(i.attrs, llfn);
llfn
import std::map::hashmap;
import util::ppaux::ty_to_str;
-export link_name, trans_foreign_mod, register_extern_fn, trans_extern_fn,
+export link_name, trans_foreign_mod, register_foreign_fn, trans_foreign_fn,
trans_intrinsic;
enum x86_64_reg_class {
Unreachable(ret_cx);
}
-// For each native function F, we generate a wrapper function W and a shim
+// For each foreign function F, we generate a wrapper function W and a shim
// function S that all work together. The wrapper function W is the function
// that other rust code actually invokes. Its job is to marshall the
// arguments into a struct. It then uses a small bit of assembly to switch
// unpacks the arguments from the struct and invokes the actual function F
// according to its specified calling convention.
//
-// Example: Given a native c-stack function F(x: X, y: Y) -> Z,
+// Example: Given a foreign c-stack function F(x: X, y: Y) -> Z,
// we generate a wrapper function W that looks like:
//
// void W(Z* dest, void *env, X x, Y y) {
finish_fn(fcx, lltop);
}
-fn trans_extern_fn(ccx: @crate_ctxt, path: ast_map::path, decl: ast::fn_decl,
+fn trans_foreign_fn(ccx: @crate_ctxt, path: ast_map::path, decl: ast::fn_decl,
body: ast::blk, llwrapfn: ValueRef, id: ast::node_id) {
- let _icx = ccx.insn_ctxt("foreign::build_extern_fn");
+ let _icx = ccx.insn_ctxt("foreign::build_foreign_fn");
fn build_rust_fn(ccx: @crate_ctxt, path: ast_map::path,
decl: ast::fn_decl, body: ast::blk,
id: ast::node_id) -> ValueRef {
- let _icx = ccx.insn_ctxt("foreign::extern::build_rust_fn");
+ let _icx = ccx.insn_ctxt("foreign::foreign::build_rust_fn");
let t = ty::node_id_to_type(ccx.tcx, id);
let ps = link::mangle_internal_name_by_path(
ccx, vec::append_one(path, ast_map::path_name(@"__rust_abi")));
fn build_shim_fn(ccx: @crate_ctxt, path: ast_map::path,
llrustfn: ValueRef, tys: @c_stack_tys) -> ValueRef {
- let _icx = ccx.insn_ctxt("foreign::extern::build_shim_fn");
+ let _icx = ccx.insn_ctxt("foreign::foreign::build_shim_fn");
fn build_args(bcx: block, tys: @c_stack_tys,
llargbundle: ValueRef) -> ~[ValueRef] {
fn build_wrap_fn(ccx: @crate_ctxt, llshimfn: ValueRef,
llwrapfn: ValueRef, tys: @c_stack_tys) {
- let _icx = ccx.insn_ctxt("foreign::extern::build_wrap_fn");
+ let _icx = ccx.insn_ctxt("foreign::foreign::build_wrap_fn");
fn build_args(bcx: block, tys: @c_stack_tys,
llwrapfn: ValueRef, llargbundle: ValueRef) {
- let _icx = bcx.insn_ctxt("foreign::extern::wrap::build_args");
+ let _icx = bcx.insn_ctxt("foreign::foreign::wrap::build_args");
alt tys.x86_64_tys {
option::some(x86_64) {
let mut atys = x86_64.arg_tys;
fn build_ret(bcx: block, tys: @c_stack_tys,
llargbundle: ValueRef) {
- let _icx = bcx.insn_ctxt("foreign::extern::wrap::build_ret");
+ let _icx = bcx.insn_ctxt("foreign::foreign::wrap::build_ret");
alt tys.x86_64_tys {
option::some(x86_64) {
if x86_64.sret || !tys.ret_def {
let llrustfn = build_rust_fn(ccx, path, decl, body, id);
// The internal shim function - runs on the Rust stack
let llshimfn = build_shim_fn(ccx, path, llrustfn, tys);
- // The external C function - runs on the C stack
+ // The foreign C function - runs on the C stack
build_wrap_fn(ccx, llshimfn, llwrapfn, tys)
}
-fn register_extern_fn(ccx: @crate_ctxt, sp: span,
+fn register_foreign_fn(ccx: @crate_ctxt, sp: span,
path: ast_map::path, node_id: ast::node_id)
-> ValueRef {
- let _icx = ccx.insn_ctxt("foreign::register_extern_fn");
+ let _icx = ccx.insn_ctxt("foreign::register_foreign_fn");
let t = ty::node_id_to_type(ccx.tcx, node_id);
let (llargtys, llretty, ret_ty) = c_arg_and_ret_lltys(ccx, node_id);
ret if ccx.sess.targ_cfg.arch == arch_x86_64 {
if !ok {
tcx.sess.span_err(main_span,
#fmt("Wrong type in main function: found `%s`, \
- expecting `native fn(~[str]) -> ()` \
- or `native fn() -> ()`",
+ expecting `extern fn(~[str]) -> ()` \
+ or `extern fn() -> ()`",
ty_to_str(tcx, main_t)));
}
}
if (*tpt.bounds).is_not_empty() {
ccx.tcx.sess.span_err(
item.span,
- #fmt["native items may not have type parameters"]);
+ #fmt["foreign items may not have type parameters"]);
}
}
}
// really hard due to the way that expr_bind() is
// written.
fcx.ccx.tcx.sess.span_fatal(sp, "mismatched types: \
- expected function or native \
- function but found "
+ expected function or foreign \
+ function but found "
+ fcx.infcx.ty_to_str(in_fty));
}
};
}
fn convert_foreign(ccx: @crate_ctxt, i: @ast::foreign_item) {
// As above, this call populates the type table with the converted
- // type of the native item. We simply write it into the node type
+ // type of the foreign item. We simply write it into the node type
// table.
let tpt = ty_of_foreign_item(ccx, i);
alt i.node {
#[test]
fn should_extract_foreign_mod_attributes() {
- let doc = test::mk_doc("#[doc = \"test\"] native mod a { }");
+ let doc = test::mk_doc("#[doc = \"test\"] extern mod a { }");
assert doc.cratemod().nmods()[0].desc() == some("test");
}
#[test]
fn should_extract_foreign_fn_attributes() {
- let doc = test::mk_doc("native mod a { #[doc = \"test\"] fn a(); }");
+ let doc = test::mk_doc("extern mod a { #[doc = \"test\"] fn a(); }");
assert doc.cratemod().nmods()[0].fns[0].desc() == some("test");
}
#[test]
fn extract_foreign_mods() {
- let doc = mk_doc("native mod a { }");
+ let doc = mk_doc("extern mod a { }");
assert doc.cratemod().nmods()[0].name() == "a";
}
#[test]
fn extract_fns_from_foreign_mods() {
- let doc = mk_doc("native mod a { fn a(); }");
+ let doc = mk_doc("extern mod a { fn a(); }");
assert doc.cratemod().nmods()[0].fns[0].name() == "a";
}
fn should_index_foreign_mod_pages() {
let doc = test::mk_doc(
config::doc_per_mod,
- "native mod a { }"
+ "extern mod a { }"
);
assert option::get(doc.cratemod().index).entries[0] == {
- kind: "Native module",
+ kind: "Foreign module",
name: "a",
brief: none,
link: "a.html"
fn should_index_foreign_mod_contents() {
let doc = test::mk_doc(
config::doc_per_crate,
- "native mod a { fn b(); }"
+ "extern mod a { fn b(); }"
);
assert option::get(doc.cratemod().nmods()[0].index).entries[0] == {
kind: "Function",
}
}
doc::nmodtag(_) {
- "Native module"
+ "Foreign module"
}
doc::fntag(_) {
"Function"
#[test]
fn should_write_index_for_foreign_mods() {
- let markdown = test::render("native mod a { fn a(); }");
+ let markdown = test::render("extern mod a { fn a(); }");
assert str::contains(
markdown,
"\n\n* [Function `a`](#function-a)\n\n"
#[test]
fn should_write_foreign_mods() {
- let markdown = test::render("#[doc = \"test\"] native mod a { }");
- assert str::contains(markdown, "Native module `a`");
+ let markdown = test::render("#[doc = \"test\"] extern mod a { }");
+ assert str::contains(markdown, "Foreign module `a`");
assert str::contains(markdown, "test");
}
#[test]
fn should_write_foreign_fns() {
- let markdown = test::render("native mod a { #[doc = \"test\"] fn a(); }");
+ let markdown = test::render("extern mod a { #[doc = \"test\"] fn a(); }");
assert str::contains(markdown, "test");
}
#[test]
fn should_write_foreign_fn_headers() {
- let markdown = test::render("native mod a { #[doc = \"test\"] fn a(); }");
+ let markdown = test::render("extern mod a { #[doc = \"test\"] fn a(); }");
assert str::contains(markdown, "## Function `a`");
}
#[test]
fn should_make_a_page_for_every_foreign_mod() {
- let doc = test::mk_doc("native mod a { }");
+ let doc = test::mk_doc("extern mod a { }");
assert doc.pages.nmods()[0].name() == "a";
}
#[test]
fn should_remove_foreign_mods_from_containing_mods() {
- let doc = test::mk_doc("native mod a { }");
+ let doc = test::mk_doc("extern mod a { }");
assert vec::is_empty(doc.cratemod().nmods());
}
#[test]
fn should_record_foreign_mod_paths() {
- let source = "mod a { native mod b { } }";
+ let source = "mod a { extern mod b { } }";
do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
#[test]
fn should_record_foreign_fn_paths() {
- let source = "native mod a { fn b(); }";
+ let source = "extern mod a { fn b(); }";
do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
#[test]
fn should_duplicate_reexported_foreign_fns() {
- let source = "native mod a { fn b(); } \
+ let source = "extern mod a { fn b(); } \
mod c { import a::b; export b; }";
let doc = test::mk_doc(source);
assert doc.cratemod().mods()[0].fns()[0].name() == "b";
fn test() {
let source =
"mod imod { } \
- native mod inmod { } \
+ extern mod inmod { } \
const iconst: int = 0; \
fn ifn() { } \
enum ienum { ivar } \
#[test]
fn should_add_foreign_fn_sig() {
- let doc = test::mk_doc("native mod a { fn a<T>() -> int; }");
+ let doc = test::mk_doc("extern mod a { fn a<T>() -> int; }");
assert doc.cratemod().nmods()[0].fns[0].sig == some("fn a<T>() -> int");
}
#[link(name="foreign_lib", vers="0.0")];
-native mod rustrt {
+extern mod rustrt {
fn last_os_error() -> str;
}
\ No newline at end of file
type port_id = int;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn new_port(unit_sz: libc::size_t) -> *rust_port;
fn del_port(po: *rust_port);
}
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn init<T>() -> T;
}
// stub. Kind of shocking. Might be able to make it faster still with
// an llvm intrinsic.
#[nolink]
-native mod libc {
+extern mod libc {
fn sqrt(n: float) -> float;
}
-// error-pattern:expecting `native fn(~[str])
+// error-pattern:expecting `extern fn(~[str])
fn main(x: int) { }
fn main() {
let x = 3;
- fn blah(_a: native fn()) {}
+ fn blah(_a: extern fn()) {}
blah(|| {
log(debug, x); //~ ERROR attempted dynamic environment capture
});
// other tycons.
fn main() {
- fn f(f: native fn(native fn(native fn()))) {
+ fn f(f: extern fn(extern fn(extern fn()))) {
}
- fn g(f: native fn(fn())) {
+ fn g(f: extern fn(fn())) {
}
f(g);
// Make sure that fn-to-block coercion isn't incorrectly lifted over
// other tycons.
-fn coerce(b: fn()) -> native fn() {
- fn lol(f: native fn(fn()) -> native fn(),
- g: fn()) -> native fn() { ret f(g); }
- fn fn_id(f: native fn()) -> native fn() { ret f }
+fn coerce(b: fn()) -> extern fn() {
+ fn lol(f: extern fn(fn()) -> extern fn(),
+ g: fn()) -> extern fn() { ret f(g); }
+ fn fn_id(f: extern fn()) -> extern fn() { ret f }
ret lol(fn_id, b);
//~^ ERROR mismatched types: expected `extern fn(fn()) -> extern fn()`
}
-// error-pattern:expected function or native function but found *u8
+// error-pattern:expected function or foreign function but found *u8
crust fn f() {
}
// error-pattern:empty #[link_name] not allowed; use #[nolink].
#[link_name = ""]
-native mod foo {
+extern mod foo {
}
#[link_name = ""]
#[nolink]
-native mod foo {
+extern mod foo {
}
--- /dev/null
+// -*- rust -*-
+
+#[abi = "cdecl"]
+extern mod test {
+ unsafe fn free();
+}
+
+fn main() {
+ test::free();
+ //~^ ERROR access to unsafe function requires unsafe function or block
+}
+
--- /dev/null
+// -*- rust -*-
+
+#[abi = "cdecl"]
+extern mod test {
+ unsafe fn free();
+}
+
+fn main() {
+ let x = test::free;
+ //~^ ERROR access to unsafe function requires unsafe function or block
+}
+
+
+++ /dev/null
-// -*- rust -*-
-
-#[abi = "cdecl"]
-native mod test {
- unsafe fn free();
-}
-
-fn main() {
- test::free();
- //~^ ERROR access to unsafe function requires unsafe function or block
-}
-
+++ /dev/null
-// -*- rust -*-
-
-#[abi = "cdecl"]
-native mod test {
- unsafe fn free();
-}
-
-fn main() {
- let x = test::free;
- //~^ ERROR access to unsafe function requires unsafe function or block
-}
-
-
#[link_args = "aFdEfSeVEEE"]
#[nolink]
-native mod m1 { }
+extern mod m1 { }
fn main() { }
\ No newline at end of file
#[link_name= "m"]
#[link_args="-foo"] // this could have been elided.
-native mod m1 {
+extern mod m1 {
}
#[link_name= "m"]
#[link_args="-bar"] // this is the actual error trigger.
-native mod m2 {
+extern mod m2 {
}
// error-pattern:unsupported cast
fn main() {
- log(debug, 1.0 as *libc::FILE); // Can't cast float to native.
+ log(debug, 1.0 as *libc::FILE); // Can't cast float to foreign.
}
#[warn(err_ctypes)];
#[nolink]
-native mod libc {
+extern mod libc {
fn malloc(size: int) -> *u8;
}
// compile-flags:-W err-ctypes
// error-pattern:found rust type
#[nolink]
-native mod libc {
+extern mod libc {
fn malloc(size: int) -> *u8;
}
--- /dev/null
+//error-pattern:libc::c_int or libc::c_long should be used
+extern mod xx {
+ fn strlen(str: *u8) -> uint;
+ fn foo(x: int, y: uint);
+}
+
+fn main() {
+ // let it fail to verify warning message
+ fail
+}
+++ /dev/null
-//error-pattern:libc::c_int or libc::c_long should be used
-native mod xx {
- fn strlen(str: *u8) -> uint;
- fn foo(x: int, y: uint);
-}
-
-fn main() {
- // let it fail to verify warning message
- fail
-}
// Testing that runtime failure doesn't cause callbacks to abort abnormally.
// Instead the failure will be delivered after the callbacks return.
-native mod rustrt {
+extern mod rustrt {
fn rust_dbg_call(cb: *u8,
data: libc::uintptr_t) -> libc::uintptr_t;
}
use std;
-native mod rustrt {
+extern mod rustrt {
fn last_os_error() -> str;
}
#[abi = "cdecl"]
#[nolink]
-native mod test {
+extern mod test {
fn unsupervise();
fn get_task_id();
}
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn unsupervise();
}
#[abi = "cdecl"]
#[nolink]
-native mod libc {
+extern mod libc {
fn atol(x: *u8) -> int;
fn atoll(x: *u8) -> i64;
}
class cat {
- let done : native fn(uint);
+ let done : extern fn(uint);
let meows : uint;
- new(done: native fn(uint)) {
+ new(done: extern fn(uint)) {
self.meows = 0u;
self.done = done;
}
#[cfg(bogus)]
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
// This symbol doesn't exist and would be a link error if this
// module was translated
fn bogus();
}
#[abi = "cdecl"]
-native mod rustrt { }
+extern mod rustrt { }
#[cfg(bogus)]
type t = int;
mod test_foreign_items {
#[abi = "cdecl"]
- native mod rustrt {
+ extern mod rustrt {
#[cfg(bogus)]
fn vec_from_buf_shared();
fn vec_from_buf_shared();
-native mod rustrt {
+extern mod rustrt {
fn rust_dbg_call(cb: *u8,
data: libc::uintptr_t) -> libc::uintptr_t;
}
-native mod rustrt {
+extern mod rustrt {
fn rust_dbg_call(cb: *u8,
data: libc::uintptr_t) -> libc::uintptr_t;
}
// make sure the stack pointers are maintained properly in both
// directions
-native mod rustrt {
+extern mod rustrt {
fn rust_dbg_call(cb: *u8,
data: libc::uintptr_t) -> libc::uintptr_t;
}
-native mod rustrt {
+extern mod rustrt {
fn rust_dbg_call(cb: *u8,
data: libc::uintptr_t) -> libc::uintptr_t;
}
// This creates a bunch of yielding tasks that run concurrently
// while holding onto C stacks
-native mod rustrt {
+extern mod rustrt {
fn rust_dbg_call(cb: *u8,
data: libc::uintptr_t) -> libc::uintptr_t;
}
-native mod rustrt {
+extern mod rustrt {
fn rust_dbg_call(cb: *u8,
data: libc::uintptr_t) -> libc::uintptr_t;
}
fn test_fn() {
- type t = native fn() -> int;
+ type t = extern fn() -> int;
fn ten() -> int { ret 10; }
let rs: t = { ten };
assert (rs() == 10);
-fn fix_help<A, B>(f: native fn(fn@(A) -> B, A) -> B, x: A) -> B {
+fn fix_help<A, B>(f: extern fn(fn@(A) -> B, A) -> B, x: A) -> B {
ret f({|a|fix_help(f, a)}, x);
}
-fn fix<A, B>(f: native fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B {
+fn fix<A, B>(f: extern fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B {
ret {|a|fix_help(f, a)};
}
-fn fix_help<A, B: send>(f: native fn(fn@(A) -> B, A) -> B, x: A) -> B {
+fn fix_help<A, B: send>(f: extern fn(fn@(A) -> B, A) -> B, x: A) -> B {
ret f({|a|fix_help(f, a)}, x);
}
-fn fix<A, B: send>(f: native fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B {
+fn fix<A, B: send>(f: extern fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B {
ret {|a|fix_help(f, a)};
}
called = true;
}
-fn g(f: native fn(int, &bool), &called: bool) {
+fn g(f: extern fn(int, &bool), &called: bool) {
f(10, called);
}
// This is what the signature to spawn should look like with bare functions
-fn spawn<T: send>(val: T, f: native fn(T)) {
+fn spawn<T: send>(val: T, f: extern fn(T)) {
f(val);
}
// -*- rust -*-
-fn foo(f: native fn(int) -> int) { }
+fn foo(f: extern fn(int) -> int) { }
fn id(x: int) -> int { ret x; }
--- /dev/null
+// xfail-fast - Somehow causes check-fast to livelock?? Probably because we're
+// calling pin_task and that's having wierd side-effects.
+
+#[abi = "cdecl"]
+#[link_name = "rustrt"]
+extern mod rustrt1 {
+ fn last_os_error() -> str;
+}
+
+#[abi = "cdecl"]
+#[link_name = "rustrt"]
+extern mod rustrt2 {
+ fn last_os_error() -> str;
+}
+
+fn main() {
+ rustrt1::last_os_error();
+ rustrt2::last_os_error();
+}
--- /dev/null
+use std;
+
+import vec;
+import str;
+
+#[nolink]
+#[abi = "cdecl"]
+extern 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);
+}
--- /dev/null
+// xfail-test FIXME I don't know how to test this (#2604)
+// compile-flags:-L.
+// The -L flag is also used for linking foreign libraries
+
+// FIXME: I want to name a mod that would not link successfully
+// wouthout providing a -L argument to the compiler, and that
+// will also be found successfully at runtime.
+extern mod WHATGOESHERE {
+ fn IDONTKNOW() -> u32;
+}
+
+fn main() {
+ assert IDONTKNOW() == 0x_BAD_DOOD_u32;
+}
\ No newline at end of file
--- /dev/null
+
+
+
+// -*- rust -*-
+fn main() {
+ let f = "Makefile";
+ let s = rustrt.str_buf(f);
+ let buf = libc.malloc(1024);
+ let fd = libc.open(s, 0, 0);
+ libc.read(fd, buf, 1024);
+ libc.write(1, buf, 1024);
+ libc.close(fd);
+ libc.free(buf);
+}
--- /dev/null
+// xfail-test
+// -*- rust -*-
+
+native mod libc = target_libc {
+ fn open(int name, int flags, int mode) -> int;
+ fn close(int fd) -> int;
+ fn read(int fd, int buf, int count) -> int;
+ fn write(int fd, int buf, int count) -> int;
+ fn malloc(int sz) -> int;
+ fn free(int p) -> ();
+}
+
+native "cdecl" mod rustrt {
+ fn str_buf(str s) -> int;
+}
+
+mod inner = "native-mod-src/inner.rs";
--- /dev/null
+// ABI is cdecl by default
+
+extern mod rustrt {
+ fn unsupervise();
+}
+
+fn main() {
+ rustrt::unsupervise();
+}
\ No newline at end of file
--- /dev/null
+
+
+
+// -*- rust -*-
+fn main() {
+ libc.puts(rustrt.str_buf("hello, extern world 1"));
+ libc.puts(rustrt.str_buf("hello, extern world 2"));
+ libc.puts(rustrt.str_buf("hello, extern world 3"));
+}
--- /dev/null
+// xfail-win32
+// Passing enums by value
+
+enum void { }
+
+#[nolink]
+extern mod bindgen {
+ fn printf(++v: void);
+}
+
+fn main() { }
--- /dev/null
+// xfail-test
+// -*- rust -*-
+
+native "cdecl" mod rustrt {
+ fn str_buf(str s) -> int;
+}
+
+
+native mod libc = target_libc {
+ fn puts(int s) -> ();
+}
+
+mod user = "native-src/native.rs";
--- /dev/null
+
+
+#[abi = "cdecl"]
+extern mod rustrt {
+ fn unsupervise();
+}
+
+#[abi = "cdecl"]
+#[nolink]
+extern mod bar { }
+
+#[abi = "cdecl"]
+#[nolink]
+extern mod zed { }
+
+#[abi = "cdecl"]
+#[nolink]
+extern mod libc {
+ fn write(fd: int, buf: *u8,
+ count: core::libc::size_t) -> core::libc::ssize_t;
+}
+
+#[abi = "cdecl"]
+#[nolink]
+extern mod baz { }
+
+fn main(args: ~[str]) { }
fn f() -> int { ret 42; }
fn main() {
- let g: native fn() -> int = f;
+ let g: extern fn() -> int = f;
let i: int = g();
assert (i == 42);
}
fn chk(&&a: int) { log(debug, a); assert (a == 1); }
-fn apply<T>(produce: native fn() -> T,
- consume: native fn(T)) {
+fn apply<T>(produce: extern fn() -> T,
+ consume: extern fn(T)) {
consume(produce());
}
fn main() {
- let produce: native fn() -> int = mk;
- let consume: native fn(&&int) = chk;
+ let produce: extern fn() -> int = mk;
+ let consume: extern fn(&&int) = chk;
apply::<int>(produce, consume);
}
type putter = fn@(str, str);
- type mapper = native fn(str, putter);
+ type mapper = extern fn(str, putter);
enum ctrl_proto { find_reducer(~[u8], chan<int>), mapper_done, }
--- /dev/null
+mod spam {
+ fn ham() { }
+ fn eggs() { }
+}
+
+#[abi = "cdecl"]
+extern mod rustrt {
+ import spam::{ham, eggs};
+ export ham;
+ export eggs;
+}
+
+fn main() { rustrt::ham(); rustrt::eggs(); }
+++ /dev/null
-mod spam {
- fn ham() { }
- fn eggs() { }
-}
-
-#[abi = "cdecl"]
-native mod rustrt {
- import spam::{ham, eggs};
- export ham;
- export eggs;
-}
-
-fn main() { rustrt::ham(); rustrt::eggs(); }
// | | |
#[abi = "cdecl"]
#[nolink]
- native mod b1 {
+ extern mod b1 {
// | | |
import a1::b2::*;
// | <-/ -/
// xfail-fast Does not work with main in a submodule
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn pref_align_of<T>() -> uint;
fn min_align_of<T>() -> uint;
}
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn atomic_xchng(&dst: int, src: int) -> int;
fn atomic_xchng_acq(&dst: int, src: int) -> int;
fn atomic_xchng_rel(&dst: int, src: int) -> int;
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn frame_address(f: fn(*u8));
}
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn move_val_init<T>(&dst: T, -src: T);
fn move_val<T>(&dst: T, -src: T);
}
#[link(name = "unsupervise")];
-native mod rustrt {
+extern mod rustrt {
fn unsupervise();
}
// xfail-test
mod a {
type rust_task = uint;
- native mod rustrt {
+ extern mod rustrt {
fn rust_task_is_unwinding(rt: *rust_task) -> bool;
}
}
mod b {
type rust_task = bool;
- native mod rustrt {
+ extern mod rustrt {
fn rust_task_is_unwinding(rt: *rust_task) -> bool;
}
}
#[link_name = "m"]
#[abi = "cdecl"]
-native mod m {
+extern mod m {
#[cfg(unix)]
#[link_name="lgamma_r"] fn lgamma(n: c_double, sign: &mut c_int)
-> c_double;
import task;
#[abi = "cdecl"]
-native mod rustrt {
+extern mod rustrt {
fn rust_task_allow_kill();
}
#[attr = "val"]
#[abi = "cdecl"]
- native mod rustrt { }
+ extern mod rustrt { }
}
mod test_multi_attr_outer {
#[attr1 = "val"]
#[attr2 = "val"]
#[abi = "cdecl"]
- native mod rustrt { }
+ extern mod rustrt { }
#[attr1 = "val"]
#[attr2 = "val"]
#[attr = "val"]
#[abi = "cdecl"]
- native mod rustrt {
+ extern mod rustrt {
}
*/
}
#[attr1 = "val"]
#[attr2 = "val"]
#[abi = "cdecl"]
- native mod rustrt {
+ extern mod rustrt {
}
*/
}
mod test_foreign_items {
#[abi = "cdecl"]
- native mod rustrt {
+ extern mod rustrt {
#[attr];
#[attr]
import task;
import std::rand;
-native mod rustrt {
+extern mod rustrt {
fn debug_get_stk_seg() -> *u8;
fn unsupervise();
+++ /dev/null
-// xfail-fast - Somehow causes check-fast to livelock?? Probably because we're
-// calling pin_task and that's having wierd side-effects.
-
-#[abi = "cdecl"]
-#[link_name = "rustrt"]
-native mod rustrt1 {
- fn last_os_error() -> str;
-}
-
-#[abi = "cdecl"]
-#[link_name = "rustrt"]
-native mod rustrt2 {
- fn last_os_error() -> str;
-}
-
-fn main() {
- rustrt1::last_os_error();
- rustrt2::last_os_error();
-}
+++ /dev/null
-use std;
-
-import vec;
-import str;
-
-#[nolink]
-#[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);
-}
+++ /dev/null
-// xfail-test FIXME I don't know how to test this (#2604)
-// compile-flags:-L.
-// The -L flag is also used for linking native libraries
-
-// FIXME: I want to name a mod that would not link successfully
-// wouthout providing a -L argument to the compiler, and that
-// will also be found successfully at runtime.
-native mod WHATGOESHERE {
- fn IDONTKNOW() -> u32;
-}
-
-fn main() {
- assert IDONTKNOW() == 0x_BAD_DOOD_u32;
-}
\ No newline at end of file
+++ /dev/null
-
-
-
-// -*- rust -*-
-fn main() {
- let f = "Makefile";
- let s = rustrt.str_buf(f);
- let buf = libc.malloc(1024);
- let fd = libc.open(s, 0, 0);
- libc.read(fd, buf, 1024);
- libc.write(1, buf, 1024);
- libc.close(fd);
- libc.free(buf);
-}
+++ /dev/null
-// xfail-test
-// -*- rust -*-
-
-native mod libc = target_libc {
- fn open(int name, int flags, int mode) -> int;
- fn close(int fd) -> int;
- fn read(int fd, int buf, int count) -> int;
- fn write(int fd, int buf, int count) -> int;
- fn malloc(int sz) -> int;
- fn free(int p) -> ();
-}
-
-native "cdecl" mod rustrt {
- fn str_buf(str s) -> int;
-}
-
-mod inner = "native-mod-src/inner.rs";
+++ /dev/null
-// ABI is cdecl by default
-
-native mod rustrt {
- fn unsupervise();
-}
-
-fn main() {
- rustrt::unsupervise();
-}
\ No newline at end of file
+++ /dev/null
-
-
-
-// -*- rust -*-
-fn main() {
- libc.puts(rustrt.str_buf("hello, native world 1"));
- libc.puts(rustrt.str_buf("hello, native world 2"));
- libc.puts(rustrt.str_buf("hello, native world 3"));
-}
+++ /dev/null
-// xfail-win32
-// Passing enums by value
-
-enum void { }
-
-#[nolink]
-native mod bindgen {
- fn printf(++v: void);
-}
-
-fn main() { }
+++ /dev/null
-// xfail-test
-// -*- rust -*-
-
-native "cdecl" mod rustrt {
- fn str_buf(str s) -> int;
-}
-
-
-native mod libc = target_libc {
- fn puts(int s) -> ();
-}
-
-mod user = "native-src/native.rs";
+++ /dev/null
-
-
-#[abi = "cdecl"]
-native mod rustrt {
- fn unsupervise();
-}
-
-#[abi = "cdecl"]
-#[nolink]
-native mod bar { }
-
-#[abi = "cdecl"]
-#[nolink]
-native mod zed { }
-
-#[abi = "cdecl"]
-#[nolink]
-native mod libc {
- fn write(fd: int, buf: *u8,
- count: core::libc::size_t) -> core::libc::ssize_t;
-}
-
-#[abi = "cdecl"]
-#[nolink]
-native mod baz { }
-
-fn main(args: ~[str]) { }
-enum mytype = {compute: native fn(mytype) -> int, val: int};
+enum mytype = {compute: extern fn(mytype) -> int, val: int};
fn compute(i: mytype) -> int { ret i.val + 20; }
--- /dev/null
+// Issue #901
+#[nolink]
+extern mod libc {
+ fn printf(x: ());
+}
+fn main() { }
\ No newline at end of file
+++ /dev/null
-// Issue #901
-#[nolink]
-native mod libc {
- fn printf(x: ());
-}
-fn main() { }
\ No newline at end of file
// Issue #2303
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn pref_align_of<T>() -> uint;
fn min_align_of<T>() -> uint;
}
// Issue #2303
#[abi = "rust-intrinsic"]
-native mod rusti {
+extern mod rusti {
fn pref_align_of<T>() -> uint;
fn min_align_of<T>() -> uint;
}
class finish<T: copy> {
- let arg: {val: T, fin: native fn(T)};
- new(arg: {val: T, fin: native fn(T)}) {
+ let arg: {val: T, fin: extern fn(T)};
+ new(arg: {val: T, fin: extern fn(T)}) {
self.arg = arg;
}
drop { self.arg.fin(self.arg.val); }
type task = *libc::c_void;
type closure = *libc::c_void;
-native mod rustrt {
+extern mod rustrt {
fn rust_new_sched(num_threads: libc::uintptr_t) -> sched_id;
fn rust_get_sched_id() -> sched_id;
fn rust_new_task_in_sched(id: sched_id) -> task_id;
assert q.b == "Ho";
}
-fn spawn<A: copy, B: copy>(f: native fn(fn~(A,B)->pair<A,B>)) {
+fn spawn<A: copy, B: copy>(f: extern fn(fn~(A,B)->pair<A,B>)) {
let arg = fn~(a: A, b: B) -> pair<A,B> {
ret make_generic_record(a, b);
};
type floats = { a: f64, b: u8, c: f64 };
#[nolink]
-native mod rustrt {
+extern mod rustrt {
fn debug_abi_1(++q: quad) -> quad;
fn debug_abi_2(++f: floats) -> floats;
}
fn main() { let k = checktrue; evenk(42, k); oddk(45, k); }
-fn evenk(n: int, k: native fn(bool) -> bool) -> bool {
+fn evenk(n: int, k: extern fn(bool) -> bool) -> bool {
#debug("evenk");
log(debug, n);
if n == 0 { ret k(true); } else { ret oddk(n - 1, k); }
}
-fn oddk(n: int, k: native fn(bool) -> bool) -> bool {
+fn oddk(n: int, k: extern fn(bool) -> bool) -> bool {
#debug("oddk");
log(debug, n);
if n == 0 { ret k(false); } else { ret evenk(n - 1, k); }
-type lteq<T> = native fn(T) -> bool;
+type lteq<T> = extern fn(T) -> bool;
fn main(args: ~[str]) { }
while lo_ < hi { it(lo_); lo_ += 1u; }
}
-fn create_index<T>(index: ~[{a: T, b: uint}], hash_fn: native fn(T) -> uint) {
+fn create_index<T>(index: ~[{a: T, b: uint}], hash_fn: extern fn(T) -> uint) {
range(0u, 256u, |_i| { let bucket: ~[T] = ~[]; } )
}
#[warn(no_ctypes)];
#[nolink]
-native mod libc {
+extern mod libc {
fn malloc(size: int) -> *u8;
}
// xfail-test
#[cfg(target_os = "win32")]
-native "stdcall" mod kernel32 {
+extern "stdcall" mod kernel32 {
fn SetLastError(err: uint);
fn GetLastError() -> uint;
}
#[cfg(target_os = "win32")]
#[abi = "stdcall"]
-native mod kernel32 {
+extern mod kernel32 {
fn GetProcessHeap() -> HANDLE;
fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;