From f41cf208b7809bcb5cd12e81970802a52b2c265e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 26 Sep 2012 15:24:31 -0700 Subject: [PATCH] libcore: De-export box, cast, and dlist --- src/libcore/box.rs | 12 ++++------- src/libcore/cast.rs | 48 +++++++++++++++++++++----------------------- src/libcore/cmp.rs | 29 +++++++++++++------------- src/libcore/dlist.rs | 9 +++------ 4 files changed, 44 insertions(+), 54 deletions(-) diff --git a/src/libcore/box.rs b/src/libcore/box.rs index fd3715b457c..65a641d208f 100644 --- a/src/libcore/box.rs +++ b/src/libcore/box.rs @@ -7,26 +7,22 @@ use cmp::{Eq, Ord}; use intrinsic::TyDesc; -export ptr_eq, raw; - -mod raw { - #[legacy_exports]; - - struct BoxHeaderRepr { +pub mod raw { + pub struct BoxHeaderRepr { ref_count: uint, type_desc: *TyDesc, prev: *BoxRepr, next: *BoxRepr, } - struct BoxRepr { + pub struct BoxRepr { header: BoxHeaderRepr, data: u8 } } -pure fn ptr_eq(a: @T, b: @T) -> bool { +pub pure fn ptr_eq(a: @T, b: @T) -> bool { //! Determine if two shared boxes point to the same object unsafe { ptr::addr_of(*a) == ptr::addr_of(*b) } } diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index 93467404868..679e62c1684 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -1,11 +1,5 @@ //! Unsafe operations -export reinterpret_cast, forget, bump_box_refcount, transmute; -export transmute_mut, transmute_immut, transmute_region, transmute_mut_region; -export transmute_mut_unsafe, transmute_immut_unsafe; - -export copy_lifetime, copy_lifetime_vec; - #[abi = "rust-intrinsic"] extern mod rusti { #[legacy_exports]; @@ -15,7 +9,7 @@ extern mod rusti { /// Casts the value at `src` to U. The two types must have the same length. #[inline(always)] -unsafe fn reinterpret_cast(src: &T) -> U { +pub unsafe fn reinterpret_cast(src: &T) -> U { rusti::reinterpret_cast(*src) } @@ -28,7 +22,7 @@ unsafe fn reinterpret_cast(src: &T) -> U { * reinterpret_cast on managed pointer types. */ #[inline(always)] -unsafe fn forget(-thing: T) { rusti::forget(move thing); } +pub unsafe fn forget(-thing: T) { rusti::forget(move thing); } /** * Force-increment the reference count on a shared box. If used @@ -36,7 +30,7 @@ unsafe fn forget(-thing: T) { rusti::forget(move thing); } * and/or reinterpret_cast when such calls would otherwise scramble a box's * reference count */ -unsafe fn bump_box_refcount(+t: @T) { forget(move t); } +pub unsafe fn bump_box_refcount(+t: @T) { forget(move t); } /** * Transform a value of one type into a value of another type. @@ -47,7 +41,7 @@ unsafe fn bump_box_refcount(+t: @T) { forget(move t); } * assert transmute("L") == ~[76u8, 0u8]; */ #[inline(always)] -unsafe fn transmute(-thing: L) -> G { +pub unsafe fn transmute(-thing: L) -> G { let newthing: G = reinterpret_cast(&thing); forget(move thing); move newthing @@ -55,39 +49,45 @@ unsafe fn transmute(-thing: L) -> G { /// Coerce an immutable reference to be mutable. #[inline(always)] -unsafe fn transmute_mut(+ptr: &a/T) -> &a/mut T { transmute(move ptr) } +pub unsafe fn transmute_mut(+ptr: &a/T) -> &a/mut T { transmute(move ptr) } /// Coerce a mutable reference to be immutable. #[inline(always)] -unsafe fn transmute_immut(+ptr: &a/mut T) -> &a/T { transmute(move ptr) } +pub unsafe fn transmute_immut(+ptr: &a/mut T) -> &a/T { + transmute(move ptr) +} /// Coerce a borrowed pointer to have an arbitrary associated region. #[inline(always)] -unsafe fn transmute_region(+ptr: &a/T) -> &b/T { transmute(move ptr) } +pub unsafe fn transmute_region(+ptr: &a/T) -> &b/T { transmute(move ptr) } /// Coerce an immutable reference to be mutable. #[inline(always)] -unsafe fn transmute_mut_unsafe(+ptr: *const T) -> *mut T { transmute(ptr) } +pub unsafe fn transmute_mut_unsafe(+ptr: *const T) -> *mut T { + transmute(ptr) +} /// Coerce an immutable reference to be mutable. #[inline(always)] -unsafe fn transmute_immut_unsafe(+ptr: *const T) -> *T { transmute(ptr) } +pub unsafe fn transmute_immut_unsafe(+ptr: *const T) -> *T { + transmute(ptr) +} /// Coerce a borrowed mutable pointer to have an arbitrary associated region. #[inline(always)] -unsafe fn transmute_mut_region(+ptr: &a/mut T) -> &b/mut T { +pub unsafe fn transmute_mut_region(+ptr: &a/mut T) -> &b/mut T { transmute(move ptr) } /// Transforms lifetime of the second pointer to match the first. #[inline(always)] -unsafe fn copy_lifetime(_ptr: &a/S, ptr: &T) -> &a/T { +pub unsafe fn copy_lifetime(_ptr: &a/S, ptr: &T) -> &a/T { transmute_region(ptr) } /// Transforms lifetime of the second pointer to match the first. #[inline(always)] -unsafe fn copy_lifetime_vec(_ptr: &a/[S], ptr: &T) -> &a/T { +pub unsafe fn copy_lifetime_vec(_ptr: &a/[S], ptr: &T) -> &a/T { transmute_region(ptr) } @@ -97,16 +97,14 @@ unsafe fn copy_lifetime_vec(_ptr: &a/[S], ptr: &T) -> &a/T { ****************************************************************************/ #[cfg(test)] -mod tests { - #[legacy_exports]; - +pub mod tests { #[test] - fn test_reinterpret_cast() { + pub fn test_reinterpret_cast() { assert 1u == unsafe { reinterpret_cast(&1) }; } #[test] - fn test_bump_box_refcount() { + pub fn test_bump_box_refcount() { unsafe { let box = @~"box box box"; // refcount 1 bump_box_refcount(box); // refcount 2 @@ -121,7 +119,7 @@ mod tests { } #[test] - fn test_transmute() { + pub fn test_transmute() { unsafe { let x = @1; let x: *int = transmute(x); @@ -131,7 +129,7 @@ mod tests { } #[test] - fn test_transmute2() { + pub fn test_transmute2() { unsafe { assert ~[76u8, 0u8] == transmute(~"L"); } diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 37a8f976d74..dedb295dacb 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -14,17 +14,16 @@ and `Eq` to overload the `==` and `!=` operators. #[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; -use nounittest::*; -use unittest::*; -export Ord; -export Eq; +pub use nounittest::*; +pub use unittest::*; + +export Ord, Eq; /// Interfaces used for comparison. // Awful hack to work around duplicate lang items in core test. #[cfg(notest)] mod nounittest { - #[legacy_exports]; /** * Trait for values that can be compared for a sort-order. * @@ -33,7 +32,7 @@ mod nounittest { * default implementations. */ #[lang="ord"] - trait Ord { + pub trait Ord { pure fn lt(other: &self) -> bool; pure fn le(other: &self) -> bool; pure fn ge(other: &self) -> bool; @@ -50,7 +49,7 @@ mod nounittest { * a default implementation. */ #[lang="eq"] - trait Eq { + pub trait Eq { pure fn eq(other: &self) -> bool; pure fn ne(other: &self) -> bool; } @@ -63,14 +62,14 @@ mod nounittest { #[cfg(test)] mod unittest { #[legacy_exports]; - trait Ord { + pub trait Ord { pure fn lt(other: &self) -> bool; pure fn le(other: &self) -> bool; pure fn ge(other: &self) -> bool; pure fn gt(other: &self) -> bool; } - trait Eq { + pub trait Eq { pure fn eq(other: &self) -> bool; pure fn ne(other: &self) -> bool; } @@ -80,27 +79,27 @@ mod unittest { mod unittest { #[legacy_exports];} -pure fn lt(v1: &T, v2: &T) -> bool { +pub pure fn lt(v1: &T, v2: &T) -> bool { (*v1).lt(v2) } -pure fn le(v1: &T, v2: &T) -> bool { +pub pure fn le(v1: &T, v2: &T) -> bool { (*v1).lt(v2) || (*v1).eq(v2) } -pure fn eq(v1: &T, v2: &T) -> bool { +pub pure fn eq(v1: &T, v2: &T) -> bool { (*v1).eq(v2) } -pure fn ne(v1: &T, v2: &T) -> bool { +pub pure fn ne(v1: &T, v2: &T) -> bool { (*v1).ne(v2) } -pure fn ge(v1: &T, v2: &T) -> bool { +pub pure fn ge(v1: &T, v2: &T) -> bool { (*v1).ge(v2) } -pure fn gt(v1: &T, v2: &T) -> bool { +pub pure fn gt(v1: &T, v2: &T) -> bool { (*v1).gt(v2) } diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index 08ce967e025..d50abc64f2b 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -12,9 +12,6 @@ Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate. #[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; -export DList; -export new_dlist, from_elem, from_vec, extensions; - type DListLink = Option>; enum DListNode = @{ @@ -24,7 +21,7 @@ enum DListNode = @{ mut next: DListLink }; -enum DList { +pub enum DList { DList_(@{ mut size: uint, mut hd: DListLink, @@ -94,13 +91,13 @@ pure fn DList() -> DList { } /// Creates a new dlist with a single element -pure fn from_elem(+data: T) -> DList { +pub pure fn from_elem(+data: T) -> DList { let list = DList(); unsafe { list.push(move data); } list } -fn from_vec(+vec: &[T]) -> DList { +pub fn from_vec(+vec: &[T]) -> DList { do vec::foldl(DList(), vec) |list,data| { list.push(data); // Iterating left-to-right -- add newly to the tail. list