diff --git a/src/libcore/logging.rs b/src/libcore/logging.rs index a9f63b57fa5..cd7321bf0d3 100644 --- a/src/libcore/logging.rs +++ b/src/libcore/logging.rs @@ -6,8 +6,6 @@ use cast::transmute; -export console_on, console_off, log_type; - #[nolink] extern mod rustrt { #[legacy_exports]; @@ -17,7 +15,7 @@ extern mod rustrt { } /// Turns on logging to stdout globally -fn console_on() { +pub fn console_on() { rustrt::rust_log_console_on(); } @@ -28,7 +26,7 @@ fn console_on() { * runtime environment's logging spec, e.g. by setting * the RUST_LOG environment variable */ -fn console_off() { +pub fn console_off() { rustrt::rust_log_console_off(); } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index b67f572d4f7..bbabceafe8e 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -81,26 +81,6 @@ use cast::{forget, reinterpret_cast, transmute}; use either::{Either, Left, Right}; use option::unwrap; -// Things used by code generated by the pipe compiler. -export entangle, get_buffer, drop_buffer; -export SendPacketBuffered, RecvPacketBuffered; -export Packet, packet, mk_packet, entangle_buffer, HasBuffer, BufferHeader; - -// export these so we can find them in the buffer_resource -// destructor. This is probably a symptom of #3005. -export atomic_add_acq, atomic_sub_rel; - -// User-level things -export SendPacket, RecvPacket, send, recv, try_recv, peek; -export select, select2, selecti, select2i, selectable; -export spawn_service, spawn_service_recv; -export stream, Port, Chan, SharedChan, PortSet, Channel; -export oneshot, ChanOne, PortOne; -export recv_one, try_recv_one, send_one, try_send_one; - -// Functions used by the protocol compiler -export rt; - #[doc(hidden)] const SPIN_COUNT: uint = 0; @@ -123,7 +103,7 @@ impl State : Eq { pure fn ne(other: &State) -> bool { !self.eq(other) } } -struct BufferHeader { +pub struct BufferHeader { // Tracks whether this buffer needs to be freed. We can probably // get away with restricting it to 0 or 1, if we're careful. mut ref_count: int, @@ -195,13 +175,13 @@ impl PacketHeader { } #[doc(hidden)] -type Packet = { +pub type Packet = { header: PacketHeader, mut payload: Option, }; #[doc(hidden)] -trait HasBuffer { +pub trait HasBuffer { // XXX This should not have a trailing underscore fn set_buffer_(b: *libc::c_void); } @@ -213,7 +193,7 @@ impl Packet: HasBuffer { } #[doc(hidden)] -fn mk_packet() -> Packet { +pub fn mk_packet() -> Packet { { header: PacketHeader(), mut payload: None @@ -237,7 +217,7 @@ fn unibuffer() -> ~Buffer> { } #[doc(hidden)] -fn packet() -> *Packet { +pub fn packet() -> *Packet { let b = unibuffer(); let p = ptr::addr_of(b.data); // We'll take over memory management from here. @@ -246,7 +226,7 @@ fn packet() -> *Packet { } #[doc(hidden)] -fn entangle_buffer( +pub fn entangle_buffer( +buffer: ~Buffer, init: fn(*libc::c_void, x: &T) -> *Packet) -> (SendPacketBuffered, RecvPacketBuffered) @@ -286,22 +266,22 @@ extern mod rusti { // If I call the rusti versions directly from a polymorphic function, // I get link errors. This is a bug that needs investigated more. #[doc(hidden)] -fn atomic_xchng_rel(dst: &mut int, src: int) -> int { +pub fn atomic_xchng_rel(dst: &mut int, src: int) -> int { rusti::atomic_xchg_rel(dst, src) } #[doc(hidden)] -fn atomic_add_acq(dst: &mut int, src: int) -> int { +pub fn atomic_add_acq(dst: &mut int, src: int) -> int { rusti::atomic_xadd_acq(dst, src) } #[doc(hidden)] -fn atomic_sub_rel(dst: &mut int, src: int) -> int { +pub fn atomic_sub_rel(dst: &mut int, src: int) -> int { rusti::atomic_xsub_rel(dst, src) } #[doc(hidden)] -fn swap_task(+dst: &mut *rust_task, src: *rust_task) -> *rust_task { +pub fn swap_task(+dst: &mut *rust_task, src: *rust_task) -> *rust_task { // It might be worth making both acquire and release versions of // this. unsafe { @@ -355,7 +335,7 @@ fn swap_state_rel(+dst: &mut State, src: State) -> State { } #[doc(hidden)] -unsafe fn get_buffer(p: *PacketHeader) -> ~Buffer { +pub unsafe fn get_buffer(p: *PacketHeader) -> ~Buffer { transmute((*p).buf_header()) } @@ -391,8 +371,8 @@ fn BufferResource(+b: ~Buffer) -> BufferResource { } #[doc(hidden)] -fn send(+p: SendPacketBuffered, - +payload: T) -> bool { +pub fn send(+p: SendPacketBuffered, + +payload: T) -> bool { let header = p.header(); let p_ = p.unwrap(); let p = unsafe { &*p_ }; @@ -435,7 +415,7 @@ fn send(+p: SendPacketBuffered, Fails if the sender closes the connection. */ -fn recv(+p: RecvPacketBuffered) -> T { +pub fn recv(+p: RecvPacketBuffered) -> T { option::unwrap_expect(try_recv(move p), "connection closed") } @@ -445,7 +425,7 @@ Returns `none` if the sender has closed the connection without sending a message, or `Some(T)` if a message was received. */ -fn try_recv(+p: RecvPacketBuffered) +pub fn try_recv(+p: RecvPacketBuffered) -> Option { let p_ = p.unwrap(); @@ -539,7 +519,7 @@ fn try_recv(+p: RecvPacketBuffered) } /// Returns true if messages are available. -pure fn peek(p: &RecvPacketBuffered) -> bool { +pub pure fn peek(p: &RecvPacketBuffered) -> bool { match unsafe {(*p.header()).state} { Empty => false, Blocked => fail ~"peeking on blocked packet", @@ -691,7 +671,7 @@ Sometimes messages will be available on both endpoints at once. In this case, `select2` may return either `left` or `right`. */ -fn select2( +pub fn select2( +a: RecvPacketBuffered, +b: RecvPacketBuffered) -> Either<(Option, RecvPacketBuffered), @@ -716,12 +696,13 @@ impl *PacketHeader: Selectable { } /// Returns the index of an endpoint that is ready to receive. -fn selecti(endpoints: &[T]) -> uint { +pub fn selecti(endpoints: &[T]) -> uint { wait_many(endpoints) } /// Returns 0 or 1 depending on which endpoint is ready to receive -fn select2i(a: &A, b: &B) -> Either<(), ()> { +pub fn select2i(a: &A, b: &B) -> + Either<(), ()> { match wait_many([a.header(), b.header()]/_) { 0 => Left(()), 1 => Right(()), @@ -733,7 +714,7 @@ fn select2i(a: &A, b: &B) -> Either<(), ()> { list of the remaining endpoints. */ -fn select(+endpoints: ~[RecvPacketBuffered]) +pub fn select(+endpoints: ~[RecvPacketBuffered]) -> (uint, Option, ~[RecvPacketBuffered]) { let ready = wait_many(endpoints.map(|p| p.header())); @@ -747,14 +728,14 @@ fn select(+endpoints: ~[RecvPacketBuffered]) message. */ -type SendPacket = SendPacketBuffered>; +pub type SendPacket = SendPacketBuffered>; #[doc(hidden)] -fn SendPacket(p: *Packet) -> SendPacket { +pub fn SendPacket(p: *Packet) -> SendPacket { SendPacketBuffered(p) } -struct SendPacketBuffered { +pub struct SendPacketBuffered { mut p: Option<*Packet>, mut buffer: Option>, drop { @@ -773,7 +754,7 @@ struct SendPacketBuffered { } } -fn SendPacketBuffered(p: *Packet) +pub fn SendPacketBuffered(p: *Packet) -> SendPacketBuffered { //debug!("take send %?", p); SendPacketBuffered { @@ -814,14 +795,14 @@ impl SendPacketBuffered { /// Represents the receive end of a pipe. It can receive exactly one /// message. -type RecvPacket = RecvPacketBuffered>; +pub type RecvPacket = RecvPacketBuffered>; #[doc(hidden)] -fn RecvPacket(p: *Packet) -> RecvPacket { +pub fn RecvPacket(p: *Packet) -> RecvPacket { RecvPacketBuffered(p) } -struct RecvPacketBuffered { +pub struct RecvPacketBuffered { mut p: Option<*Packet>, mut buffer: Option>, drop { @@ -867,7 +848,7 @@ impl RecvPacketBuffered : Selectable { } } -fn RecvPacketBuffered(p: *Packet) +pub fn RecvPacketBuffered(p: *Packet) -> RecvPacketBuffered { //debug!("take recv %?", p); RecvPacketBuffered { @@ -880,7 +861,7 @@ fn RecvPacketBuffered(p: *Packet) } #[doc(hidden)] -fn entangle() -> (SendPacket, RecvPacket) { +pub fn entangle() -> (SendPacket, RecvPacket) { let p = packet(); (SendPacket(p), RecvPacket(p)) } @@ -892,7 +873,7 @@ endpoint. The send endpoint is returned to the caller and the receive endpoint is passed to the new task. */ -fn spawn_service( +pub fn spawn_service( init: extern fn() -> (SendPacketBuffered, RecvPacketBuffered), +service: fn~(+v: RecvPacketBuffered)) @@ -916,7 +897,7 @@ fn spawn_service( receive state. */ -fn spawn_service_recv( +pub fn spawn_service_recv( init: extern fn() -> (RecvPacketBuffered, SendPacketBuffered), +service: fn~(+v: SendPacketBuffered)) @@ -945,7 +926,7 @@ proto! streamp ( ) /// A trait for things that can send multiple messages. -trait Channel { +pub trait Channel { // It'd be nice to call this send, but it'd conflict with the // built in send kind. @@ -957,7 +938,7 @@ trait Channel { } /// A trait for things that can receive multiple messages. -trait Recv { +pub trait Recv { /// Receives a message, or fails if the connection closes. fn recv() -> T; @@ -978,7 +959,7 @@ trait Recv { type Chan_ = { mut endp: Option> }; /// An endpoint that can send many messages. -enum Chan { +pub enum Chan { Chan_(Chan_) } @@ -986,7 +967,7 @@ enum Chan { type Port_ = { mut endp: Option> }; /// An endpoint that can receive many messages. -enum Port { +pub enum Port { Port_(Port_) } @@ -995,7 +976,7 @@ enum Port { These allow sending or receiving an unlimited number of messages. */ -fn stream() -> (Chan, Port) { +pub fn stream() -> (Chan, Port) { let (c, s) = streamp::init(); (Chan_({ mut endp: Some(move c) }), Port_({ mut endp: Some(move s) })) @@ -1065,11 +1046,11 @@ impl Port: Selectable { } /// Treat many ports as one. -struct PortSet { +pub struct PortSet { mut ports: ~[pipes::Port], } -fn PortSet() -> PortSet{ +pub fn PortSet() -> PortSet{ PortSet { ports: ~[] } @@ -1124,7 +1105,7 @@ impl PortSet : Recv { } /// A channel that can be shared between many senders. -type SharedChan = private::Exclusive>; +pub type SharedChan = private::Exclusive>; impl SharedChan: Channel { fn send(+x: T) { @@ -1152,7 +1133,7 @@ fn SharedChan(+c: Chan) -> SharedChan { } /// Receive a message from one of two endpoints. -trait Select2 { +pub trait Select2 { /// Receive a message or return `none` if a connection closes. fn try_select() -> Either, Option>; /// Receive a message or fail if a connection closes. @@ -1188,12 +1169,12 @@ proto! oneshot ( ) /// The send end of a oneshot pipe. -type ChanOne = oneshot::client::Oneshot; +pub type ChanOne = oneshot::client::Oneshot; /// The receive end of a oneshot pipe. -type PortOne = oneshot::server::Oneshot; +pub type PortOne = oneshot::server::Oneshot; /// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair. -fn oneshot() -> (ChanOne, PortOne) { +pub fn oneshot() -> (ChanOne, PortOne) { oneshot::init() } @@ -1201,13 +1182,13 @@ fn oneshot() -> (ChanOne, PortOne) { * Receive a message from a oneshot pipe, failing if the connection was * closed. */ -fn recv_one(+port: PortOne) -> T { +pub fn recv_one(+port: PortOne) -> T { let oneshot::send(message) = recv(move port); move message } /// Receive a message from a oneshot pipe unless the connection was closed. -fn try_recv_one (+port: PortOne) -> Option { +pub fn try_recv_one (+port: PortOne) -> Option { let message = try_recv(move port); if message.is_none() { None } @@ -1218,7 +1199,7 @@ fn try_recv_one (+port: PortOne) -> Option { } /// Send a message on a oneshot pipe, failing if the connection was closed. -fn send_one(+chan: ChanOne, +data: T) { +pub fn send_one(+chan: ChanOne, +data: T) { oneshot::client::send(move chan, move data); } @@ -1226,7 +1207,7 @@ fn send_one(+chan: ChanOne, +data: T) { * Send a message on a oneshot pipe, or return false if the connection was * closed. */ -fn try_send_one(+chan: ChanOne, +data: T) +pub fn try_send_one(+chan: ChanOne, +data: T) -> bool { oneshot::client::try_send(move chan, move data).is_some() } @@ -1240,10 +1221,9 @@ mod rt { } #[cfg(test)] -mod test { - #[legacy_exports]; +pub mod test { #[test] - fn test_select2() { + pub fn test_select2() { let (c1, p1) = pipes::stream(); let (c2, p2) = pipes::stream(); @@ -1258,7 +1238,7 @@ mod test { } #[test] - fn test_oneshot() { + pub fn test_oneshot() { let (c, p) = oneshot::init(); oneshot::client::send(c, ());