File tree Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -150,11 +150,7 @@ wrapping `malloc` and `free`:
150150
151151~~~~
152152use core::libc::{c_void, size_t, malloc, free};
153-
154- #[abi = "rust-intrinsic"]
155- extern "rust-intrinsic" mod rusti {
156- fn init<T>() -> T;
157- }
153+ use core::unstable::intrinsics;
158154
159155// a wrapper around the handle returned by the foreign code
160156pub struct Unique<T> {
@@ -166,7 +162,8 @@ pub impl<'self, T: Owned> Unique<T> {
166162 unsafe {
167163 let ptr = malloc(core::sys::size_of::<T>() as size_t) as *mut T;
168164 assert!(!ptr::is_null(ptr));
169- *ptr = value;
165+ // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it
166+ intrinsics::move_val_init(&mut *ptr, value);
170167 Unique{ptr: ptr}
171168 }
172169 }
@@ -186,7 +183,7 @@ pub impl<'self, T: Owned> Unique<T> {
186183impl<T: Owned> Drop for Unique<T> {
187184 fn finalize(&self) {
188185 unsafe {
189- let mut x = rusti ::init(); // dummy value to swap in
186+ let mut x = intrinsics ::init(); // dummy value to swap in
190187 x <-> *self.ptr; // moving the object out is needed to call the destructor
191188 free(self.ptr as *c_void)
192189 }
You can’t perform that action at this time.
0 commit comments