Skip to content

Commit d06ee00

Browse files
committed
---
yaml --- r: 59380 b: refs/heads/snap-stage3 c: db38ab9 h: refs/heads/master v: v3
1 parent 82d5eb2 commit d06ee00

File tree

15 files changed

+177
-577
lines changed

15 files changed

+177
-577
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 3225870191f7e6b601d70fa5aa08617eb04b170b
4+
refs/heads/snap-stage3: db38ab9ad9dd5f5f2407129c44eb06e94fa7974b
55
refs/heads/try: c50a9d5b664478e533ba1d1d353213d70c8ad589
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/mk/rt.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ endif
163163
ifdef CFG_WINDOWSY_$(1)
164164
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
165165
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
166-
CFLAGS="$$(CFG_GCCISH_CFLAGS)" \
167-
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS)" \
168166
builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
169167
OS=mingw \
170168
V=$$(VERBOSE)

branches/snap-stage3/src/libcore/char.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use option::{None, Option, Some};
1616
use str;
1717
use u32;
1818
use uint;
19-
use unicode::{derived_property, general_category};
19+
use unicode;
2020

2121
#[cfg(notest)] use cmp::Eq;
2222

@@ -53,17 +53,18 @@ use unicode::{derived_property, general_category};
5353
Cn Unassigned a reserved unassigned code point or a noncharacter
5454
*/
5555

56-
pub fn is_alphabetic(c: char) -> bool { derived_property::Alphabetic(c) }
57-
pub fn is_XID_start(c: char) -> bool { derived_property::XID_Start(c) }
58-
pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) }
56+
pub use is_alphabetic = unicode::derived_property::Alphabetic;
57+
pub use is_XID_start = unicode::derived_property::XID_Start;
58+
pub use is_XID_continue = unicode::derived_property::XID_Continue;
59+
5960

6061
/**
6162
* Indicates whether a character is in lower case, defined
6263
* in terms of the Unicode General Category 'Ll'
6364
*/
6465
#[inline(always)]
6566
pub fn is_lowercase(c: char) -> bool {
66-
return general_category::Ll(c);
67+
return unicode::general_category::Ll(c);
6768
}
6869

6970
/**
@@ -72,7 +73,7 @@ pub fn is_lowercase(c: char) -> bool {
7273
*/
7374
#[inline(always)]
7475
pub fn is_uppercase(c: char) -> bool {
75-
return general_category::Lu(c);
76+
return unicode::general_category::Lu(c);
7677
}
7778

7879
/**
@@ -83,9 +84,9 @@ pub fn is_uppercase(c: char) -> bool {
8384
#[inline(always)]
8485
pub fn is_whitespace(c: char) -> bool {
8586
return ('\x09' <= c && c <= '\x0d')
86-
|| general_category::Zs(c)
87-
|| general_category::Zl(c)
88-
|| general_category::Zp(c);
87+
|| unicode::general_category::Zs(c)
88+
|| unicode::general_category::Zl(c)
89+
|| unicode::general_category::Zp(c);
8990
}
9091

9192
/**
@@ -95,18 +96,18 @@ pub fn is_whitespace(c: char) -> bool {
9596
*/
9697
#[inline(always)]
9798
pub fn is_alphanumeric(c: char) -> bool {
98-
return derived_property::Alphabetic(c) ||
99-
general_category::Nd(c) ||
100-
general_category::Nl(c) ||
101-
general_category::No(c);
99+
return unicode::derived_property::Alphabetic(c) ||
100+
unicode::general_category::Nd(c) ||
101+
unicode::general_category::Nl(c) ||
102+
unicode::general_category::No(c);
102103
}
103104

104105
/// Indicates whether the character is numeric (Nd, Nl, or No)
105106
#[inline(always)]
106107
pub fn is_digit(c: char) -> bool {
107-
return general_category::Nd(c) ||
108-
general_category::Nl(c) ||
109-
general_category::No(c);
108+
return unicode::general_category::Nd(c) ||
109+
unicode::general_category::Nl(c) ||
110+
unicode::general_category::No(c);
110111
}
111112

112113
/**

branches/snap-stage3/src/libcore/container.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ pub trait Map<K, V>: Mutable {
5555
/// Remove a key-value pair from the map. Return true if the key
5656
/// was present in the map, otherwise false.
5757
fn remove(&mut self, key: &K) -> bool;
58-
59-
/// Insert a key-value pair from the map. If the key already had a value
60-
/// present in the map, that value is returned. Otherwise None is returned.
61-
fn swap(&mut self, k: K, v: V) -> Option<V>;
62-
63-
/// Removes a key from the map, returning the value at the key if the key
64-
/// was previously in the map.
65-
fn pop(&mut self, k: &K) -> Option<V>;
6658
}
6759

6860
pub trait Set<T>: Mutable {

branches/snap-stage3/src/libcore/core.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ pub mod unstable;
244244

245245
/* For internal use, not exported */
246246

247-
mod unicode;
247+
pub mod unicode;
248248
#[path = "num/cmath.rs"]
249-
mod cmath;
250-
mod stackwalk;
249+
pub mod cmath;
250+
pub mod stackwalk;
251251
#[path = "rt/mod.rs"]
252-
mod rt;
252+
pub mod rt;
253253

254254
// A curious inner-module that's not exported that contains the binding
255255
// 'core' so that macro-expanded references to core::error and such

branches/snap-stage3/src/libcore/gc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use libc::{size_t, uintptr_t};
4444
use option::{None, Option, Some};
4545
use ptr;
4646
use hashmap::HashSet;
47-
use stackwalk::walk_stack;
47+
use stackwalk;
4848
use sys;
4949

5050
pub use stackwalk::Word;
@@ -230,7 +230,7 @@ unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) {
230230
// frame is marked by a sentinel, which is a box pointer stored on
231231
// the stack.
232232
let mut reached_sentinel = ptr::is_null(sentinel);
233-
for walk_stack |frame| {
233+
for stackwalk::walk_stack |frame| {
234234
let pc = last_ret;
235235
let Segment {segment: next_segment, boundary: boundary} =
236236
find_segment_for_frame(frame.fp, segment);

branches/snap-stage3/src/libcore/hashmap.rs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use rand::RngUtil;
2424
use rand;
2525
use uint;
2626
use vec;
27+
use util::unreachable;
2728
use kinds::Copy;
28-
use util::{replace, unreachable};
2929

3030
static INITIAL_CAPACITY: uint = 32u; // 2^5
3131

@@ -204,7 +204,7 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
204204
/// Inserts the key value pair into the buckets.
205205
/// Assumes that there will be a bucket.
206206
/// True if there was no previous entry with that key
207-
fn insert_internal(&mut self, hash: uint, k: K, v: V) -> Option<V> {
207+
fn insert_internal(&mut self, hash: uint, k: K, v: V) -> bool {
208208
match self.bucket_for_key_with_hash(hash, &k) {
209209
TableFull => { fail!(~"Internal logic error"); }
210210
FoundHole(idx) => {
@@ -213,19 +213,14 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
213213
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
214214
value: v});
215215
self.size += 1;
216-
None
216+
true
217217
}
218218
FoundEntry(idx) => {
219219
debug!("insert overwrite (%?->%?) at idx %?, hash %?",
220220
k, v, idx, hash);
221-
match self.buckets[idx] {
222-
None => { fail!(~"insert_internal: Internal logic error") }
223-
Some(ref mut b) => {
224-
b.hash = hash;
225-
b.key = k;
226-
Some(replace(&mut b.value, v))
227-
}
228-
}
221+
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
222+
value: v});
223+
false
229224
}
230225
}
231226
}
@@ -366,20 +361,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
366361
/// key is replaced by the new value. Return true if the key did
367362
/// not already exist in the map.
368363
fn insert(&mut self, k: K, v: V) -> bool {
369-
self.swap(k, v).is_none()
370-
}
371-
372-
/// Remove a key-value pair from the map. Return true if the key
373-
/// was present in the map, otherwise false.
374-
fn remove(&mut self, k: &K) -> bool {
375-
self.pop(k).is_some()
376-
}
377-
378-
/// Insert a key-value pair from the map. If the key already had a value
379-
/// present in the map, that value is returned. Otherwise None is returned.
380-
fn swap(&mut self, k: K, v: V) -> Option<V> {
381-
// this could be faster.
382-
383364
if self.size >= self.resize_at {
384365
// n.b.: We could also do this after searching, so
385366
// that we do not resize if this call to insert is
@@ -394,11 +375,10 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
394375
self.insert_internal(hash, k, v)
395376
}
396377
397-
/// Removes a key from the map, returning the value at the key if the key
398-
/// was previously in the map.
399-
fn pop(&mut self, k: &K) -> Option<V> {
400-
let hash = k.hash_keyed(self.k0, self.k1) as uint;
401-
self.pop_internal(hash, k)
378+
/// Remove a key-value pair from the map. Return true if the key
379+
/// was present in the map, otherwise false.
380+
fn remove(&mut self, k: &K) -> bool {
381+
self.pop(k).is_some()
402382
}
403383
}
404384
@@ -422,6 +402,31 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
422402
}
423403
}
424404
405+
fn pop(&mut self, k: &K) -> Option<V> {
406+
let hash = k.hash_keyed(self.k0, self.k1) as uint;
407+
self.pop_internal(hash, k)
408+
}
409+
410+
fn swap(&mut self, k: K, v: V) -> Option<V> {
411+
// this could be faster.
412+
let hash = k.hash_keyed(self.k0, self.k1) as uint;
413+
let old_value = self.pop_internal(hash, &k);
414+
415+
if self.size >= self.resize_at {
416+
// n.b.: We could also do this after searching, so
417+
// that we do not resize if this call to insert is
418+
// simply going to update a key in place. My sense
419+
// though is that it's worse to have to search through
420+
// buckets to find the right spot twice than to just
421+
// resize in this corner case.
422+
self.expand();
423+
}
424+
425+
self.insert_internal(hash, k, v);
426+
427+
old_value
428+
}
429+
425430
/// Return the value corresponding to the key in the map, or insert
426431
/// and return the value if it doesn't exist.
427432
fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a V {

branches/snap-stage3/src/libcore/run.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,4 +855,74 @@ mod tests {
855855
fn waitpid_non_existant_pid() {
856856
run::waitpid(123456789); // assume that this pid doesn't exist
857857
}
858+
859+
#[test]
860+
fn test_destroy_once() {
861+
let mut p = run::start_program("echo", []);
862+
p.destroy(); // this shouldn't crash (and nor should the destructor)
863+
}
864+
865+
#[test]
866+
fn test_destroy_twice() {
867+
let mut p = run::start_program("echo", []);
868+
p.destroy(); // this shouldnt crash...
869+
p.destroy(); // ...and nor should this (and nor should the destructor)
870+
}
871+
872+
fn test_destroy_actually_kills(force: bool) {
873+
874+
#[cfg(unix)]
875+
static BLOCK_COMMAND: &'static str = "cat";
876+
877+
#[cfg(windows)]
878+
static BLOCK_COMMAND: &'static str = "cmd";
879+
880+
#[cfg(unix)]
881+
fn process_exists(pid: libc::pid_t) -> bool {
882+
run::program_output("ps", [~"-p", pid.to_str()]).out.contains(pid.to_str())
883+
}
884+
885+
#[cfg(windows)]
886+
fn process_exists(pid: libc::pid_t) -> bool {
887+
888+
use libc::types::os::arch::extra::DWORD;
889+
use libc::funcs::extra::kernel32::{CloseHandle, GetExitCodeProcess, OpenProcess};
890+
use libc::consts::os::extra::{FALSE, PROCESS_QUERY_INFORMATION, STILL_ACTIVE };
891+
892+
unsafe {
893+
let proc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid as DWORD);
894+
if proc.is_null() {
895+
return false;
896+
}
897+
// proc will be non-null if the process is alive, or if it died recently
898+
let mut status = 0;
899+
GetExitCodeProcess(proc, &mut status);
900+
CloseHandle(proc);
901+
return status == STILL_ACTIVE;
902+
}
903+
}
904+
905+
// this program will stay alive indefinitely trying to read from stdin
906+
let mut p = run::start_program(BLOCK_COMMAND, []);
907+
908+
assert!(process_exists(p.get_id()));
909+
910+
if force {
911+
p.force_destroy();
912+
} else {
913+
p.destroy();
914+
}
915+
916+
assert!(!process_exists(p.get_id()));
917+
}
918+
919+
#[test]
920+
fn test_unforced_destroy_actually_kills() {
921+
test_destroy_actually_kills(false);
922+
}
923+
924+
#[test]
925+
fn test_forced_destroy_actually_kills() {
926+
test_destroy_actually_kills(true);
927+
}
858928
}

0 commit comments

Comments
 (0)