Skip to content

Commit 679a5d1

Browse files
committed
---
yaml --- r: 3179 b: refs/heads/master c: 050f629 h: refs/heads/master i: 3177: 325cbe2 3175: be3e04d v: v3
1 parent 3f1fcfb commit 679a5d1

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 94cd2985b267dd8462f2518c5d9109b4e0f71402
2+
refs/heads/master: 050f62983d68cc01ec3e0f81b04a7f4c45145555

trunk/src/lib/ivec.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Interior vector utility functions.
2+
3+
import option::none;
4+
import option::some;
5+
6+
type operator2[T,U,V] = fn(&T, &U) -> V;
7+
8+
native "rust-intrinsic" mod rusti {
9+
fn ivec_len[T](&T[] v) -> uint;
10+
}
11+
12+
native "rust" mod rustrt {
13+
fn ivec_reserve[T](&mutable T[] v, uint n);
14+
fn ivec_on_heap[T](&T[] v) -> bool;
15+
}
16+
17+
/// Reserves space for `n` elements in the given vector.
18+
fn reserve[T](&mutable T[] v, uint n) {
19+
rustrt::ivec_reserve(v, n);
20+
}
21+
22+
fn on_heap[T](&T[] v) -> bool {
23+
ret rustrt::ivec_on_heap(v);
24+
}
25+

trunk/src/lib/std.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod int;
1212
mod uint;
1313
mod u8;
1414
mod vec;
15+
mod ivec;
1516
mod str;
1617

1718
// General io and system-services modules.

trunk/src/rt/rust_builtin.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,16 @@ ivec_reserve(rust_task *task, type_desc *ty, rust_ivec *v, size_t n_elems)
606606
v->alloc = new_alloc;
607607
}
608608

609+
/**
610+
* Returns true if the given vector is on the heap and false if it's on the
611+
* stack.
612+
*/
613+
extern "C" bool
614+
ivec_on_heap(rust_task *task, type_desc *ty, rust_ivec *v)
615+
{
616+
return !v->fill && v->payload.ptr;
617+
}
618+
609619

610620
//
611621
// Local Variables:

trunk/src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ debug_trap
99
debug_tydesc
1010
do_gc
1111
get_time
12+
ivec_on_heap
1213
ivec_reserve
1314
last_os_error
1415
rand_free

trunk/src/test/run-pass/lib-ivec.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// xfail-stage0
2+
3+
use std;
4+
import std::ivec;
5+
6+
fn test_reserve_and_on_heap() {
7+
let int[] v = ~[ 1, 2 ];
8+
assert (!ivec::on_heap(v));
9+
ivec::reserve(v, 8u);
10+
assert (ivec::on_heap(v));
11+
}
12+
13+
fn main() {
14+
test_reserve_and_on_heap();
15+
}
16+

0 commit comments

Comments
 (0)