Skip to content

Commit 45dc535

Browse files
jwisenikomatsakis
authored andcommitted
c_vec: Remove the mutable cast be forcing the pointer to be mutable throughout (discussion in #1217).
1 parent c2eb084 commit 45dc535

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/lib/c_vec.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export ptr;
4343
*/
4444

4545
tag t<T> {
46-
t({ base: *T, size: uint, rsrc: @dtor_res});
46+
t({ base: *mutable T, size: uint, rsrc: @dtor_res});
4747
}
4848

4949
resource dtor_res(dtor: option::t<fn@()>) {
@@ -57,14 +57,15 @@ resource dtor_res(dtor: option::t<fn@()>) {
5757
Section: Introduction forms
5858
*/
5959

60-
unsafe fn create<T>(base: *T, size: uint) -> t<T> {
60+
unsafe fn create<T>(base: *mutable T, size: uint) -> t<T> {
6161
ret t({base: base,
6262
size: size,
6363
rsrc: @dtor_res(option::none)
6464
});
6565
}
6666

67-
unsafe fn create_with_dtor<T>(base: *T, size: uint, dtor: fn@()) -> t<T> {
67+
unsafe fn create_with_dtor<T>(base: *mutable T, size: uint, dtor: fn@())
68+
-> t<T> {
6869
ret t({base: base,
6970
size: size,
7071
rsrc: @dtor_res(option::some(dtor))
@@ -77,12 +78,12 @@ unsafe fn create_with_dtor<T>(base: *T, size: uint, dtor: fn@()) -> t<T> {
7778

7879
fn get<copy T>(t: t<T>, ofs: uint) -> T {
7980
assert ofs < (*t).size;
80-
ret unsafe { *ptr::offset((*t).base, ofs) };
81+
ret unsafe { *ptr::mut_offset((*t).base, ofs) };
8182
}
8283

8384
fn set<copy T>(t: t<T>, ofs: uint, v: T) {
8485
assert ofs < (*t).size;
85-
unsafe { *(ptr::offset((*t).base, ofs) as *mutable T) = v };
86+
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
8687
}
8788

8889
/*
@@ -93,6 +94,6 @@ fn size<T>(t: t<T>) -> uint {
9394
ret (*t).size;
9495
}
9596

96-
unsafe fn ptr<T>(t: t<T>) -> *T {
97+
unsafe fn ptr<T>(t: t<T>) -> *mutable T {
9798
ret (*t).base;
9899
}

0 commit comments

Comments
 (0)