diff options
| author | bors <bors@rust-lang.org> | 2013-08-11 14:17:09 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-08-11 14:17:09 -0700 |
| commit | b285f1e6c90332188bb720bf320c507fc4156fdc (patch) | |
| tree | b1b5657b028f7a1c5253ae3bc8d87b806e464a6e /src/libstd | |
| parent | 63c62bea3ac2782ae421d5bd211f2e7393bad7a2 (diff) | |
| parent | 7343478d67ba3eb0c62dcc37db65d82d12b8e140 (diff) | |
| download | rust-b285f1e6c90332188bb720bf320c507fc4156fdc.tar.gz rust-b285f1e6c90332188bb720bf320c507fc4156fdc.zip | |
auto merge of #8455 : nikomatsakis/rust/issue-5762-objects-dralston-d, r=graydon
Fix #5762 and various other aspects of object invocation. r? @graydon
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/repr.rs | 24 | ||||
| -rw-r--r-- | src/libstd/unstable/intrinsics.rs | 24 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index a53e3e796a7..d0970f1b6b7 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -158,6 +158,7 @@ impl ReprVisitor { } #[inline] + #[cfg(stage0)] pub fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool { unsafe { let u = ReprVisitor(ptr, self.writer); @@ -168,6 +169,17 @@ impl ReprVisitor { } #[inline] + #[cfg(not(stage0))] + pub fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool { + unsafe { + let u = ReprVisitor(ptr, self.writer); + let v = reflect::MovePtrAdaptor(u); + visit_tydesc(inner, &v as &TyVisitor); + true + } + } + + #[inline] pub fn write<T:Repr>(&self) -> bool { do self.get |v:&T| { v.write_repr(self.writer); @@ -556,6 +568,7 @@ impl TyVisitor for ReprVisitor { fn visit_closure_ptr(&self, _ck: uint) -> bool { true } } +#[cfg(stage0)] pub fn write_repr<T>(writer: @Writer, object: &T) { unsafe { let ptr = ptr::to_unsafe_ptr(object) as *c_void; @@ -566,6 +579,17 @@ pub fn write_repr<T>(writer: @Writer, object: &T) { } } +#[cfg(not(stage0))] +pub fn write_repr<T>(writer: @Writer, object: &T) { + unsafe { + let ptr = ptr::to_unsafe_ptr(object) as *c_void; + let tydesc = get_tydesc::<T>(); + let u = ReprVisitor(ptr, writer); + let v = reflect::MovePtrAdaptor(u); + visit_tydesc(tydesc, &v as &TyVisitor) + } +} + #[cfg(test)] struct P {a: int, b: float} diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index 9f69ee47e9b..92725fda705 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -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"] @@ -310,8 +328,12 @@ extern "rust-intrinsic" { /// Returns `true` if a type is managed (will be allocated on the local heap) pub fn contains_managed<T>() -> bool; + #[cfg(stage0)] pub fn visit_tydesc(td: *TyDesc, tv: @TyVisitor); + #[cfg(not(stage0))] + pub fn visit_tydesc(td: *TyDesc, tv: &TyVisitor); + pub fn frame_address(f: &once fn(*u8)); /// Get the address of the `__morestack` stack growth function. |
