Created
June 25, 2013 07:54
-
-
Save Aatch/5856745 to your computer and use it in GitHub Desktop.
My Magnificent Hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum opaque {} | |
trait thing { | |
pub fn foo(&self); | |
} | |
impl thing for opaque { | |
pub fn foo(&self) { | |
unsafe { | |
let o : *[int,..8] = std::cast::transmute(self); | |
println(fmt!("%?", *o)); | |
} | |
} | |
} | |
fn main() { | |
unsafe { | |
let o = test(); | |
o.foo(); | |
} | |
} | |
unsafe fn test() -> &'static thing { | |
let src = [987654321,..8]; | |
let a = std::libc::malloc(128 as std::libc::size_t) as *mut [int,..8]; | |
let srcp = &src; | |
std::ptr::copy_memory(a, srcp, 1); | |
println(fmt!("%?", a)); | |
let o : &'static opaque = std::cast::transmute(a); | |
o as &thing | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment