Skip to content

Commit 0e1a4a4

Browse files
committed
libcore: rewrite vec::unsafe::from_buf in pure rust
1 parent 536cb90 commit 0e1a4a4

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

src/libcore/vec.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ extern mod rustrt {
102102
fn vec_reserve_shared(++t: *sys::TypeDesc,
103103
++v: **unsafe::VecRepr,
104104
++n: libc::size_t);
105-
fn vec_from_buf_shared(++t: *sys::TypeDesc,
106-
++ptr: *(),
107-
++count: libc::size_t) -> *unsafe::VecRepr;
108105
}
109106

110107
#[abi = "rust-intrinsic"]
@@ -1727,10 +1724,11 @@ mod unsafe {
17271724
*/
17281725
#[inline(always)]
17291726
unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
1730-
return ::unsafe::reinterpret_cast(
1731-
rustrt::vec_from_buf_shared(sys::get_type_desc::<T>(),
1732-
ptr as *(),
1733-
elts as size_t));
1727+
let mut dst = ~[];
1728+
reserve(dst, elts);
1729+
set_len(dst, elts);
1730+
as_buf(dst, |p_dst, _len_dst| ptr::memcpy(p_dst, ptr, elts));
1731+
dst
17341732
}
17351733

17361734
/**

src/rt/rust_builtin.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,6 @@ str_reserve_shared(rust_vec_box** sp,
148148
reserve_vec_exact(task, sp, n_elts + 1);
149149
}
150150

151-
/**
152-
* Copies elements in an unsafe buffer to the given interior vector. The
153-
* vector must have size zero.
154-
*/
155-
extern "C" CDECL rust_vec_box*
156-
vec_from_buf_shared(type_desc *ty, void *ptr, size_t count) {
157-
rust_task *task = rust_get_current_task();
158-
size_t fill = ty->size * count;
159-
rust_vec_box* v = (rust_vec_box*)
160-
task->kernel->malloc(fill + sizeof(rust_vec_box),
161-
"vec_from_buf");
162-
v->body.fill = v->body.alloc = fill;
163-
memmove(&v->body.data[0], ptr, fill);
164-
return v;
165-
}
166-
167151
extern "C" CDECL void
168152
rust_str_push(rust_vec_box** sp, uint8_t byte) {
169153
rust_task *task = rust_get_current_task();
@@ -515,8 +499,9 @@ void tm_to_rust_tm(tm* in_tm, rust_tm* out_tm, int32_t gmtoff,
515499
out_tm->tm_nsec = nsec;
516500

517501
if (zone != NULL) {
502+
rust_task *task = rust_get_current_task();
518503
size_t size = strlen(zone);
519-
str_reserve_shared(&out_tm->tm_zone, size);
504+
reserve_vec_exact(task, &out_tm->tm_zone, size + 1);
520505
memcpy(out_tm->tm_zone->body.data, zone, size);
521506
out_tm->tm_zone->body.fill = size + 1;
522507
out_tm->tm_zone->body.data[size] = '\0';

src/rt/rustrt.def.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ start_task
6363
vec_reserve_shared_actual
6464
vec_reserve_shared
6565
str_reserve_shared
66-
vec_from_buf_shared
6766
task_clear_event_reject
6867
task_wait_event
6968
task_signal_event

0 commit comments

Comments
 (0)