Skip to content

Commit

Permalink
Fixed lifetime bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bvssvni committed Apr 11, 2015
1 parent 6dc9533 commit b417a8c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,17 @@ impl Object {
/// of type `T`.
pub unsafe fn get_mut_ivar<T>(&mut self, name: &str) -> &mut T
where T: Encode {
let cls = self.class();
let ptr = match cls.instance_variable(name) {
let offset = match self.class().instance_variable(name) {
Some(ivar) => {
assert!(ivar.type_encoding() == T::encode());
let offset = ivar.offset();
let self_ptr: *mut Object = self;
(self_ptr as *mut u8).offset(offset) as *mut T
offset
}
None => panic!("Ivar {} not found on class {}", name, cls.name()),
None => panic!("Ivar {} not found on class {}", name, self.class().name()),
};
let ptr = {
let self_ptr: *mut Object = self;
(self_ptr as *mut u8).offset(offset) as *mut T
};
&mut *ptr
}
Expand Down

0 comments on commit b417a8c

Please sign in to comment.