about summary refs log tree commit diff
path: root/doc/tutorial-ffi.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/tutorial-ffi.md')
-rw-r--r--doc/tutorial-ffi.md11
1 files changed, 4 insertions, 7 deletions
diff --git a/doc/tutorial-ffi.md b/doc/tutorial-ffi.md
index 127f8158923..b806df5dd20 100644
--- a/doc/tutorial-ffi.md
+++ b/doc/tutorial-ffi.md
@@ -150,11 +150,7 @@ wrapping `malloc` and `free`:
 
 ~~~~
 use core::libc::{c_void, size_t, malloc, free};
-
-#[abi = "rust-intrinsic"]
-extern "rust-intrinsic" mod rusti {
-    fn init<T>() -> T;
-}
+use core::unstable::intrinsics;
 
 // a wrapper around the handle returned by the foreign code
 pub struct Unique<T> {
@@ -166,7 +162,8 @@ pub impl<'self, T: Owned> Unique<T> {
         unsafe {
             let ptr = malloc(core::sys::size_of::<T>() as size_t) as *mut T;
             assert!(!ptr::is_null(ptr));
-            *ptr = value;
+            // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it
+            intrinsics::move_val_init(&mut *ptr, value);
             Unique{ptr: ptr}
         }
     }
@@ -186,7 +183,7 @@ pub impl<'self, T: Owned> Unique<T> {
 impl<T: Owned> Drop for Unique<T> {
     fn finalize(&self) {
         unsafe {
-            let mut x = rusti::init(); // dummy value to swap in
+            let mut x = intrinsics::init(); // dummy value to swap in
             x <-> *self.ptr; // moving the object out is needed to call the destructor
             free(self.ptr as *c_void)
         }