diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 02e6c232de7..a7e0f8a3c80 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -55,9 +55,9 @@ native mod rustrt { yield: *libc::uintptr_t); } -#[abi = "rust-intrinsic"] +#[abi = "rust-builtin"] native mod rusti { - fn call_with_retptr(&&f: fn(*uint)) -> T; + fn init() -> T; } type port_id = int; @@ -137,18 +137,13 @@ fn recv(p: port) -> T { recv_(***p) } #[doc = "Receive on a raw port pointer"] fn recv_(p: *rust_port) -> T { - // FIXME: Due to issue 1185 we can't use a return pointer when - // calling C code, and since we can't create our own return - // pointer on the stack, we're going to call a little intrinsic - // that will grab the value of the return pointer, then call this - // function, which we will then use to call the runtime. - fn recv(dptr: *uint, port: *rust_port, - yield: *libc::uintptr_t) unsafe { - rustrt::port_recv(dptr, port, yield); - } let yield = 0u; let yieldp = ptr::addr_of(yield); - let res = rusti::call_with_retptr(bind recv(_, p, yieldp)); + let mut res; + res = rusti::init::(); + log(debug, ptr::addr_of(res)); + rustrt::port_recv(ptr::addr_of(res) as *uint, p, yieldp); + if yield != 0u { // Data isn't available yet, so res has not been initialized. task::yield(); @@ -161,26 +156,18 @@ fn recv_(p: *rust_port) -> T { } #[doc = "Receive on one of two ports"] -fn select2( - p_a: port, p_b: port -) -> either unsafe { - - fn select(dptr: **rust_port, ports: **rust_port, - n_ports: libc::size_t, yield: *libc::uintptr_t) { - rustrt::rust_port_select(dptr, ports, n_ports, yield) - } - - let mut ports = []; - ports += [***p_a, ***p_b]; +fn select2(p_a: port, p_b: port) + -> either unsafe { + let ports = [***p_a, ***p_b]; let n_ports = 2 as libc::size_t; - let yield = 0u; - let yieldp = ptr::addr_of(yield); + let yield = 0u, yieldp = ptr::addr_of(yield); - let resport: *rust_port = vec::as_buf(ports) {|ports| - rusti::call_with_retptr {|retptr| - select(unsafe::reinterpret_cast(retptr), ports, n_ports, yieldp) - } - }; + let mut resport: *rust_port; + resport = rusti::init::<*rust_port>(); + vec::as_buf(ports) {|ports| + rustrt::rust_port_select(ptr::addr_of(resport), ports, n_ports, + yieldp); + } if yield != 0u { // Wait for data diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 750dbdd3e4e..29369d9b8ca 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -8,22 +8,28 @@ export null; export memcpy; export memmove; +import libc::c_void; -#[abi = "rust-intrinsic"] +#[nolink] +#[abi = "cdecl"] +native mod libc_ { + fn memcpy(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void; + fn memmove(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void; +} + +#[abi = "rust-builtin"] native mod rusti { fn addr_of(val: T) -> *T; - fn memcpy(dst: *T, src: *T, count: libc::uintptr_t); - fn memmove(dst: *T, src: *T, count: libc::uintptr_t); } #[doc = "Get an unsafe pointer to a value"] #[inline(always)] -fn addr_of(val: T) -> *T { ret rusti::addr_of(val); } +fn addr_of(val: T) -> *T { rusti::addr_of(val) } #[doc = "Get an unsafe mutable pointer to a value"] #[inline(always)] fn mut_addr_of(val: T) -> *mutable T unsafe { - ret unsafe::reinterpret_cast(rusti::addr_of(val)); + unsafe::reinterpret_cast(rusti::addr_of(val)) } #[doc = "Calculate the offset from a pointer"] @@ -51,7 +57,8 @@ and destination may not overlap. "] #[inline(always)] unsafe fn memcpy(dst: *T, src: *T, count: uint) { - rusti::memcpy(dst, src, count); + let n = count * sys::size_of::(); + libc_::memcpy(dst as *c_void, src as *c_void, n); } #[doc = " @@ -62,7 +69,8 @@ and destination may overlap. "] #[inline(always)] unsafe fn memmove(dst: *T, src: *T, count: uint) { - rusti::memmove(dst, src, count); + let n = count * sys::size_of::(); + libc_::memmove(dst as *c_void, src as *c_void, n); } #[test] diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index b402f98ed26..93d6a9f0089 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -28,13 +28,11 @@ native mod rustrt { fn rust_set_exit_status(code: libc::intptr_t); } -#[abi = "rust-intrinsic"] +#[abi = "rust-builtin"] native mod rusti { - fn get_type_desc() -> *type_desc; - - // Invokes __builtin_frame_address(). - // See . - fn frame_address(n: libc::c_uint) -> libc::uintptr_t; + fn get_tydesc() -> *(); + fn size_of() -> uint; + fn align_of() -> uint; } #[doc = " @@ -44,7 +42,7 @@ Useful for calling certain function in the Rust runtime or otherwise performing dark magick. "] fn get_type_desc() -> *type_desc { - ret rusti::get_type_desc::(); + rusti::get_tydesc::() as *type_desc } #[doc = "Get a string representing the platform-dependent last error"] @@ -54,12 +52,12 @@ fn last_os_error() -> str { #[doc = "Returns the size of a type"] fn size_of() -> uint unsafe { - ret (*get_type_desc::()).size; + rusti::size_of::() } #[doc = "Returns the alignment of a type"] fn align_of() -> uint unsafe { - ret (*get_type_desc::()).align; + rusti::align_of::() } #[doc = "Returns the refcount of a shared box"] diff --git a/src/libcore/unsafe.rs b/src/libcore/unsafe.rs index 9a6375345d0..829d53008ea 100644 --- a/src/libcore/unsafe.rs +++ b/src/libcore/unsafe.rs @@ -2,10 +2,10 @@ export reinterpret_cast, forget; -#[abi = "rust-intrinsic"] +#[abi = "rust-builtin"] native mod rusti { - fn cast(src: T) -> U; - fn leak(-thing: T); + fn forget(-x: T); + fn reinterpret_cast(e: T) -> U; } #[doc = " @@ -13,12 +13,7 @@ Casts the value at `src` to U. The two types must have the same length. "] #[inline(always)] unsafe fn reinterpret_cast(src: T) -> U { - let t1 = sys::get_type_desc::(); - let t2 = sys::get_type_desc::(); - if (*t1).size != (*t2).size { - fail "attempt to cast values of differing sizes"; - } - ret rusti::cast(src); + rusti::reinterpret_cast(src) } #[doc =" @@ -30,7 +25,7 @@ can be used for various acts of magick, particularly when using reinterpret_cast on managed pointer types. "] #[inline(always)] -unsafe fn forget(-thing: T) { rusti::leak(thing); } +unsafe fn forget(-thing: T) { rusti::forget(thing); } #[cfg(test)] mod tests { diff --git a/src/test/run-pass/interior-vec.rs b/src/test/run-pass/interior-vec.rs deleted file mode 100644 index a006fea656d..00000000000 --- a/src/test/run-pass/interior-vec.rs +++ /dev/null @@ -1,29 +0,0 @@ -import rusti::vec_len; - -#[abi = "rust-intrinsic"] -native mod rusti { - fn vec_len(&&v: [T]) -> uint; -} - -fn main() unsafe { - let mut v: [int] = []; - assert (vec_len(v) == 0u); // zero-length - let mut x = [1, 2]; - assert (vec_len(x) == 2u); // on stack - let mut y = [1, 2, 3, 4, 5]; - assert (vec_len(y) == 5u); // on heap - - v += []; - assert (vec_len(v) == 0u); // zero-length append - x += [3]; - assert (vec_len(x) == 3u); // on-stack append - y += [6, 7, 8, 9]; - assert (vec_len(y) == 9u); // on-heap append - - let vv = v + v; - assert (vec_len(vv) == 0u); // zero-length add - let xx = x + [4]; - assert (vec_len(xx) == 4u); // on-stack add - let yy = y + [10, 11]; - assert (vec_len(yy) == 11u); // on-heap add -}