rustc: Implement conversions from interior vector data to unsafe pointers and vice-versa

This commit is contained in:
Patrick Walton
2011-06-16 17:06:24 -07:00
parent e50c918e6b
commit 40746fa447
4 changed files with 82 additions and 2 deletions

View File

@@ -12,6 +12,8 @@ native "rust-intrinsic" mod rusti {
native "rust" mod rustrt {
fn ivec_reserve[T](&mutable T[] v, uint n);
fn ivec_on_heap[T](&T[] v) -> bool;
fn ivec_to_ptr[T](&T[] v) -> *T;
fn ivec_copy_from_buf[T](&mutable T[] v, *T ptr, uint count);
}
/// Reserves space for `n` elements in the given vector.
@@ -23,3 +25,17 @@ fn on_heap[T](&T[] v) -> bool {
ret rustrt::ivec_on_heap(v);
}
fn to_ptr[T](&T[] v) -> *T {
ret rustrt::ivec_to_ptr(v);
}
fn len[T](&T[] v) -> uint {
ret rusti::ivec_len(v);
}
mod unsafe {
fn copy_from_buf[T](&mutable T[] v, *T ptr, uint count) {
ret rustrt::ivec_copy_from_buf(v, ptr, count);
}
}