Skip to content

Commit 151a65b

Browse files
committed
---
yaml --- r: 153098 b: refs/heads/try2 c: 935da07 h: refs/heads/master v: v3
1 parent ad33d8c commit 151a65b

File tree

12 files changed

+333
-130
lines changed

12 files changed

+333
-130
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: 29ec2506abb1d382e432cae2519aa7b7695c276a
8+
refs/heads/try2: 935da0739e71c5581e5e6abb564e18f894e0ec04
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/rust.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ nav {
132132
-moz-column-count: 2;
133133
-webkit-column-count: 2;
134134
font-size: 15px;
135+
margin: 0 0 1em 0;
135136
}
136137
p {
137138
margin: 0 0 1em 0;
@@ -275,7 +276,7 @@ dd {
275276

276277
nav ul {
277278
list-style-type: none;
278-
margin: 0 0 20px 0;
279+
margin: 0;
279280
padding-left: 0px;
280281
}
281282

branches/try2/src/doc/rust.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,7 @@ A temporary's lifetime equals the largest lifetime of any reference that points
25392539
#### Moved and copied types
25402540

25412541
When a [local variable](#memory-slots) is used
2542-
as an [rvalue](#lvalues-rvalues-and-temporaries)
2542+
as an [rvalue](#lvalues,-rvalues-and-temporaries)
25432543
the variable will either be moved or copied, depending on its type.
25442544
For types that contain [owning pointers](#pointer-types)
25452545
or values that implement the special trait `Drop`,
@@ -2562,7 +2562,7 @@ string, boolean value, or the unit value.
25622562
### Path expressions
25632563

25642564
A [path](#paths) used as an expression context denotes either a local variable or an item.
2565-
Path expressions are [lvalues](#lvalues-rvalues-and-temporaries).
2565+
Path expressions are [lvalues](#lvalues,-rvalues-and-temporaries).
25662566

25672567
### Tuple expressions
25682568

@@ -2675,7 +2675,7 @@ foo().x;
26752675
(Struct {a: 10, b: 20}).a;
26762676
~~~~
26772677

2678-
A field access is an [lvalue](#lvalues-rvalues-and-temporaries) referring to the value of that field.
2678+
A field access is an [lvalue](#lvalues,-rvalues-and-temporaries) referring to the value of that field.
26792679
When the type providing the field inherits mutabilty, it can be [assigned](#assignment-expressions) to.
26802680

26812681
Also, if the type of the expression to the left of the dot is a pointer,
@@ -2711,7 +2711,7 @@ idx_expr : expr '[' expr ']' ;
27112711

27122712
[Vector](#vector-types)-typed expressions can be indexed by writing a
27132713
square-bracket-enclosed expression (the index) after them. When the
2714-
vector is mutable, the resulting [lvalue](#lvalues-rvalues-and-temporaries) can be assigned to.
2714+
vector is mutable, the resulting [lvalue](#lvalues,-rvalues-and-temporaries) can be assigned to.
27152715

27162716
Indices are zero-based, and may be of any integral type. Vector access
27172717
is bounds-checked at run-time. When the check fails, it will put the
@@ -2737,7 +2737,7 @@ before the expression they apply to.
27372737
: Negation. May only be applied to numeric types.
27382738
* `*`
27392739
: Dereference. When applied to a [pointer](#pointer-types) it denotes the pointed-to location.
2740-
For pointers to mutable locations, the resulting [lvalue](#lvalues-rvalues-and-temporaries) can be assigned to.
2740+
For pointers to mutable locations, the resulting [lvalue](#lvalues,-rvalues-and-temporaries) can be assigned to.
27412741
On non-pointer types, it calls the `deref` method of the `std::ops::Deref` trait, or the
27422742
`deref_mut` method of the `std::ops::DerefMut` trait (if implemented by the type and required
27432743
for an outer expression that will or could mutate the dereference), and produces the
@@ -2872,8 +2872,8 @@ fn avg(v: &[f64]) -> f64 {
28722872

28732873
#### Assignment expressions
28742874

2875-
An _assignment expression_ consists of an [lvalue](#lvalues-rvalues-and-temporaries) expression followed by an
2876-
equals sign (`=`) and an [rvalue](#lvalues-rvalues-and-temporaries) expression.
2875+
An _assignment expression_ consists of an [lvalue](#lvalues,-rvalues-and-temporaries) expression followed by an
2876+
equals sign (`=`) and an [rvalue](#lvalues,-rvalues-and-temporaries) expression.
28772877

28782878
Evaluating an assignment expression [either copies or moves](#moved-and-copied-types) its right-hand operand to its left-hand operand.
28792879

@@ -3186,7 +3186,7 @@ fn main() {
31863186
~~~~
31873187

31883188
A `match` behaves differently depending on whether or not the head expression
3189-
is an [lvalue or an rvalue](#lvalues-rvalues-and-temporaries).
3189+
is an [lvalue or an rvalue](#lvalues,-rvalues-and-temporaries).
31903190
If the head expression is an rvalue, it is
31913191
first evaluated into a temporary location, and the resulting value
31923192
is sequentially compared to the patterns in the arms until a match
@@ -3550,7 +3550,7 @@ There are four varieties of pointer in Rust:
35503550
: These point to memory _owned by some other value_.
35513551
References arise by (automatic) conversion from owning pointers, managed pointers,
35523552
or by applying the borrowing operator `&` to some other value,
3553-
including [lvalues, rvalues or temporaries](#lvalues-rvalues-and-temporaries).
3553+
including [lvalues, rvalues or temporaries](#lvalues,-rvalues-and-temporaries).
35543554
References are written `&content`, or in some cases `&'f content` for some lifetime-variable `f`,
35553555
for example `&int` means a reference to an integer.
35563556
Copying a reference is a "shallow" operation:
@@ -3852,7 +3852,7 @@ references to any boxes; the remainder of its heap is immediately freed.
38523852
A task's stack contains slots.
38533853

38543854
A _slot_ is a component of a stack frame, either a function parameter,
3855-
a [temporary](#lvalues-rvalues-and-temporaries), or a local variable.
3855+
a [temporary](#lvalues,-rvalues-and-temporaries), or a local variable.
38563856

38573857
A _local variable_ (or *stack-local* allocation) holds a value directly,
38583858
allocated within the stack's memory. The value is a part of the stack frame.

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ pub static WSASYS_STATUS_LEN: uint = 128;
1919
pub static FIONBIO: libc::c_long = 0x8004667e;
2020
static FD_SETSIZE: uint = 64;
2121
pub static MSG_DONTWAIT: libc::c_int = 0;
22+
pub static ERROR_ILLEGAL_CHARACTER: libc::c_int = 582;
23+
pub static ENABLE_ECHO_INPUT: libc::DWORD = 0x4;
24+
pub static ENABLE_EXTENDED_FLAGS: libc::DWORD = 0x80;
25+
pub static ENABLE_INSERT_MODE: libc::DWORD = 0x20;
26+
pub static ENABLE_LINE_INPUT: libc::DWORD = 0x2;
27+
pub static ENABLE_PROCESSED_INPUT: libc::DWORD = 0x1;
28+
pub static ENABLE_QUICK_EDIT_MODE: libc::DWORD = 0x40;
2229

2330
#[repr(C)]
2431
pub struct WSADATA {
@@ -165,3 +172,24 @@ pub mod compat {
165172
})
166173
}
167174
}
175+
176+
extern "system" {
177+
// FIXME - pInputControl should be PCONSOLE_READCONSOLE_CONTROL
178+
pub fn ReadConsoleW(hConsoleInput: libc::HANDLE,
179+
lpBuffer: libc::LPVOID,
180+
nNumberOfCharsToRead: libc::DWORD,
181+
lpNumberOfCharsRead: libc::LPDWORD,
182+
pInputControl: libc::LPVOID) -> libc::BOOL;
183+
184+
pub fn WriteConsoleW(hConsoleOutput: libc::HANDLE,
185+
lpBuffer: libc::types::os::arch::extra::LPCVOID,
186+
nNumberOfCharsToWrite: libc::DWORD,
187+
lpNumberOfCharsWritten: libc::LPDWORD,
188+
lpReserved: libc::LPVOID) -> libc::BOOL;
189+
190+
pub fn GetConsoleMode(hConsoleHandle: libc::HANDLE,
191+
lpMode: libc::LPDWORD) -> libc::BOOL;
192+
193+
pub fn SetConsoleMode(hConsoleHandle: libc::HANDLE,
194+
lpMode: libc::DWORD) -> libc::BOOL;
195+
}

branches/try2/src/libnative/io/mod.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ pub mod pipe;
6969
#[path = "pipe_win32.rs"]
7070
pub mod pipe;
7171

72+
#[cfg(windows)]
73+
#[path = "tty_win32.rs"]
74+
mod tty;
75+
7276
#[cfg(unix)] #[path = "c_unix.rs"] mod c;
7377
#[cfg(windows)] #[path = "c_win32.rs"] mod c;
7478

@@ -280,15 +284,27 @@ impl rtio::IoFactory for IoFactory {
280284
fn pipe_open(&mut self, fd: c_int) -> IoResult<Box<rtio::RtioPipe + Send>> {
281285
Ok(box file::FileDesc::new(fd, true) as Box<rtio::RtioPipe + Send>)
282286
}
287+
#[cfg(unix)]
283288
fn tty_open(&mut self, fd: c_int, _readable: bool)
284289
-> IoResult<Box<rtio::RtioTTY + Send>> {
285-
#[cfg(unix)] use ERROR = libc::ENOTTY;
286-
#[cfg(windows)] use ERROR = libc::ERROR_INVALID_HANDLE;
287290
if unsafe { libc::isatty(fd) } != 0 {
288291
Ok(box file::FileDesc::new(fd, true) as Box<rtio::RtioTTY + Send>)
289292
} else {
290293
Err(IoError {
291-
code: ERROR as uint,
294+
code: libc::ENOTTY as uint,
295+
extra: 0,
296+
detail: None,
297+
})
298+
}
299+
}
300+
#[cfg(windows)]
301+
fn tty_open(&mut self, fd: c_int, _readable: bool)
302+
-> IoResult<Box<rtio::RtioTTY + Send>> {
303+
if tty::is_tty(fd) {
304+
Ok(box tty::WindowsTTY::new(fd) as Box<rtio::RtioTTY + Send>)
305+
} else {
306+
Err(IoError {
307+
code: libc::ERROR_INVALID_HANDLE as uint,
292308
extra: 0,
293309
detail: None,
294310
})

branches/try2/src/libnative/io/timer_unix.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,7 @@ pub fn now() -> u64 {
9393
}
9494
}
9595

96-
97-
// Note: although the last parameter isn't used there is no way now to
98-
// convert it to unit type, because LLVM dies in SjLj preparation
99-
// step (unfortunately iOS uses SjLJ exceptions)
100-
//
101-
// It's definitely a temporary workaround just to get it working.
102-
// So far it looks like an LLVM issue and it was reported:
103-
// http://llvm.org/bugs/show_bug.cgi?id=19855
104-
// Actually this issue is pretty common while compiling for armv7 iOS
105-
// and in most cases it is simply solved by using --opt-level=2 (or -O)
106-
//
107-
// For this specific case unfortunately turning optimizations wasn't
108-
// enough.
109-
fn helper(input: libc::c_int, messages: Receiver<Req>, _: int) {
96+
fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
11097
let mut set: c::fd_set = unsafe { mem::zeroed() };
11198

11299
let mut fd = FileDesc::new(input, true);
@@ -218,7 +205,7 @@ impl Timer {
218205
pub fn new() -> IoResult<Timer> {
219206
// See notes above regarding using int return value
220207
// instead of ()
221-
unsafe { HELPER.boot(|| {0}, helper); }
208+
unsafe { HELPER.boot(|| {}, helper); }
222209

223210
static mut ID: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
224211
let id = unsafe { ID.fetch_add(1, atomics::Relaxed) };
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Windows specific console TTY implementation
12+
//!
13+
//! This module contains the implementation of a Windows specific console TTY.
14+
//! Also converts between UTF-16 and UTF-8. Windows has very poor support for
15+
//! UTF-8 and some functions will fail. In particular ReadFile and ReadConsole
16+
//! will fail when the codepage is set to UTF-8 and a unicode character is
17+
//! entered.
18+
//!
19+
//! FIXME
20+
//! This implementation does not account for codepoints that are split across
21+
//! multiple reads and writes. Also, this implementation does not expose a way
22+
//! to read/write UTF-16 directly. When/if Rust receives a Reader/Writer
23+
//! wrapper that performs encoding/decoding, this implementation should switch
24+
//! to working in raw UTF-16, with such a wrapper around it.
25+
26+
use super::c::{ReadConsoleW, WriteConsoleW, GetConsoleMode, SetConsoleMode};
27+
use super::c::{ERROR_ILLEGAL_CHARACTER};
28+
use super::c::{ENABLE_ECHO_INPUT, ENABLE_EXTENDED_FLAGS};
29+
use super::c::{ENABLE_INSERT_MODE, ENABLE_LINE_INPUT};
30+
use super::c::{ENABLE_PROCESSED_INPUT, ENABLE_QUICK_EDIT_MODE};
31+
use libc::{c_int, HANDLE, LPDWORD, DWORD, LPVOID};
32+
use libc::{get_osfhandle, CloseHandle};
33+
use libc::types::os::arch::extra::LPCVOID;
34+
use std::io::MemReader;
35+
use std::ptr;
36+
use std::rt::rtio::{IoResult, IoError, RtioTTY};
37+
use std::str::{from_utf16, from_utf8};
38+
39+
fn invalid_encoding() -> IoError {
40+
IoError {
41+
code: ERROR_ILLEGAL_CHARACTER as uint,
42+
extra: 0,
43+
detail: Some("text was not valid unicode".to_string()),
44+
}
45+
}
46+
47+
pub fn is_tty(fd: c_int) -> bool {
48+
let mut out: DWORD = 0;
49+
// If this function doesn't fail then fd is a TTY
50+
match unsafe { GetConsoleMode(get_osfhandle(fd) as HANDLE,
51+
&mut out as LPDWORD) } {
52+
0 => false,
53+
_ => true,
54+
}
55+
}
56+
57+
pub struct WindowsTTY {
58+
closeme: bool,
59+
handle: HANDLE,
60+
utf8: MemReader,
61+
}
62+
63+
impl WindowsTTY {
64+
pub fn new(fd: c_int) -> WindowsTTY {
65+
// If the file descriptor is one of stdin, stderr, or stdout
66+
// then it should not be closed by us
67+
let closeme = match fd {
68+
0..2 => false,
69+
_ => true,
70+
};
71+
let handle = unsafe { get_osfhandle(fd) as HANDLE };
72+
WindowsTTY {
73+
handle: handle,
74+
utf8: MemReader::new(Vec::new()),
75+
closeme: closeme,
76+
}
77+
}
78+
}
79+
80+
impl Drop for WindowsTTY {
81+
fn drop(&mut self) {
82+
if self.closeme {
83+
// Nobody cares about the return value
84+
let _ = unsafe { CloseHandle(self.handle) };
85+
}
86+
}
87+
}
88+
89+
impl RtioTTY for WindowsTTY {
90+
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
91+
// Read more if the buffer is empty
92+
if self.utf8.eof() {
93+
let mut utf16 = Vec::from_elem(0x1000, 0u16);
94+
let mut num: DWORD = 0;
95+
match unsafe { ReadConsoleW(self.handle,
96+
utf16.as_mut_ptr() as LPVOID,
97+
utf16.len() as u32,
98+
&mut num as LPDWORD,
99+
ptr::mut_null()) } {
100+
0 => return Err(super::last_error()),
101+
_ => (),
102+
};
103+
utf16.truncate(num as uint);
104+
let utf8 = match from_utf16(utf16.as_slice()) {
105+
Some(utf8) => utf8.into_bytes(),
106+
None => return Err(invalid_encoding()),
107+
};
108+
self.utf8 = MemReader::new(utf8);
109+
}
110+
// MemReader shouldn't error here since we just filled it
111+
Ok(self.utf8.read(buf).unwrap())
112+
}
113+
114+
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
115+
let utf16 = match from_utf8(buf) {
116+
Some(utf8) => utf8.to_utf16(),
117+
None => return Err(invalid_encoding()),
118+
};
119+
let mut num: DWORD = 0;
120+
match unsafe { WriteConsoleW(self.handle,
121+
utf16.as_ptr() as LPCVOID,
122+
utf16.len() as u32,
123+
&mut num as LPDWORD,
124+
ptr::mut_null()) } {
125+
0 => Err(super::last_error()),
126+
_ => Ok(()),
127+
}
128+
}
129+
130+
fn set_raw(&mut self, raw: bool) -> IoResult<()> {
131+
// FIXME
132+
// Somebody needs to decide on which of these flags we want
133+
match unsafe { SetConsoleMode(self.handle,
134+
match raw {
135+
true => 0,
136+
false => ENABLE_ECHO_INPUT | ENABLE_EXTENDED_FLAGS |
137+
ENABLE_INSERT_MODE | ENABLE_LINE_INPUT |
138+
ENABLE_PROCESSED_INPUT | ENABLE_QUICK_EDIT_MODE,
139+
}) } {
140+
0 => Err(super::last_error()),
141+
_ => Ok(()),
142+
}
143+
}
144+
145+
fn get_winsize(&mut self) -> IoResult<(int, int)> {
146+
// FIXME
147+
// Get console buffer via CreateFile with CONOUT$
148+
// Make a CONSOLE_SCREEN_BUFFER_INFO
149+
// Call GetConsoleScreenBufferInfo
150+
// Maybe call GetLargestConsoleWindowSize instead?
151+
Err(super::unimpl())
152+
}
153+
154+
// Let us magically declare this as a TTY
155+
fn isatty(&self) -> bool { true }
156+
}

0 commit comments

Comments
 (0)