Skip to content

Commit eaa593f

Browse files
committed
---
yaml --- r: 72677 b: refs/heads/dist-snap c: 8f2d71a h: refs/heads/master i: 72675: 9c7651f v: v3
1 parent fb797f4 commit eaa593f

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: d74ac9ea03eb8faab72ce48b89dd47a14f45982a
10+
refs/heads/dist-snap: 8f2d71ac009e1f93c14266ecebb1c105a0a907e3
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/tutorial-ffi.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,7 @@ wrapping `malloc` and `free`:
150150

151151
~~~~
152152
use 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
160156
pub 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> {
186183
impl<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
}

0 commit comments

Comments
 (0)