struct Item {
int id;
char name[8];
std::vector<int> refs;
};
currently becomes in the refcount model:
pub struct Item {
pub id: Value<i32>,
pub name: Value<Box<[u8]>>,
pub refs: Value<Vec<i32>>,
}
This breaks 2 patterns:
- field writes of reinterpreted structs are lost.
*reinterpreted_p.upgrade().deref().field.borrow_mut = 42 loses the field write because reinterpreted_p.upgrade().deref() is a temporary
- taking the address of a field from a reinterpreted struct is dangling.
reinterpreted_p.upgrade().deref().field.as_pointer() dangles because reinterpreted_p.upgrade().deref() is a temporary
The solution is to write the struct as:
pub struct Item {
pub id: i32,
pub name: Box<[u8]>,
pub refs: Vec<i32>,
}
And add a new PtrKind for field pointers that saves a pointer to the parent struct + an offset into the struct.
currently becomes in the refcount model:
This breaks 2 patterns:
*reinterpreted_p.upgrade().deref().field.borrow_mut = 42loses the field write becausereinterpreted_p.upgrade().deref()is a temporaryreinterpreted_p.upgrade().deref().field.as_pointer()dangles becausereinterpreted_p.upgrade().deref()is a temporaryThe solution is to write the struct as:
And add a new PtrKind for field pointers that saves a pointer to the parent struct + an offset into the struct.