De-export std::c_vec. Part of Part of #3583.

This commit is contained in:
Graydon Hoare 2012-09-28 17:43:57 -07:00
parent 3654287826
commit 9e6d3cf3c9
2 changed files with 7 additions and 15 deletions

View File

@ -26,19 +26,13 @@
* still held if needed. * still held if needed.
*/ */
export CVec;
export CVec, c_vec_with_dtor;
export get, set;
export len;
export ptr;
/** /**
* The type representing a foreign 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 * Wrapped in a enum for opacity; FIXME #818 when it is possible to have
* truly opaque types, this should be revisited. * truly opaque types, this should be revisited.
*/ */
enum CVec<T> { pub enum CVec<T> {
CVecCtor({ base: *mut T, len: uint, rsrc: @DtorRes}) CVecCtor({ base: *mut T, len: uint, rsrc: @DtorRes})
} }
@ -70,7 +64,7 @@ fn DtorRes(dtor: Option<fn@()>) -> DtorRes {
* * base - A foreign pointer to a buffer * * base - A foreign pointer to a buffer
* * len - The number of elements in the buffer * * len - The number of elements in the buffer
*/ */
unsafe fn CVec<T>(base: *mut T, len: uint) -> CVec<T> { pub unsafe fn CVec<T>(base: *mut T, len: uint) -> CVec<T> {
return CVecCtor({ return CVecCtor({
base: base, base: base,
len: len, len: len,
@ -89,7 +83,7 @@ unsafe fn CVec<T>(base: *mut T, len: uint) -> CVec<T> {
* * dtor - A function to run when the value is destructed, useful * * dtor - A function to run when the value is destructed, useful
* for freeing the buffer, etc. * for freeing the buffer, etc.
*/ */
unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@()) pub unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
-> CVec<T> { -> CVec<T> {
return CVecCtor({ return CVecCtor({
base: base, base: base,
@ -107,7 +101,7 @@ unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
* *
* Fails if `ofs` is greater or equal to the length of the vector * Fails if `ofs` is greater or equal to the length of the vector
*/ */
fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T { pub fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
assert ofs < len(t); assert ofs < len(t);
return unsafe { *ptr::mut_offset((*t).base, ofs) }; return unsafe { *ptr::mut_offset((*t).base, ofs) };
} }
@ -117,7 +111,7 @@ fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
* *
* Fails if `ofs` is greater or equal to the length of the vector * Fails if `ofs` is greater or equal to the length of the vector
*/ */
fn set<T: Copy>(t: CVec<T>, ofs: uint, +v: T) { pub fn set<T: Copy>(t: CVec<T>, ofs: uint, +v: T) {
assert ofs < len(t); assert ofs < len(t);
unsafe { *ptr::mut_offset((*t).base, ofs) = v }; unsafe { *ptr::mut_offset((*t).base, ofs) = v };
} }
@ -127,18 +121,17 @@ fn set<T: Copy>(t: CVec<T>, ofs: uint, +v: T) {
*/ */
/// Returns the length of the vector /// Returns the length of the vector
fn len<T>(t: CVec<T>) -> uint { pub fn len<T>(t: CVec<T>) -> uint {
return (*t).len; return (*t).len;
} }
/// Returns a pointer to the first element of the vector /// Returns a pointer to the first element of the vector
unsafe fn ptr<T>(t: CVec<T>) -> *mut T { pub unsafe fn ptr<T>(t: CVec<T>) -> *mut T {
return (*t).base; return (*t).base;
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[legacy_exports];
use libc::*; use libc::*;
fn malloc(n: size_t) -> CVec<u8> { fn malloc(n: size_t) -> CVec<u8> {

View File

@ -67,7 +67,6 @@ mod uv_global_loop;
// Utility modules // Utility modules
#[legacy_exports]
mod c_vec; mod c_vec;
mod timer; mod timer;
mod cell; mod cell;