Skip to content

Commit d5dedd5

Browse files
committed
---
yaml --- r: 128695 b: refs/heads/try c: be6c7cf h: refs/heads/master i: 128693: 4f6aaf0 128691: 29c8934 128687: bf4af7a v: v3
1 parent 96f3fe4 commit d5dedd5

Some content is hidden

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

52 files changed

+1272
-327
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 07d86b46a949a94223da714e35b343243e4ecce4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5-
refs/heads/try: 1d784d46613af14e2c54f3b2b5ce8bb50775e18b
5+
refs/heads/try: be6c7cf882bacc9da96df5304679af678390d5b0
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ please do two things:
1616

1717
2. Run the full Rust test suite with the `make check` command. You're
1818
not off the hook even if you just stick to documentation; code
19-
examples in the docs are tested as well!
19+
examples in the docs are tested as well! Although for simple
20+
wording or grammar fixes, this is probably unnecessary.
2021

2122
Pull requests will be treated as "review requests", and we will give
2223
feedback we expect to see corrected on

branches/try/mk/main.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ endif
139139
RUSTFLAGS_STAGE0 += -C prefer-dynamic
140140
RUSTFLAGS_STAGE1 += -C prefer-dynamic
141141

142+
# Landing pads require a lot of codegen. We can get through bootstrapping faster
143+
# by not emitting them.
144+
RUSTFLAGS_STAGE0 += -Z no-landing-pads
145+
142146
# platform-specific auto-configuration
143147
include $(CFG_SRC_DIR)mk/platform.mk
144148

branches/try/src/doc/guide.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,86 @@ building our guessing game, but we need to know how to do one last thing first:
14321432
get input from the keyboard. You can't have a guessing game without the ability
14331433
to guess!
14341434

1435+
# Strings
1436+
1437+
Strings are an important concept for any programmer to master. Rust's string
1438+
handling system is a bit different than in other languages, due to its systems
1439+
focus. Any time you have a data structure of variable size, things can get
1440+
tricky, and strings are a re-sizable data structure. That said, Rust's strings
1441+
also work differently than in some other systems languages, such as C.
1442+
1443+
Let's dig into the details. A **string** is a sequence of unicode scalar values
1444+
encoded as a stream of UTF-8 bytes. All strings are guaranteed to be
1445+
validly-encoded UTF-8 sequences. Additionally, strings are not null-terminated
1446+
and can contain null bytes.
1447+
1448+
Rust has two main types of strings: `&str` and `String`.
1449+
1450+
The first kind is a `&str`. This is pronounced a 'string slice.' String literals
1451+
are of the type `&str`:
1452+
1453+
```{rust}
1454+
let string = "Hello there.";
1455+
```
1456+
1457+
This string is statically allocated, meaning that it's saved inside our
1458+
compiled program, and exists for the entire duration it runs. The `string`
1459+
binding is a reference to this statically allocated string. String slices
1460+
have a fixed size, and cannot be mutated.
1461+
1462+
A `String`, on the other hand, is an in-memory string. This string is
1463+
growable, and is also guaranteed to be UTF-8.
1464+
1465+
```{rust}
1466+
let mut s = "Hello".to_string();
1467+
println!("{}", s);
1468+
1469+
s.push_str(", world.");
1470+
println!("{}", s);
1471+
```
1472+
1473+
You can coerce a `String` into a `&str` with the `as_slice()` method:
1474+
1475+
```{rust}
1476+
fn takes_slice(slice: &str) {
1477+
println!("Got: {}", slice);
1478+
}
1479+
1480+
fn main() {
1481+
let s = "Hello".to_string();
1482+
takes_slice(s.as_slice());
1483+
}
1484+
```
1485+
1486+
To compare a String to a constant string, prefer `as_slice()`...
1487+
1488+
```{rust}
1489+
fn compare(string: String) {
1490+
if string.as_slice() == "Hello" {
1491+
println!("yes");
1492+
}
1493+
}
1494+
```
1495+
1496+
... over `to_string()`:
1497+
1498+
```{rust}
1499+
fn compare(string: String) {
1500+
if string == "Hello".to_string() {
1501+
println!("yes");
1502+
}
1503+
}
1504+
```
1505+
1506+
Converting a `String` to a `&str` is cheap, but converting the `&str` to a
1507+
`String` involves allocating memory. No reason to do that unless you have to!
1508+
1509+
That's the basics of strings in Rust! They're probably a bit more complicated
1510+
than you are used to, if you come from a scripting language, but when the
1511+
low-level details matter, they really matter. Just remember that `String`s
1512+
allocate memory and control their data, while `&str`s are a reference to
1513+
another string, and you'll be all set.
1514+
14351515
# Standard Input
14361516

14371517
Getting input from the keyboard is pretty easy, but uses some things

branches/try/src/libcollections/ringbuf.rs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ impl<'a, T> ExactSize<&'a mut T> for MutItems<'a, T> {}
403403
fn grow<T>(nelts: uint, loptr: &mut uint, elts: &mut Vec<Option<T>>) {
404404
assert_eq!(nelts, elts.len());
405405
let lo = *loptr;
406-
let newlen = nelts * 2;
407-
elts.reserve(newlen);
406+
elts.reserve(nelts * 2);
407+
let newlen = elts.capacity();
408408

409409
/* fill with None */
410-
for _ in range(elts.len(), elts.capacity()) {
410+
for _ in range(elts.len(), newlen) {
411411
elts.push(None);
412412
}
413413

@@ -750,6 +750,47 @@ mod tests {
750750
assert_eq!(d.len(), 1);
751751
}
752752

753+
#[test]
754+
fn test_with_capacity_non_power_two() {
755+
let mut d3 = RingBuf::with_capacity(3);
756+
d3.push(1i);
757+
758+
// X = None, | = lo
759+
// [|1, X, X]
760+
assert_eq!(d3.pop_front(), Some(1));
761+
// [X, |X, X]
762+
assert_eq!(d3.front(), None);
763+
764+
// [X, |3, X]
765+
d3.push(3);
766+
// [X, |3, 6]
767+
d3.push(6);
768+
// [X, X, |6]
769+
assert_eq!(d3.pop_front(), Some(3));
770+
771+
// Pushing the lo past half way point to trigger
772+
// the 'B' scenario for growth
773+
// [9, X, |6]
774+
d3.push(9);
775+
// [9, 12, |6]
776+
d3.push(12);
777+
778+
d3.push(15);
779+
// There used to be a bug here about how the
780+
// RingBuf made growth assumptions about the
781+
// underlying Vec which didn't hold and lead
782+
// to corruption.
783+
// (Vec grows to next power of two)
784+
//good- [9, 12, 15, X, X, X, X, |6]
785+
//bug- [15, 12, X, X, X, |6, X, X]
786+
assert_eq!(d3.pop_front(), Some(6));
787+
788+
// Which leads us to the following state which
789+
// would be a failure case.
790+
//bug- [15, 12, X, X, X, X, |X, X]
791+
assert_eq!(d3.front(), Some(&9));
792+
}
793+
753794
#[test]
754795
fn test_reserve_exact() {
755796
let mut d = RingBuf::new();

branches/try/src/libcore/num/f32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl Float for f32 {
293293
#[inline]
294294
fn frac_pi_8() -> f32 { consts::FRAC_PI_8 }
295295

296-
/// 1 .0/ pi
296+
/// 1.0 / pi
297297
#[inline]
298298
fn frac_1_pi() -> f32 { consts::FRAC_1_PI }
299299

branches/try/src/liblibc/lib.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,18 +1142,16 @@ pub mod types {
11421142
pub mod os {
11431143
pub mod common {
11441144
pub mod posix01 {
1145-
use types::os::arch::c95::{c_short, time_t, suseconds_t,
1146-
c_long};
1145+
use types::os::arch::c95::{c_short, time_t, c_long};
11471146
use types::os::arch::extra::{int64, time64_t};
11481147
use types::os::arch::posix88::{dev_t, ino_t};
1149-
use types::os::arch::posix88::mode_t;
11501148

11511149
// pub Note: this is the struct called stat64 in win32. Not stat,
11521150
// nor stati64.
11531151
pub struct stat {
11541152
pub st_dev: dev_t,
11551153
pub st_ino: ino_t,
1156-
pub st_mode: mode_t,
1154+
pub st_mode: u16,
11571155
pub st_nlink: c_short,
11581156
pub st_uid: c_short,
11591157
pub st_gid: c_short,
@@ -1171,8 +1169,8 @@ pub mod types {
11711169
}
11721170

11731171
pub struct timeval {
1174-
pub tv_sec: time_t,
1175-
pub tv_usec: suseconds_t,
1172+
pub tv_sec: c_long,
1173+
pub tv_usec: c_long,
11761174
}
11771175

11781176
pub struct timespec {
@@ -1186,7 +1184,7 @@ pub mod types {
11861184
pub mod bsd44 {
11871185
use types::os::arch::c95::{c_char, c_int, c_uint, size_t};
11881186

1189-
pub type SOCKET = c_uint;
1187+
pub type SOCKET = uint;
11901188
pub type socklen_t = c_int;
11911189
pub type sa_family_t = u16;
11921190
pub type in_port_t = u16;
@@ -1197,6 +1195,7 @@ pub mod types {
11971195
}
11981196
pub struct sockaddr_storage {
11991197
pub ss_family: sa_family_t,
1198+
pub __ss_pad1: [u8, ..6],
12001199
pub __ss_align: i64,
12011200
pub __ss_pad2: [u8, ..112],
12021201
}
@@ -1293,12 +1292,9 @@ pub mod types {
12931292
pub mod posix88 {
12941293
pub type off_t = i32;
12951294
pub type dev_t = u32;
1296-
pub type ino_t = i16;
1295+
pub type ino_t = u16;
12971296

1298-
#[cfg(target_arch = "x86")]
1299-
pub type pid_t = i32;
1300-
#[cfg(target_arch = "x86_64")]
1301-
pub type pid_t = i64;
1297+
pub type pid_t = u32;
13021298

13031299
pub type useconds_t = u32;
13041300
pub type mode_t = u16;
@@ -1415,7 +1411,7 @@ pub mod types {
14151411
pub dwPageSize: DWORD,
14161412
pub lpMinimumApplicationAddress: LPVOID,
14171413
pub lpMaximumApplicationAddress: LPVOID,
1418-
pub dwActiveProcessorMask: DWORD,
1414+
pub dwActiveProcessorMask: uint,
14191415
pub dwNumberOfProcessors: DWORD,
14201416
pub dwProcessorType: DWORD,
14211417
pub dwAllocationGranularity: DWORD,
@@ -1950,7 +1946,7 @@ pub mod consts {
19501946
}
19511947
pub mod extra {
19521948
use types::os::arch::c95::c_int;
1953-
use types::os::arch::extra::{WORD, DWORD, BOOL};
1949+
use types::os::arch::extra::{WORD, DWORD, BOOL, HANDLE};
19541950

19551951
pub static TRUE : BOOL = 1;
19561952
pub static FALSE : BOOL = 0;
@@ -1979,7 +1975,7 @@ pub mod consts {
19791975
pub static ERROR_IO_PENDING: c_int = 997;
19801976
pub static ERROR_FILE_INVALID : c_int = 1006;
19811977
pub static ERROR_NOT_FOUND: c_int = 1168;
1982-
pub static INVALID_HANDLE_VALUE : c_int = -1;
1978+
pub static INVALID_HANDLE_VALUE: HANDLE = -1 as HANDLE;
19831979

19841980
pub static DELETE : DWORD = 0x00010000;
19851981
pub static READ_CONTROL : DWORD = 0x00020000;

branches/try/src/libnative/io/c_win32.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub static ENABLE_PROCESSED_INPUT: libc::DWORD = 0x1;
2828
pub static ENABLE_QUICK_EDIT_MODE: libc::DWORD = 0x40;
2929

3030
#[repr(C)]
31+
#[cfg(target_arch = "x86")]
3132
pub struct WSADATA {
3233
pub wVersion: libc::WORD,
3334
pub wHighVersion: libc::WORD,
@@ -37,6 +38,17 @@ pub struct WSADATA {
3738
pub iMaxUdpDg: u16,
3839
pub lpVendorInfo: *mut u8,
3940
}
41+
#[repr(C)]
42+
#[cfg(target_arch = "x86_64")]
43+
pub struct WSADATA {
44+
pub wVersion: libc::WORD,
45+
pub wHighVersion: libc::WORD,
46+
pub iMaxSockets: u16,
47+
pub iMaxUdpDg: u16,
48+
pub lpVendorInfo: *mut u8,
49+
pub szDescription: [u8, ..WSADESCRIPTION_LEN + 1],
50+
pub szSystemStatus: [u8, ..WSASYS_STATUS_LEN + 1],
51+
}
4052

4153
pub type LPWSADATA = *mut WSADATA;
4254

branches/try/src/libnative/io/file_win32.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub fn open(path: &CString, fm: rtio::FileMode, fa: rtio::FileAccess)
320320
dwFlagsAndAttributes,
321321
ptr::mut_null())
322322
};
323-
if handle == libc::INVALID_HANDLE_VALUE as libc::HANDLE {
323+
if handle == libc::INVALID_HANDLE_VALUE {
324324
Err(super::last_error())
325325
} else {
326326
let fd = unsafe {
@@ -368,7 +368,7 @@ pub fn readdir(p: &CString) -> IoResult<Vec<CString>> {
368368
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
369369
let find_handle = libc::FindFirstFileW(path.as_ptr(),
370370
wfd_ptr as libc::HANDLE);
371-
if find_handle as libc::c_int != libc::INVALID_HANDLE_VALUE {
371+
if find_handle != libc::INVALID_HANDLE_VALUE {
372372
let mut paths = vec!();
373373
let mut more_files = 1 as libc::c_int;
374374
while more_files != 0 {
@@ -440,7 +440,7 @@ pub fn readlink(p: &CString) -> IoResult<CString> {
440440
libc::FILE_ATTRIBUTE_NORMAL,
441441
ptr::mut_null())
442442
};
443-
if handle as int == libc::INVALID_HANDLE_VALUE as int {
443+
if handle == libc::INVALID_HANDLE_VALUE {
444444
return Err(super::last_error())
445445
}
446446
// Specify (sz - 1) because the documentation states that it's the size

branches/try/src/libnative/io/pipe_win32.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl UnixStream {
223223
libc::FILE_FLAG_OVERLAPPED,
224224
ptr::mut_null())
225225
};
226-
if result != libc::INVALID_HANDLE_VALUE as libc::HANDLE {
226+
if result != libc::INVALID_HANDLE_VALUE {
227227
return Some(result)
228228
}
229229

@@ -238,7 +238,7 @@ impl UnixStream {
238238
libc::FILE_FLAG_OVERLAPPED,
239239
ptr::mut_null())
240240
};
241-
if result != libc::INVALID_HANDLE_VALUE as libc::HANDLE {
241+
if result != libc::INVALID_HANDLE_VALUE {
242242
return Some(result)
243243
}
244244
}
@@ -253,7 +253,7 @@ impl UnixStream {
253253
libc::FILE_FLAG_OVERLAPPED,
254254
ptr::mut_null())
255255
};
256-
if result != libc::INVALID_HANDLE_VALUE as libc::HANDLE {
256+
if result != libc::INVALID_HANDLE_VALUE {
257257
return Some(result)
258258
}
259259
}
@@ -565,7 +565,7 @@ impl UnixListener {
565565
// and such.
566566
let addr_v = try!(to_utf16(addr));
567567
let ret = unsafe { pipe(addr_v.as_ptr(), true) };
568-
if ret == libc::INVALID_HANDLE_VALUE as libc::HANDLE {
568+
if ret == libc::INVALID_HANDLE_VALUE {
569569
Err(super::last_error())
570570
} else {
571571
Ok(UnixListener { handle: ret, name: addr.clone() })
@@ -680,7 +680,7 @@ impl UnixAcceptor {
680680
// create a second server pipe. If this fails, we disconnect the
681681
// connected client and return an error (see comments above).
682682
let new_handle = unsafe { pipe(name.as_ptr(), false) };
683-
if new_handle == libc::INVALID_HANDLE_VALUE as libc::HANDLE {
683+
if new_handle == libc::INVALID_HANDLE_VALUE {
684684
let ret = Err(super::last_error());
685685
// If our disconnection fails, then there's not really a whole lot
686686
// that we can do, so fail the task.

0 commit comments

Comments
 (0)