Skip to content

Commit ecd3d48

Browse files
committed
---
yaml --- r: 151494 b: refs/heads/try2 c: 426d022 h: refs/heads/master v: v3
1 parent d241b41 commit ecd3d48

File tree

114 files changed

+1171
-1533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+1171
-1533
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 58d540f0c6cdab817aba3705c9d4842b995ab4c9
8+
refs/heads/try2: 426d022732d02a86d53076e8a35e081f2e29c7cb
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/mk/crates.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
TARGET_CRATES := libc std green rustuv native flate arena glob term semver \
5353
uuid serialize sync getopts collections num test time rand \
5454
workcache url log regex graphviz core
55-
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros
55+
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros
5656
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5757
TOOLS := compiletest rustdoc rustc
5858

@@ -61,7 +61,7 @@ DEPS_std := core libc native:rustrt native:compiler-rt native:backtrace
6161
DEPS_green := std rand native:context_switch
6262
DEPS_rustuv := std native:uv native:uv_support
6363
DEPS_native := std
64-
DEPS_syntax := std term serialize collections log fmt_macros
64+
DEPS_syntax := std term serialize collections log
6565
DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts \
6666
collections time log
6767
DEPS_rustdoc := rustc native:hoedown serialize sync getopts collections \
@@ -88,7 +88,6 @@ DEPS_workcache := std serialize collections log
8888
DEPS_log := std sync
8989
DEPS_regex := std collections
9090
DEPS_regex_macros = syntax std regex
91-
DEPS_fmt_macros = std
9291

9392
TOOL_DEPS_compiletest := test green rustuv getopts
9493
TOOL_DEPS_rustdoc := rustdoc native

branches/try2/src/compiletest/runtest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ fn make_lib_name(config: &config, auxfile: &Path, testfile: &Path) -> Path {
997997
fn make_exe_name(config: &config, testfile: &Path) -> Path {
998998
let mut f = output_base_name(config, testfile);
999999
if !os::consts::EXE_SUFFIX.is_empty() {
1000-
match f.filename().map(|s| Vec::from_slice(s).append(os::consts::EXE_SUFFIX.as_bytes())) {
1000+
match f.filename().map(|s| s + os::consts::EXE_SUFFIX.as_bytes()) {
10011001
Some(v) => f.set_filename(v),
10021002
None => ()
10031003
}
@@ -1091,7 +1091,7 @@ fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
10911091

10921092
fn aux_output_dir_name(config: &config, testfile: &Path) -> Path {
10931093
let mut f = output_base_name(config, testfile);
1094-
match f.filename().map(|s| Vec::from_slice(s).append(bytes!(".libaux"))) {
1094+
match f.filename().map(|s| s + bytes!(".libaux")) {
10951095
Some(v) => f.set_filename(v),
10961096
None => ()
10971097
}
@@ -1273,7 +1273,7 @@ fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path {
12731273
(*p).clone()
12741274
} else {
12751275
let stem = p.filestem().unwrap();
1276-
p.with_filename(Vec::from_slice(stem).append(bytes!("-")).append(suffix.as_bytes()))
1276+
p.with_filename(stem + bytes!("-") + suffix.as_bytes())
12771277
}
12781278
}
12791279

branches/try2/src/doc/guide-container.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ Iterators offer generic conversion to containers with the `collect` adaptor:
266266

267267
~~~
268268
let xs = [0, 1, 1, 2, 3, 5, 8];
269-
let ys = xs.iter().rev().skip(1).map(|&x| x * 2).collect::<Vec<int>>();
270-
assert_eq!(ys, vec![10, 6, 4, 2, 2, 0]);
269+
let ys = xs.iter().rev().skip(1).map(|&x| x * 2).collect::<~[int]>();
270+
assert_eq!(ys, ~[10, 6, 4, 2, 2, 0]);
271271
~~~
272272

273273
The method requires a type hint for the container type, if the surrounding code
@@ -278,14 +278,14 @@ implementing the `FromIterator` trait. For example, the implementation for
278278
vectors is as follows:
279279

280280
~~~ {.ignore}
281-
impl<T> FromIterator<T> for Vec<T> {
282-
fn from_iter<I:Iterator<A>>(mut iterator: I) -> Vec<T> {
281+
impl<A> FromIterator<A> for ~[A] {
282+
pub fn from_iter<T: Iterator<A>>(iterator: &mut T) -> ~[A] {
283283
let (lower, _) = iterator.size_hint();
284-
let mut vector = Vec::with_capacity(lower);
285-
for element in iterator {
286-
vector.push(element);
284+
let mut xs = with_capacity(lower);
285+
for x in iterator {
286+
xs.push(x);
287287
}
288-
vector
288+
xs
289289
}
290290
}
291291
~~~

branches/try2/src/doc/rust.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,10 +1741,10 @@ import public items from their destination, not private items.
17411741
## Attributes
17421742

17431743
~~~~ {.notrust .ebnf .gram}
1744-
attribute : '#' '!' ? '[' meta_item ']' ;
1745-
meta_item : ident [ '=' literal
1746-
| '(' meta_seq ')' ] ? ;
1747-
meta_seq : meta_item [ ',' meta_seq ]* ;
1744+
attribute : '#' '!' ? '[' attr_list ']' ;
1745+
attr_list : attr [ ',' attr_list ]* ;
1746+
attr : ident [ '=' literal
1747+
| '(' attr_list ')' ] ? ;
17481748
~~~~
17491749

17501750
Static entities in Rust &mdash; crates, modules and items &mdash; may have _attributes_
@@ -3598,18 +3598,18 @@ and the cast expression in `main`.
35983598
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
35993599

36003600
~~~~
3601-
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
3601+
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> ~[B] {
36023602
if xs.len() == 0 {
3603-
return vec![];
3603+
return ~[];
36043604
}
36053605
let first: B = f(xs[0].clone());
3606-
let rest: Vec<B> = map(f, xs.slice(1, xs.len()));
3607-
return vec![first].append(rest.as_slice());
3606+
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
3607+
return ~[first] + rest;
36083608
}
36093609
~~~~
36103610

36113611
Here, `first` has type `B`, referring to `map`'s `B` type parameter;
3612-
and `rest` has type `Vec<B>`, a vector type with element type `B`.
3612+
and `rest` has type `~[B]`, a vector type with element type `B`.
36133613

36143614
### Self types
36153615

branches/try2/src/doc/tutorial.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,8 +1588,8 @@ let mut numbers = vec![1, 2, 3];
15881588
numbers.push(4);
15891589
numbers.push(5);
15901590
1591-
// The type of a unique vector is written as `Vec<int>`
1592-
let more_numbers: Vec<int> = numbers.move_iter().map(|i| i+1).collect();
1591+
// The type of a unique vector is written as `~[int]`
1592+
let more_numbers: ~[int] = numbers.move_iter().collect();
15931593
15941594
// The original `numbers` value can no longer be used, due to move semantics.
15951595
@@ -1633,7 +1633,7 @@ view[0] = 5;
16331633
let ys: &mut [int] = &mut [1, 2, 3];
16341634
~~~
16351635

1636-
Square brackets denote indexing into a slice or fixed-size vector:
1636+
Square brackets denote indexing into a vector:
16371637

16381638
~~~~
16391639
# enum Crayon { Almond, AntiqueBrass, Apricot,
@@ -1647,7 +1647,7 @@ match crayons[0] {
16471647
}
16481648
~~~~
16491649

1650-
A slice or fixed-size vector can be destructured using pattern matching:
1650+
A vector can be destructured using pattern matching:
16511651

16521652
~~~~
16531653
let numbers: &[int] = &[1, 2, 3];
@@ -1660,10 +1660,9 @@ let score = match numbers {
16601660
~~~~
16611661

16621662
Both vectors and strings support a number of useful [methods](#methods),
1663-
defined in [`std::vec`], [`std::slice`], and [`std::str`].
1663+
defined in [`std::vec`] and [`std::str`].
16641664

16651665
[`std::vec`]: std/vec/index.html
1666-
[`std::slice`]: std/slice/index.html
16671666
[`std::str`]: std/str/index.html
16681667

16691668
# Ownership escape hatches

branches/try2/src/libcore/cast.rs

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,32 @@ use mem;
1414
use intrinsics;
1515
use ptr::copy_nonoverlapping_memory;
1616

17+
/// Casts the value at `src` to U. The two types must have the same length.
18+
#[inline]
19+
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
20+
let mut dest: U = mem::uninit();
21+
let dest_ptr: *mut u8 = transmute(&mut dest);
22+
let src_ptr: *u8 = transmute(src);
23+
copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::<U>());
24+
dest
25+
}
26+
27+
/**
28+
* Move a thing into the void
29+
*
30+
* The forget function will take ownership of the provided value but neglect
31+
* to run any required cleanup or memory-management operations on it.
32+
*/
33+
#[inline]
34+
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing); }
35+
36+
/**
37+
* Force-increment the reference count on a shared box. If used
38+
* carelessly, this can leak the box.
39+
*/
40+
#[inline]
41+
pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
42+
1743
/**
1844
* Transform a value of one type into a value of another type.
1945
* Both types must have the same size and alignment.
@@ -28,29 +54,10 @@ use ptr::copy_nonoverlapping_memory;
2854
* ```
2955
*/
3056
#[inline]
31-
pub unsafe fn transmute<T, U>(thing: T) -> U {
57+
pub unsafe fn transmute<L, G>(thing: L) -> G {
3258
intrinsics::transmute(thing)
3359
}
3460

35-
/**
36-
* Move a thing into the void
37-
*
38-
* The forget function will take ownership of the provided value but neglect
39-
* to run any required cleanup or memory-management operations on it.
40-
*/
41-
#[inline]
42-
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing); }
43-
44-
/// Casts the value at `src` to U. The two types must have the same length.
45-
#[inline]
46-
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
47-
let mut dest: U = mem::uninit();
48-
let dest_ptr: *mut u8 = transmute(&mut dest);
49-
let src_ptr: *u8 = transmute(src);
50-
copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::<U>());
51-
dest
52-
}
53-
5461
/// Coerce an immutable reference to be mutable.
5562
#[inline]
5663
#[deprecated="casting &T to &mut T is undefined behaviour: use Cell<T>, RefCell<T> or Unsafe<T>"]
@@ -99,7 +106,7 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
99106

100107
#[cfg(test)]
101108
mod tests {
102-
use cast::transmute;
109+
use cast::{bump_box_refcount, transmute};
103110
use raw;
104111
use realstd::str::StrAllocating;
105112

@@ -108,6 +115,21 @@ mod tests {
108115
assert_eq!(1u, unsafe { ::cast::transmute_copy(&1) });
109116
}
110117

118+
#[test]
119+
fn test_bump_managed_refcount() {
120+
unsafe {
121+
let managed = @"box box box".to_owned(); // refcount 1
122+
bump_box_refcount(managed); // refcount 2
123+
let ptr: *int = transmute(managed); // refcount 2
124+
let _box1: @~str = ::cast::transmute_copy(&ptr);
125+
let _box2: @~str = ::cast::transmute_copy(&ptr);
126+
assert!(*_box1 == "box box box".to_owned());
127+
assert!(*_box2 == "box box box".to_owned());
128+
// Will destroy _box1 and _box2. Without the bump, this would
129+
// use-after-free. With too many bumps, it would leak.
130+
}
131+
}
132+
111133
#[test]
112134
fn test_transmute() {
113135
unsafe {

branches/try2/src/libcore/cell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Types that provide interior mutability.
11+
//! Types dealing with dynamic mutability
1212
1313
use clone::Clone;
1414
use cmp::Eq;

0 commit comments

Comments
 (0)