libcore: Remove `extern mod { ... }` from libcore. rs=deexterning

This commit is contained in:
Patrick Walton 2013-03-05 11:57:50 -08:00
parent 88f0a10578
commit fd271adc75
21 changed files with 822 additions and 624 deletions

View File

@ -23,11 +23,18 @@ use vec;
/// Code for dealing with @-vectors. This is pretty incomplete, and
/// contains a bunch of duplication from the code for ~-vectors.
#[abi = "cdecl"]
pub extern mod rustrt {
pub mod rustrt {
use libc;
use sys;
use vec;
#[abi = "cdecl"]
#[link_name = "rustrt"]
pub extern {
pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
++v: **vec::raw::VecRepr,
++n: libc::size_t);
}
}
/// Returns the number of elements the vector can hold without reallocating

View File

@ -8,10 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[abi = "rust-intrinsic"]
extern mod rusti {
pub mod rusti {
#[abi = "rust-intrinsic"]
#[link_name = "rusti"]
pub extern {
fn forget<T>(-x: T);
fn reinterpret_cast<T, U>(&&e: T) -> U;
}
}
/// Casts the value at `src` to U. The two types must have the same length.

View File

@ -218,9 +218,14 @@ pub unsafe fn annihilate() {
}
/// Bindings to the runtime
extern mod rustrt {
pub mod rustrt {
use libc::c_void;
#[link_name = "rustrt"]
pub extern {
#[rust_stack]
// FIXME (#4386): Unable to make following method private.
pub unsafe fn rust_get_task() -> *c_void;
}
}

View File

@ -21,16 +21,23 @@ use vec;
#[cfg(test)] use rand;
extern mod rustrt {
pub mod rustrt {
use libc::{c_int, c_void, size_t};
#[link_name = "rustrt"]
pub extern {
unsafe fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
src_buf_len: size_t,
pout_len: *size_t,
flags: c_int) -> *c_void;
flags: c_int)
-> *c_void;
unsafe fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
src_buf_len: size_t,
pout_len: *size_t,
flags: c_int) -> *c_void;
flags: c_int)
-> *c_void;
}
}
const lz_none : c_int = 0x0; // Huffman-coding only.

View File

@ -48,14 +48,20 @@ use sys;
pub use stackwalk::Word;
// Mirrors rust_stack.h stk_seg
struct StackSegment {
pub struct StackSegment {
prev: *StackSegment,
next: *StackSegment,
end: uintptr_t,
// And other fields which we don't care about...
}
extern mod rustrt {
pub mod rustrt {
use libc::size_t;
use stackwalk::Word;
use super::StackSegment;
#[link_name = "rustrt"]
pub extern {
#[rust_stack]
pub unsafe fn rust_call_tydesc_glue(root: *Word,
tydesc: *Word,
@ -65,6 +71,7 @@ extern mod rustrt {
pub unsafe fn rust_gc_metadata() -> *Word;
pub unsafe fn rust_get_stack_segment() -> *StackSegment;
}
}
unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U {

View File

@ -32,11 +32,16 @@ use vec;
#[allow(non_camel_case_types)] // not sure what to do about this
pub type fd_t = c_int;
#[abi = "cdecl"]
extern mod rustrt {
pub mod rustrt {
use libc;
#[abi = "cdecl"]
#[link_name = "rustrt"]
pub extern {
unsafe fn rust_get_stdin() -> *libc::FILE;
unsafe fn rust_get_stdout() -> *libc::FILE;
unsafe fn rust_get_stderr() -> *libc::FILE;
}
}
// Reading

View File

@ -1006,13 +1006,12 @@ pub mod funcs {
// or anything. The same is not true of POSIX.
pub mod c95 {
use libc::types::common::c95::{FILE, c_void, fpos_t};
use libc::types::os::arch::c95::{c_char, c_double, c_int, c_long};
use libc::types::os::arch::c95::{c_uint, c_ulong, c_void, size_t};
#[nolink]
#[abi = "cdecl"]
pub extern mod ctype {
pub mod ctype {
use libc::types::os::arch::c95::{c_char, c_int};
pub extern {
unsafe fn isalnum(c: c_int) -> c_int;
unsafe fn isalpha(c: c_int) -> c_int;
unsafe fn iscntrl(c: c_int) -> c_int;
@ -1027,10 +1026,15 @@ pub mod funcs {
unsafe fn tolower(c: c_char) -> c_char;
unsafe fn toupper(c: c_char) -> c_char;
}
}
#[nolink]
#[abi = "cdecl"]
pub extern mod stdio {
pub mod stdio {
use libc::types::common::c95::{FILE, c_void, fpos_t};
use libc::types::os::arch::c95::{c_char, c_int, c_long, size_t};
pub extern {
unsafe fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
unsafe fn freopen(filename: *c_char, mode: *c_char,
file: *FILE) -> *FILE;
@ -1070,11 +1074,17 @@ pub mod funcs {
unsafe fn ferror(stream: *FILE) -> c_int;
unsafe fn perror(s: *c_char);
}
}
#[nolink]
#[abi = "cdecl"]
pub extern mod stdlib {
pub mod stdlib {
use libc::types::common::c95::c_void;
use libc::types::os::arch::c95::{c_char, c_double, c_int};
use libc::types::os::arch::c95::{c_long, c_uint, c_ulong};
use libc::types::os::arch::c95::{size_t};
pub extern {
unsafe fn abs(i: c_int) -> c_int;
unsafe fn labs(i: c_long) -> c_long;
// Omitted: div, ldiv (return pub type incomplete).
@ -1098,17 +1108,24 @@ pub mod funcs {
unsafe fn rand() -> c_int;
unsafe fn srand(seed: c_uint);
}
}
#[nolink]
#[abi = "cdecl"]
pub extern mod string {
pub mod string {
use libc::types::common::c95::c_void;
use libc::types::os::arch::c95::{c_char, c_int, size_t};
pub extern {
unsafe fn strcpy(dst: *c_char, src: *c_char) -> *c_char;
unsafe fn strncpy(dst: *c_char, src: *c_char, n: size_t)
-> *c_char;
unsafe fn strcat(s: *c_char, ct: *c_char) -> *c_char;
unsafe fn strncat(s: *c_char, ct: *c_char, n: size_t) -> *c_char;
unsafe fn strncat(s: *c_char, ct: *c_char, n: size_t)
-> *c_char;
unsafe fn strcmp(cs: *c_char, ct: *c_char) -> c_int;
unsafe fn strncmp(cs: *c_char, ct: *c_char, n: size_t) -> c_int;
unsafe fn strncmp(cs: *c_char, ct: *c_char, n: size_t)
-> c_int;
unsafe fn strcoll(cs: *c_char, ct: *c_char) -> c_int;
unsafe fn strchr(cs: *c_char, c: c_int) -> *c_char;
unsafe fn strrchr(cs: *c_char, c: c_int) -> *c_char;
@ -1119,19 +1136,23 @@ pub mod funcs {
unsafe fn strlen(cs: *c_char) -> size_t;
unsafe fn strerror(n: c_int) -> *c_char;
unsafe fn strtok(s: *c_char, t: *c_char) -> *c_char;
unsafe fn strxfrm(s: *c_char, ct: *c_char, n: size_t) -> size_t;
unsafe fn strxfrm(s: *c_char, ct: *c_char, n: size_t)
-> size_t;
// These are fine to execute on the Rust stack. They must be, in
// fact, because LLVM generates calls to them!
#[rust_stack]
#[inline(always)]
unsafe fn memcpy(s: *c_void, ct: *c_void, n: size_t) -> *c_void;
unsafe fn memcpy(s: *c_void, ct: *c_void, n: size_t)
-> *c_void;
#[rust_stack]
#[inline(always)]
unsafe fn memmove(s: *c_void, ct: *c_void, n: size_t) -> *c_void;
unsafe fn memmove(s: *c_void, ct: *c_void, n: size_t)
-> *c_void;
#[rust_stack]
#[inline(always)]
unsafe fn memcmp(cx: *c_void, ct: *c_void, n: size_t) -> c_int;
unsafe fn memcmp(cx: *c_void, ct: *c_void, n: size_t)
-> c_int;
#[rust_stack]
#[inline(always)]
unsafe fn memchr(cx: *c_void, c: c_int, n: size_t) -> *c_void;
@ -1140,6 +1161,7 @@ pub mod funcs {
unsafe fn memset(s: *c_void, c: c_int, n: size_t) -> *c_void;
}
}
}
// Microsoft helpfully underscore-qualifies all of its POSIX-like symbols
// to make sure you don't use them accidentally. It also randomly deviates
@ -1151,10 +1173,11 @@ pub mod funcs {
pub mod posix88 {
#[nolink]
#[abi = "cdecl"]
pub extern mod stat_ {
pub mod stat_ {
use libc::types::os::common::posix01::stat;
use libc::types::os::arch::c95::{c_int, c_char};
pub extern {
#[link_name = "_chmod"]
unsafe fn chmod(path: *c_char, mode: c_int) -> c_int;
@ -1167,13 +1190,15 @@ pub mod funcs {
#[link_name = "_stat64"]
unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
}
}
#[nolink]
#[abi = "cdecl"]
pub extern mod stdio {
pub mod stdio {
use libc::types::common::c95::FILE;
use libc::types::os::arch::c95::{c_int, c_char};
pub extern {
#[link_name = "_popen"]
unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
@ -1186,33 +1211,38 @@ pub mod funcs {
#[link_name = "_fileno"]
unsafe fn fileno(stream: *FILE) -> c_int;
}
#[nolink]
#[abi = "cdecl"]
pub extern mod fcntl {
use libc::types::os::arch::c95::{c_int, c_char};
#[link_name = "_open"]
unsafe fn open(path: *c_char, oflag: c_int, mode: c_int) -> c_int;
#[link_name = "_creat"]
unsafe fn creat(path: *c_char, mode: c_int) -> c_int;
}
#[nolink]
#[abi = "cdecl"]
pub extern mod dirent {
pub mod fcntl {
pub extern {
use libc::types::os::arch::c95::{c_int, c_char};
#[link_name = "_open"]
unsafe fn open(path: *c_char, oflag: c_int, mode: c_int)
-> c_int;
#[link_name = "_creat"]
unsafe fn creat(path: *c_char, mode: c_int) -> c_int;
}
}
#[nolink]
#[abi = "cdecl"]
pub mod dirent {
// Not supplied at all.
}
#[nolink]
#[abi = "cdecl"]
pub extern mod unistd {
pub mod unistd {
use libc::types::common::c95::c_void;
use libc::types::os::arch::c95::{c_int, c_uint, c_char,
c_long, size_t};
use libc::types::os::arch::c99::intptr_t;
pub extern {
#[link_name = "_access"]
unsafe fn access(path: *c_char, amode: c_int) -> c_int;
@ -1270,8 +1300,9 @@ pub mod funcs {
unsafe fn unlink(c: *c_char) -> c_int;
#[link_name = "_write"]
unsafe fn write(fd: c_int, buf: *c_void, count: c_uint) -> c_int;
unsafe fn write(fd: c_int, buf: *c_void, count: c_uint)
-> c_int;
}
}
}
@ -1281,17 +1312,14 @@ pub mod funcs {
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
pub mod posix88 {
use libc::types::common::c95::{FILE, c_void};
use libc::types::common::posix88::{DIR, dirent_t};
use libc::types::os::arch::c95::{c_char, c_int, c_long, c_uint};
use libc::types::os::arch::c95::{size_t};
pub mod stat_ {
use libc::types::os::arch::c95::{c_char, c_int};
use libc::types::os::arch::posix01::stat;
use libc::types::os::arch::posix88::{gid_t, mode_t, off_t, pid_t};
use libc::types::os::arch::posix88::{ssize_t, uid_t};
use libc::types::os::arch::posix88::mode_t;
#[nolink]
#[abi = "cdecl"]
pub extern mod stat_ {
pub extern {
unsafe fn chmod(path: *c_char, mode: mode_t) -> c_int;
unsafe fn fchmod(fd: c_int, mode: mode_t) -> c_int;
@ -1316,27 +1344,43 @@ pub mod funcs {
#[link_name = "stat64"]
unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
}
}
#[nolink]
#[abi = "cdecl"]
pub extern mod stdio {
pub mod stdio {
use libc::types::common::c95::FILE;
use libc::types::os::arch::c95::{c_char, c_int};
pub extern {
unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
unsafe fn pclose(stream: *FILE) -> c_int;
unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
unsafe fn fileno(stream: *FILE) -> c_int;
}
#[nolink]
#[abi = "cdecl"]
pub extern mod fcntl {
unsafe fn open(path: *c_char, oflag: c_int, mode: c_int) -> c_int;
unsafe fn creat(path: *c_char, mode: mode_t) -> c_int;
unsafe fn fcntl(fd: c_int, cmd: c_int) -> c_int;
}
#[nolink]
#[abi = "cdecl"]
pub extern mod dirent {
pub mod fcntl {
use libc::types::os::arch::c95::{c_char, c_int};
use libc::types::os::arch::posix88::mode_t;
pub extern {
unsafe fn open(path: *c_char, oflag: c_int, mode: c_int)
-> c_int;
unsafe fn creat(path: *c_char, mode: mode_t) -> c_int;
unsafe fn fcntl(fd: c_int, cmd: c_int) -> c_int;
}
}
#[nolink]
#[abi = "cdecl"]
pub mod dirent {
use libc::types::common::posix88::{DIR, dirent_t};
use libc::types::os::arch::c95::{c_char, c_int, c_long};
pub extern {
unsafe fn opendir(dirname: *c_char) -> *DIR;
unsafe fn closedir(dirp: *DIR) -> c_int;
unsafe fn readdir(dirp: *DIR) -> *dirent_t;
@ -1344,19 +1388,30 @@ pub mod funcs {
unsafe fn seekdir(dirp: *DIR, loc: c_long);
unsafe fn telldir(dirp: *DIR) -> c_long;
}
}
#[nolink]
#[abi = "cdecl"]
pub extern mod unistd {
pub mod unistd {
use libc::types::common::c95::c_void;
use libc::types::os::arch::c95::{c_char, c_int, c_long, c_uint};
use libc::types::os::arch::c95::{size_t};
use libc::types::os::arch::posix88::{gid_t, off_t, pid_t};
use libc::types::os::arch::posix88::{ssize_t, uid_t};
pub extern {
unsafe fn access(path: *c_char, amode: c_int) -> c_int;
unsafe fn alarm(seconds: c_uint) -> c_uint;
unsafe fn chdir(dir: *c_char) -> c_int;
unsafe fn chown(path: *c_char, uid: uid_t, gid: gid_t) -> c_int;
unsafe fn chown(path: *c_char, uid: uid_t, gid: gid_t)
-> c_int;
unsafe fn close(fd: c_int) -> c_int;
unsafe fn dup(fd: c_int) -> c_int;
unsafe fn dup2(src: c_int, dst: c_int) -> c_int;
unsafe fn execv(prog: *c_char, argv: **c_char) -> c_int;
unsafe fn execve(prog: *c_char, argv: **c_char, envp: **c_char)
unsafe fn execve(prog: *c_char,
argv: **c_char,
envp: **c_char)
-> c_int;
unsafe fn execvp(c: *c_char, argv: **c_char) -> c_int;
unsafe fn fork() -> pid_t;
@ -1376,7 +1431,8 @@ pub mod funcs {
unsafe fn getuid() -> uid_t;
unsafe fn isatty(fd: c_int) -> c_int;
unsafe fn link(src: *c_char, dst: *c_char) -> c_int;
unsafe fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t;
unsafe fn lseek(fd: c_int, offset: off_t, whence: c_int)
-> off_t;
unsafe fn pathconf(path: *c_char, name: c_int) -> c_long;
unsafe fn pause() -> c_int;
unsafe fn pipe(fds: *mut c_int) -> c_int;
@ -1396,19 +1452,20 @@ pub mod funcs {
-> ssize_t;
}
}
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
pub mod posix01 {
use libc::types::os::arch::c95::{c_char, c_int, size_t};
use libc::types::os::arch::posix01::stat;
use libc::types::os::arch::posix88::{pid_t, ssize_t};
#[nolink]
#[abi = "cdecl"]
pub extern mod stat_ {
pub mod stat_ {
use libc::types::os::arch::c95::{c_char, c_int};
use libc::types::os::arch::posix01::stat;
pub extern {
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "android")]
@ -1418,10 +1475,15 @@ pub mod funcs {
#[link_name = "lstat64"]
unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
}
}
#[nolink]
#[abi = "cdecl"]
pub extern mod unistd {
pub mod unistd {
use libc::types::os::arch::c95::{c_char, c_int, size_t};
use libc::types::os::arch::posix88::{ssize_t};
pub extern {
unsafe fn readlink(path: *c_char, buf: *mut c_char,
bufsz: size_t) -> ssize_t;
@ -1438,23 +1500,29 @@ pub mod funcs {
unsafe fn symlink(path1: *c_char, path2: *c_char) -> c_int;
}
}
#[nolink]
#[abi = "cdecl"]
pub extern mod wait {
unsafe fn waitpid(pid: pid_t, status: *mut c_int,
options: c_int) -> pid_t;
pub mod wait {
use libc::types::os::arch::c95::{c_int};
use libc::types::os::arch::posix88::{pid_t};
pub extern {
unsafe fn waitpid(pid: pid_t,
status: *mut c_int,
options: c_int)
-> pid_t;
}
}
}
#[cfg(target_os = "win32")]
pub mod posix01 {
#[nolink]
pub extern mod stat_ {
pub mod stat_ {
}
#[nolink]
pub extern mod unistd {
pub mod unistd {
}
}
@ -1465,17 +1533,16 @@ pub mod funcs {
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
pub mod posix08 {
#[nolink]
pub extern mod unistd {
pub mod unistd {
}
}
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[nolink]
pub mod bsd44 {
#[abi = "cdecl"]
pub extern mod bsd44 {
pub extern {
use libc::types::common::c95::{c_void};
use libc::types::os::arch::c95::{c_char, c_int, c_uint, size_t};
@ -1490,6 +1557,7 @@ pub mod funcs {
unsafe fn sysctlnametomib(name: *c_char, mibp: *mut c_int,
sizep: *mut size_t) -> c_int;
}
}
#[cfg(target_os = "linux")]
@ -1500,12 +1568,15 @@ pub mod funcs {
#[cfg(target_os = "macos")]
#[nolink]
#[abi = "cdecl"]
pub extern mod extra {
pub mod extra {
use libc::types::os::arch::c95::{c_char, c_int};
#[abi = "cdecl"]
pub extern {
unsafe fn _NSGetExecutablePath(buf: *mut c_char,
bufsize: *mut u32) -> c_int;
bufsize: *mut u32)
-> c_int;
}
}
#[cfg(target_os = "freebsd")]
@ -1520,40 +1591,52 @@ pub mod funcs {
#[cfg(target_os = "win32")]
pub mod extra {
use libc::types::os::arch::c95::c_int;
use libc::types::os::arch::extra::{DWORD, HMODULE, LPCWSTR, LPWSTR};
use libc::types::os::arch::extra::{BOOL, LPSECURITY_ATTRIBUTES};
pub mod kernel32 {
use libc::types::os::arch::extra::{BOOL, DWORD, HMODULE};
use libc::types::os::arch::extra::{LPCWSTR, LPWSTR};
use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES};
#[abi = "stdcall"]
pub extern mod kernel32 {
pub extern {
unsafe fn GetEnvironmentVariableW(n: LPCWSTR,
v: LPWSTR,
nsize: DWORD) -> DWORD;
unsafe fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
nsize: DWORD)
-> DWORD;
unsafe fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR)
-> BOOL;
unsafe fn GetModuleFileNameW(hModule: HMODULE,
lpFilename: LPWSTR,
nSize: DWORD) -> DWORD;
nSize: DWORD)
-> DWORD;
unsafe fn CreateDirectoryW(lpPathName: LPCWSTR,
lpSecurityAttributes:
LPSECURITY_ATTRIBUTES) -> BOOL;
LPSECURITY_ATTRIBUTES)
-> BOOL;
unsafe fn CopyFileW(lpExistingFileName: LPCWSTR,
lpNewFileName: LPCWSTR,
bFailIfExists: BOOL) -> BOOL;
bFailIfExists: BOOL)
-> BOOL;
unsafe fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
unsafe fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
unsafe fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
unsafe fn GetLastError() -> DWORD;
}
}
pub mod msvcrt {
use libc::types::os::arch::c95::c_int;
#[abi = "cdecl"]
#[nolink]
pub extern mod msvcrt {
pub extern {
#[link_name = "_commit"]
unsafe fn commit(fd: c_int) -> c_int;
}
}
}
}

View File

@ -12,13 +12,16 @@
use libc;
#[nolink]
extern mod rustrt {
pub mod rustrt {
use libc;
pub extern {
unsafe fn rust_log_console_on();
unsafe fn rust_log_console_off();
unsafe fn rust_log_str(level: u32,
string: *libc::c_char,
size: libc::size_t);
}
}
/// Turns on logging to stdout globally

View File

@ -17,10 +17,12 @@ use libc::c_double;
// function names are almost identical to C's libmath, a few have been
// renamed, grep for "rename:"
#[link_name = "m"]
#[abi = "cdecl"]
pub extern mod c_double_utils {
pub mod c_double_utils {
use libc::{c_double, c_int};
#[link_name = "m"]
#[abi = "cdecl"]
pub extern {
// Alpabetically sorted by link_name
unsafe fn acos(n: c_double) -> c_double;
@ -43,20 +45,22 @@ pub extern mod c_double_utils {
unsafe fn abs_sub(a: c_double, b: c_double) -> c_double;
unsafe fn floor(n: c_double) -> c_double;
// rename: for clarity and consistency with add/sub/mul/div
#[link_name="fma"] unsafe fn mul_add(a: c_double, b: c_double,
c: c_double) -> c_double;
#[link_name="fmax"] unsafe fn fmax(a: c_double, b: c_double) -> c_double;
#[link_name="fmin"] unsafe fn fmin(a: c_double, b: c_double) -> c_double;
#[link_name="fma"]
unsafe fn mul_add(a: c_double, b: c_double, c: c_double) -> c_double;
#[link_name="fmax"]
unsafe fn fmax(a: c_double, b: c_double) -> c_double;
#[link_name="fmin"]
unsafe fn fmin(a: c_double, b: c_double) -> c_double;
unsafe fn nextafter(x: c_double, y: c_double) -> c_double;
unsafe fn frexp(n: c_double, value: &mut c_int) -> c_double;
unsafe fn hypot(x: c_double, y: c_double) -> c_double;
unsafe fn ldexp(x: c_double, n: c_int) -> c_double;
#[cfg(unix)]
#[link_name="lgamma_r"] unsafe fn lgamma(n: c_double,
sign: &mut c_int) -> c_double;
#[link_name="lgamma_r"]
unsafe fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
#[cfg(windows)]
#[link_name="__lgamma_r"] unsafe fn lgamma(n: c_double,
sign: &mut c_int) -> c_double;
#[link_name="__lgamma_r"]
unsafe fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
// renamed: log is a reserved keyword; ln seems more natural, too
#[link_name="log"] unsafe fn ln(n: c_double) -> c_double;
// renamed: "logb" /often/ is confused for log2 by beginners
@ -68,8 +72,8 @@ pub extern mod c_double_utils {
#[link_name="ilogb"] unsafe fn ilog_radix(n: c_double) -> c_int;
unsafe fn modf(n: c_double, iptr: &mut c_double) -> c_double;
unsafe fn pow(n: c_double, e: c_double) -> c_double;
// FIXME (#1379): enable when rounding modes become available
// unsafe fn rint(n: c_double) -> c_double;
// FIXME (#1379): enable when rounding modes become available
// unsafe fn rint(n: c_double) -> c_double;
unsafe fn round(n: c_double) -> c_double;
// rename: for consistency with logradix
#[link_name="scalbn"] unsafe fn ldexp_radix(n: c_double, i: c_int) ->
@ -91,18 +95,22 @@ pub extern mod c_double_utils {
unsafe fn y0(n: c_double) -> c_double;
unsafe fn y1(n: c_double) -> c_double;
unsafe fn yn(i: c_int, n: c_double) -> c_double;
}
}
#[link_name = "m"]
#[abi = "cdecl"]
pub extern mod c_float_utils {
pub mod c_float_utils {
use libc::{c_float, c_int};
#[link_name = "m"]
#[abi = "cdecl"]
pub extern {
// Alpabetically sorted by link_name
#[link_name="acosf"] unsafe fn acos(n: c_float) -> c_float;
#[link_name="asinf"] unsafe fn asin(n: c_float) -> c_float;
#[link_name="atanf"] unsafe fn atan(n: c_float) -> c_float;
#[link_name="atan2f"] unsafe fn atan2(a: c_float, b: c_float) -> c_float;
#[link_name="atan2f"]
unsafe fn atan2(a: c_float, b: c_float) -> c_float;
#[link_name="cbrtf"] unsafe fn cbrt(n: c_float) -> c_float;
#[link_name="ceilf"] unsafe fn ceil(n: c_float) -> c_float;
#[link_name="copysignf"] unsafe fn copysign(x: c_float,
@ -115,26 +123,31 @@ pub extern mod c_float_utils {
#[link_name="expm1f"]unsafe fn expm1(n: c_float) -> c_float;
#[link_name="exp2f"] unsafe fn exp2(n: c_float) -> c_float;
#[link_name="fabsf"] unsafe fn abs(n: c_float) -> c_float;
#[link_name="fdimf"] unsafe fn abs_sub(a: c_float, b: c_float) -> c_float;
#[link_name="fdimf"]
unsafe fn abs_sub(a: c_float, b: c_float) -> c_float;
#[link_name="floorf"] unsafe fn floor(n: c_float) -> c_float;
#[link_name="frexpf"] unsafe fn frexp(n: c_float,
value: &mut c_int) -> c_float;
#[link_name="fmaf"] unsafe fn mul_add(a: c_float,
b: c_float, c: c_float) -> c_float;
#[link_name="fmaxf"] unsafe fn fmax(a: c_float, b: c_float) -> c_float;
#[link_name="fminf"] unsafe fn fmin(a: c_float, b: c_float) -> c_float;
#[link_name="nextafterf"] unsafe fn nextafter(x: c_float,
y: c_float) -> c_float;
#[link_name="hypotf"] unsafe fn hypot(x: c_float, y: c_float) -> c_float;
#[link_name="ldexpf"] unsafe fn ldexp(x: c_float, n: c_int) -> c_float;
#[link_name="fmaf"]
unsafe fn mul_add(a: c_float, b: c_float, c: c_float) -> c_float;
#[link_name="fmaxf"]
unsafe fn fmax(a: c_float, b: c_float) -> c_float;
#[link_name="fminf"]
unsafe fn fmin(a: c_float, b: c_float) -> c_float;
#[link_name="nextafterf"]
unsafe fn nextafter(x: c_float, y: c_float) -> c_float;
#[link_name="hypotf"]
unsafe fn hypot(x: c_float, y: c_float) -> c_float;
#[link_name="ldexpf"]
unsafe fn ldexp(x: c_float, n: c_int) -> c_float;
#[cfg(unix)]
#[link_name="lgammaf_r"] unsafe fn lgamma(n: c_float,
sign: &mut c_int) -> c_float;
#[cfg(windows)]
#[link_name="__lgammaf_r"] unsafe fn lgamma(n: c_float,
sign: &mut c_int) -> c_float;
#[link_name="__lgammaf_r"]
unsafe fn lgamma(n: c_float, sign: &mut c_int) -> c_float;
#[link_name="logf"] unsafe fn ln(n: c_float) -> c_float;
#[link_name="logbf"] unsafe fn log_radix(n: c_float) -> c_float;
@ -145,8 +158,8 @@ pub extern mod c_float_utils {
#[link_name="modff"] unsafe fn modf(n: c_float,
iptr: &mut c_float) -> c_float;
#[link_name="powf"] unsafe fn pow(n: c_float, e: c_float) -> c_float;
// FIXME (#1379): enable when rounding modes become available
// #[link_name="rintf"] unsafe fn rint(n: c_float) -> c_float;
// FIXME (#1379): enable when rounding modes become available
// #[link_name="rintf"] unsafe fn rint(n: c_float) -> c_float;
#[link_name="roundf"] unsafe fn round(n: c_float) -> c_float;
#[link_name="scalbnf"] unsafe fn ldexp_radix(n: c_float, i: c_int)
-> c_float;
@ -157,6 +170,7 @@ pub extern mod c_float_utils {
#[link_name="tanhf"] unsafe fn tanh(n: c_float) -> c_float;
#[link_name="tgammaf"] unsafe fn tgamma(n: c_float) -> c_float;
#[link_name="truncf"] unsafe fn trunc(n: c_float) -> c_float;
}
}
// PORT check these by running src/etc/machconsts.c for your architecture

View File

@ -51,7 +51,11 @@ pub fn close(fd: c_int) -> c_int {
}
}
extern mod rustrt {
pub mod rustrt {
use libc::{c_char, c_int};
use libc;
pub extern {
unsafe fn rust_get_argc() -> c_int;
unsafe fn rust_get_argv() -> **c_char;
unsafe fn rust_getcwd() -> ~str;
@ -60,6 +64,7 @@ extern mod rustrt {
unsafe fn rust_list_files2(&&path: ~str) -> ~[~str];
unsafe fn rust_process_wait(handle: c_int) -> c_int;
unsafe fn rust_set_exit_status(code: libc::intptr_t);
}
}
pub const TMPBUF_SZ : uint = 1000u;
@ -159,14 +164,14 @@ fn with_env_lock<T>(f: &fn() -> T) -> T {
}
pub fn env() -> ~[(~str,~str)] {
extern mod rustrt {
extern {
unsafe fn rust_env_pairs() -> ~[~str];
}
unsafe {
do with_env_lock {
let mut pairs = ~[];
for vec::each(rustrt::rust_env_pairs()) |p| {
for vec::each(rust_env_pairs()) |p| {
let vs = str::splitn_char(*p, '=', 1u);
assert vec::len(vs) == 2u;
pairs.push((copy vs[0], copy vs[1]));

View File

@ -288,10 +288,14 @@ pub fn swap_task(dst: &mut *rust_task, src: *rust_task) -> *rust_task {
#[doc(hidden)]
#[allow(non_camel_case_types)]
type rust_task = libc::c_void;
pub type rust_task = libc::c_void;
#[doc(hidden)]
extern mod rustrt {
pub mod rustrt {
use libc;
use super::rust_task;
pub extern {
#[rust_stack]
unsafe fn rust_get_task() -> *rust_task;
#[rust_stack]
@ -301,9 +305,11 @@ extern mod rustrt {
#[rust_stack]
unsafe fn task_clear_event_reject(task: *rust_task);
unsafe fn task_wait_event(this: *rust_task, killed: &mut *libc::c_void)
unsafe fn task_wait_event(this: *rust_task,
killed: &mut *libc::c_void)
-> bool;
unsafe fn task_signal_event(target: *rust_task, event: *libc::c_void);
}
}
#[doc(hidden)]

View File

@ -20,9 +20,13 @@ use sys;
#[cfg(test)] use str;
#[cfg(notest)] use cmp::{Eq, Ord};
#[nolink]
#[abi = "cdecl"]
extern mod libc_ {
pub mod libc_ {
use libc::c_void;
use libc;
#[nolink]
#[abi = "cdecl"]
pub extern {
#[rust_stack]
unsafe fn memmove(dest: *mut c_void,
src: *const c_void,
@ -34,11 +38,14 @@ extern mod libc_ {
c: libc::c_int,
len: libc::size_t)
-> *c_void;
}
}
#[abi = "rust-intrinsic"]
extern mod rusti {
pub mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
fn addr_of<T>(&&val: T) -> *T;
}
}
/// Get an unsafe pointer to a value

View File

@ -117,15 +117,20 @@ impl<T:Rand> Rand for Option<T> {
}
#[allow(non_camel_case_types)] // runtime type
enum rust_rng {}
pub enum rust_rng {}
#[abi = "cdecl"]
extern mod rustrt {
pub mod rustrt {
use libc::size_t;
use rand::rust_rng;
pub extern {
unsafe fn rand_seed_size() -> size_t;
unsafe fn rand_gen_seed(buf: *mut u8, sz: size_t);
unsafe fn rand_new_seeded(buf: *u8, sz: size_t) -> *rust_rng;
unsafe fn rand_next(rng: *rust_rng) -> u32;
unsafe fn rand_free(rng: *rust_rng);
}
}
/// A random number generator

View File

@ -23,12 +23,20 @@ use str;
use task;
use vec;
#[abi = "cdecl"]
extern mod rustrt {
unsafe fn rust_run_program(argv: **libc::c_char, envp: *c_void,
pub mod rustrt {
use libc::{c_int, c_void, pid_t};
use libc;
#[abi = "cdecl"]
pub extern {
unsafe 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)
in_fd: c_int,
out_fd: c_int,
err_fd: c_int)
-> pid_t;
}
}
/// A value representing a child process

View File

@ -86,11 +86,16 @@ fn frame_address(f: fn(++x: *u8)) {
}
}
extern mod rustrt {
pub mod rustrt {
pub extern {
pub unsafe fn rust_dbg_breakpoint();
}
}
#[abi = "rust-intrinsic"]
extern mod rusti {
pub mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
pub fn frame_address(f: &once fn(++x: *u8));
}
}

View File

@ -37,17 +37,25 @@ pub struct Closure {
env: *(),
}
#[abi = "rust-intrinsic"]
extern mod rusti {
pub mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
fn get_tydesc<T>() -> *();
fn size_of<T>() -> uint;
fn pref_align_of<T>() -> uint;
fn min_align_of<T>() -> uint;
}
}
extern mod rustrt {
pub mod rustrt {
use libc::{c_char, size_t};
pub extern {
#[rust_stack]
unsafe fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t);
unsafe fn rust_upcall_fail(expr: *c_char,
file: *c_char,
line: size_t);
}
}
/// Compares contents of two pointers using the default method.

View File

@ -938,15 +938,17 @@ fn test_spawn_sched_childs_on_default_sched() {
po.recv();
}
#[nolink]
#[cfg(test)]
extern mod testrt {
pub mod testrt {
#[nolink]
pub extern {
unsafe fn rust_dbg_lock_create() -> *libc::c_void;
unsafe fn rust_dbg_lock_destroy(lock: *libc::c_void);
unsafe fn rust_dbg_lock_lock(lock: *libc::c_void);
unsafe fn rust_dbg_lock_unlock(lock: *libc::c_void);
unsafe fn rust_dbg_lock_wait(lock: *libc::c_void);
unsafe fn rust_dbg_lock_signal(lock: *libc::c_void);
}
}
#[test]

View File

@ -36,7 +36,10 @@ pub mod extfmt;
#[cfg(notest)]
pub mod lang;
extern mod rustrt {
mod rustrt {
use unstable::{raw_thread, rust_little_lock};
pub extern {
pub unsafe fn rust_create_little_lock() -> rust_little_lock;
pub unsafe fn rust_destroy_little_lock(lock: rust_little_lock);
pub unsafe fn rust_lock_little_lock(lock: rust_little_lock);
@ -44,10 +47,11 @@ extern mod rustrt {
pub unsafe fn rust_raw_thread_start(f: &fn()) -> *raw_thread;
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
}
}
#[allow(non_camel_case_types)] // runtime type
type raw_thread = libc::c_void;
pub type raw_thread = libc::c_void;
/**
@ -204,7 +208,7 @@ impl<T:Owned> Clone for SharedMutableState<T> {
/****************************************************************************/
#[allow(non_camel_case_types)] // runtime type
type rust_little_lock = *libc::c_void;
pub type rust_little_lock = *libc::c_void;
struct LittleLock {
l: rust_little_lock,

View File

@ -37,8 +37,12 @@ pub fn at_exit(f: ~fn()) {
// NB: The double pointer indirection here is because ~fn() is a fat
// pointer and due to FFI problems I am more comfortable making the
// interface use a normal pointer
extern mod rustrt {
mod rustrt {
use libc::c_void;
pub extern {
fn rust_register_exit_function(runner: *c_void, f: ~~fn());
}
}
struct ExitFunctions {

View File

@ -26,12 +26,16 @@ pub const FROZEN_BIT: uint = 0x80000000;
#[cfg(target_word_size = "64")]
pub const FROZEN_BIT: uint = 0x8000000000000000;
pub extern mod rustrt {
pub mod rustrt {
use libc::{c_char, uintptr_t};
pub extern {
#[rust_stack]
unsafe fn rust_upcall_malloc(td: *c_char, size: uintptr_t) -> *c_char;
#[rust_stack]
unsafe fn rust_upcall_free(ptr: *c_char);
}
}
#[lang="fail_"]

View File

@ -28,8 +28,13 @@ use sys;
use uint;
use vec;
#[abi = "cdecl"]
pub extern mod rustrt {
pub mod rustrt {
use libc;
use sys;
use vec::raw;
#[abi = "cdecl"]
pub extern {
// These names are terrible. reserve_shared applies
// to ~[] and reserve_shared_actual applies to @[].
unsafe fn vec_reserve_shared(++t: *sys::TypeDesc,
@ -38,6 +43,7 @@ pub extern mod rustrt {
unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
++v: **raw::VecRepr,
++n: libc::size_t);
}
}
/// Returns true if a vector contains no elements