Add a field borrow_offset to the type descriptor indicating
what amount a T* pointer must be adjusted to reach the contents of the box. For `~T` types, this requires knowing the type `T`, which is not known in the case of objects.
This commit is contained in:
parent
3aefb9649d
commit
6fe59bf877
9 changed files with 94 additions and 16 deletions
|
|
@ -38,16 +38,34 @@ pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor};
|
|||
|
||||
pub type GlueFn = extern "Rust" fn(*i8);
|
||||
|
||||
// NB: this has to be kept in sync with the Rust ABI.
|
||||
// NB: this has to be kept in sync with `type_desc` in `rt`
|
||||
#[lang="ty_desc"]
|
||||
#[cfg(not(test))]
|
||||
pub struct TyDesc {
|
||||
// sizeof(T)
|
||||
size: uint,
|
||||
|
||||
// alignof(T)
|
||||
align: uint,
|
||||
|
||||
// Called on a copy of a value of type `T` *after* memcpy
|
||||
take_glue: GlueFn,
|
||||
|
||||
// Called when a value of type `T` is no longer needed
|
||||
drop_glue: GlueFn,
|
||||
|
||||
// Called by drop glue when a value of type `T` can be freed
|
||||
free_glue: GlueFn,
|
||||
|
||||
// Called by reflection visitor to visit a value of type `T`
|
||||
visit_glue: GlueFn,
|
||||
|
||||
// If T represents a box pointer (`@U` or `~U`), then
|
||||
// `borrow_offset` is the amount that the pointer must be adjusted
|
||||
// to find the payload. This is always derivable from the type
|
||||
// `U`, but in the case of `@Trait` or `~Trait` objects, the type
|
||||
// `U` is unknown.
|
||||
borrow_offset: uint,
|
||||
}
|
||||
|
||||
#[lang="opaque"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue