Skip to content

Commit 16b8358

Browse files
committed
---
yaml --- r: 105983 b: refs/heads/auto c: fc7a112 h: refs/heads/master i: 105981: 9cbc586 105979: 7f7c122 105975: e8788b8 105967: 9fa06cb 105951: abaaa0f 105919: f8ce778 105855: 282821f 105727: c387a4e 105471: d51eda6 v: v3
1 parent a05e576 commit 16b8358

File tree

20 files changed

+686
-151
lines changed

20 files changed

+686
-151
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 58e4ab2b33f559107dbdfa9d3cab882cf8029481
16+
refs/heads/auto: fc7a112808fa918fa76c39ebd324bc5d19bc66e1
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/mk/docs.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
DOCS := index tutorial guide-ffi guide-macros guide-lifetimes \
3030
guide-tasks guide-container guide-pointers guide-testing \
3131
guide-runtime complement-bugreport complement-cheatsheet \
32-
complement-lang-faq complement-project-faq rust rustdoc
32+
complement-lang-faq complement-project-faq rust rustdoc \
33+
guide-unsafe
3334

3435
PDF_DOCS := tutorial rust
3536

branches/auto/src/doc/guide-ffi.md

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -170,85 +170,6 @@ Foreign libraries often hand off ownership of resources to the calling code.
170170
When this occurs, we must use Rust's destructors to provide safety and guarantee
171171
the release of these resources (especially in the case of failure).
172172

173-
As an example, we give a reimplementation of owned boxes by wrapping `malloc`
174-
and `free`:
175-
176-
~~~~
177-
use std::cast;
178-
use std::libc::{c_void, size_t, malloc, free};
179-
use std::mem;
180-
use std::ptr;
181-
182-
// Define a wrapper around the handle returned by the foreign code.
183-
// Unique<T> has the same semantics as ~T
184-
pub struct Unique<T> {
185-
// It contains a single raw, mutable pointer to the object in question.
186-
priv ptr: *mut T
187-
}
188-
189-
// Implement methods for creating and using the values in the box.
190-
// NB: For simplicity and correctness, we require that T has kind Send
191-
// (owned boxes relax this restriction, and can contain managed (GC) boxes).
192-
// This is because, as implemented, the garbage collector would not know
193-
// about any shared boxes stored in the malloc'd region of memory.
194-
impl<T: Send> Unique<T> {
195-
pub fn new(value: T) -> Unique<T> {
196-
unsafe {
197-
let ptr = malloc(std::mem::size_of::<T>() as size_t) as *mut T;
198-
assert!(!ptr.is_null());
199-
// `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it
200-
// move_val_init moves a value into this memory without
201-
// attempting to drop the original value.
202-
mem::move_val_init(&mut *ptr, value);
203-
Unique{ptr: ptr}
204-
}
205-
}
206-
207-
// the 'r lifetime results in the same semantics as `&*x` with ~T
208-
pub fn borrow<'r>(&'r self) -> &'r T {
209-
unsafe { cast::copy_lifetime(self, &*self.ptr) }
210-
}
211-
212-
// the 'r lifetime results in the same semantics as `&mut *x` with ~T
213-
pub fn borrow_mut<'r>(&'r mut self) -> &'r mut T {
214-
unsafe { cast::copy_mut_lifetime(self, &mut *self.ptr) }
215-
}
216-
}
217-
218-
// The key ingredient for safety, we associate a destructor with
219-
// Unique<T>, making the struct manage the raw pointer: when the
220-
// struct goes out of scope, it will automatically free the raw pointer.
221-
// NB: This is an unsafe destructor, because rustc will not normally
222-
// allow destructors to be associated with parametrized types, due to
223-
// bad interaction with managed boxes. (With the Send restriction,
224-
// we don't have this problem.)
225-
#[unsafe_destructor]
226-
impl<T: Send> Drop for Unique<T> {
227-
fn drop(&mut self) {
228-
unsafe {
229-
let x = mem::uninit(); // dummy value to swap in
230-
// We need to move the object out of the box, so that
231-
// the destructor is called (at the end of this scope.)
232-
ptr::replace(self.ptr, x);
233-
free(self.ptr as *mut c_void)
234-
}
235-
}
236-
}
237-
238-
// A comparison between the built-in ~ and this reimplementation
239-
fn main() {
240-
{
241-
let mut x = ~5;
242-
*x = 10;
243-
} // `x` is freed here
244-
245-
{
246-
let mut y = Unique::new(5);
247-
*y.borrow_mut() = 10;
248-
} // `y` is freed here
249-
}
250-
~~~~
251-
252173
# Callbacks from C code to Rust functions
253174

254175
Some external libraries require the usage of callbacks to report back their

branches/auto/src/doc/guide-tasks.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,6 @@ fn pnorm(nums: &~[f64], p: uint) -> f64 {
351351
352352
fn main() {
353353
let numbers = vec::from_fn(1000000, |_| rand::random::<f64>());
354-
println!("Inf-norm = {}", *numbers.iter().max().unwrap());
355-
356354
let numbers_arc = Arc::new(numbers);
357355
358356
for num in range(1u, 10) {

0 commit comments

Comments
 (0)