Skip to content

Commit 0361f69

Browse files
committed
---
yaml --- r: 117704 b: refs/heads/auto c: 47b72e3 h: refs/heads/master v: v3
1 parent ec96f3f commit 0361f69

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: a535cfb1f04953e2307b0a2d1b3ddcfdf348009f
16+
refs/heads/auto: 47b72e388d6f2207c977fb6b06399717bca96a77
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libarena/lib.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,20 @@ fn test_arena_destructors_fail() {
345345
/// run again for these objects.
346346
pub struct TypedArena<T> {
347347
/// A pointer to the next object to be allocated.
348-
ptr: *T,
348+
ptr: Cell<*T>,
349349

350350
/// A pointer to the end of the allocated area. When this pointer is
351351
/// reached, a new chunk is allocated.
352-
end: *T,
352+
end: Cell<*T>,
353353

354354
/// A pointer to the first arena segment.
355-
first: Option<Box<TypedArenaChunk<T>>>,
355+
first: RefCell<TypedArenaChunkRef<T>>,
356356
}
357+
type TypedArenaChunkRef<T> = Option<Box<TypedArenaChunk<T>>>;
357358

358359
struct TypedArenaChunk<T> {
359360
/// Pointer to the next arena segment.
360-
next: Option<Box<TypedArenaChunk<T>>>,
361+
next: TypedArenaChunkRef<T>,
361362

362363
/// The number of elements that this chunk can hold.
363364
capacity: uint,
@@ -443,53 +444,52 @@ impl<T> TypedArena<T> {
443444
pub fn with_capacity(capacity: uint) -> TypedArena<T> {
444445
let chunk = TypedArenaChunk::<T>::new(None, capacity);
445446
TypedArena {
446-
ptr: chunk.start() as *T,
447-
end: chunk.end() as *T,
448-
first: Some(chunk),
447+
ptr: Cell::new(chunk.start() as *T),
448+
end: Cell::new(chunk.end() as *T),
449+
first: RefCell::new(Some(chunk)),
449450
}
450451
}
451452

452453
/// Allocates an object in the TypedArena, returning a reference to it.
453454
#[inline]
454455
pub fn alloc<'a>(&'a self, object: T) -> &'a T {
455-
unsafe {
456-
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
457-
let this: &mut TypedArena<T> = mem::transmute::<&_, &mut _>(self);
458-
if this.ptr == this.end {
459-
this.grow()
460-
}
456+
if self.ptr == self.end {
457+
self.grow()
458+
}
461459

462-
let ptr: &'a mut T = mem::transmute(this.ptr);
460+
let ptr: &'a T = unsafe {
461+
let ptr: &'a mut T = mem::transmute(self.ptr);
463462
ptr::write(ptr, object);
464-
this.ptr = this.ptr.offset(1);
465-
let ptr: &'a T = ptr;
463+
self.ptr.set(self.ptr.get().offset(1));
466464
ptr
467-
}
465+
};
466+
467+
ptr
468468
}
469469

470470
/// Grows the arena.
471471
#[inline(never)]
472-
fn grow(&mut self) {
473-
let chunk = self.first.take_unwrap();
472+
fn grow(&self) {
473+
let chunk = self.first.borrow_mut().take_unwrap();
474474
let new_capacity = chunk.capacity.checked_mul(&2).unwrap();
475475
let chunk = TypedArenaChunk::<T>::new(Some(chunk), new_capacity);
476-
self.ptr = chunk.start() as *T;
477-
self.end = chunk.end() as *T;
478-
self.first = Some(chunk)
476+
self.ptr.set(chunk.start() as *T);
477+
self.end.set(chunk.end() as *T);
478+
*self.first.borrow_mut() = Some(chunk)
479479
}
480480
}
481481

482482
#[unsafe_destructor]
483483
impl<T> Drop for TypedArena<T> {
484484
fn drop(&mut self) {
485485
// Determine how much was filled.
486-
let start = self.first.get_ref().start() as uint;
487-
let end = self.ptr as uint;
486+
let start = self.first.borrow().get_ref().start() as uint;
487+
let end = self.ptr.get() as uint;
488488
let diff = (end - start) / mem::size_of::<T>();
489489

490490
// Pass that to the `destroy` method.
491491
unsafe {
492-
self.first.get_mut_ref().destroy(diff)
492+
self.first.borrow_mut().get_mut_ref().destroy(diff)
493493
}
494494
}
495495
}

0 commit comments

Comments
 (0)