Skip to content

Commit e1af25e

Browse files
committed
---
yaml --- r: 145202 b: refs/heads/try2 c: 6318288 h: refs/heads/master v: v3
1 parent 19cb60d commit e1af25e

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
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: 71c7798d66953e9f53192d54985a6a46736f5ca5
8+
refs/heads/try2: 63182885d857fdf5641449a397ad7e3f4ebff8a7
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn env() -> ~[(~str,~str)] {
196196
if (ch as uint == 0) {
197197
fail!("os::env() failure getting env string from OS: %s", os::last_os_error());
198198
}
199-
result = unsafe { str::raw::from_c_multistring(ch as *libc::c_char) };
199+
result = unsafe { str::raw::from_c_multistring(ch as *libc::c_char, None) };
200200
FreeEnvironmentStringsA(ch);
201201
result
202202
}

branches/try2/src/libstd/str.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use char;
2222
use char::Char;
2323
use clone::{Clone, DeepClone};
2424
use container::{Container, Mutable};
25+
use num::Times;
2526
use iter::{Iterator, FromIterator, Extendable, range};
2627
use iter::{Filter, AdditiveIterator, Map};
2728
use iter::{Invert, DoubleEndedIterator, ExactSize};
@@ -938,6 +939,7 @@ static TAG_CONT_U8: u8 = 128u8;
938939

939940
/// Unsafe operations
940941
pub mod raw {
942+
use option::{Option, Some};
941943
use cast;
942944
use libc;
943945
use ptr;
@@ -1092,20 +1094,29 @@ pub mod raw {
10921094
}
10931095

10941096
/// Parses a C "multistring", eg windows env values or
1095-
/// the req->ptr result in a uv_fs_readdir() call
1097+
/// the req->ptr result in a uv_fs_readdir() call.
1098+
/// Optionally, a `count` can be passed in, limiting the
1099+
/// parsing to only being done `count`-times.
10961100
#[inline]
1097-
pub unsafe fn from_c_multistring(c: *libc::c_char) -> ~[~str] {
1101+
pub unsafe fn from_c_multistring(buf: *libc::c_char, count: Option<uint>) -> ~[~str] {
10981102
#[fixed_stack_segment]; #[inline(never)];
10991103

1100-
let mut curr_ptr: uint = c as uint;
1104+
let mut curr_ptr: uint = buf as uint;
11011105
let mut result = ~[];
1102-
while(*(curr_ptr as *libc::c_char) != 0 as libc::c_char) {
1106+
let mut ctr = 0;
1107+
let (limited_count, limit) = match count {
1108+
Some(limit) => (true, limit),
1109+
None => (false, 0)
1110+
};
1111+
while(*(curr_ptr as *libc::c_char) != 0 as libc::c_char
1112+
&& ((limited_count && ctr < limit) || !limited_count)) {
11031113
let env_pair = from_c_str(
11041114
curr_ptr as *libc::c_char);
11051115
result.push(env_pair);
11061116
curr_ptr +=
11071117
libc::strlen(curr_ptr as *libc::c_char) as uint
11081118
+ 1;
1119+
ctr += 1;
11091120
}
11101121
result
11111122
}
@@ -1127,10 +1138,11 @@ pub mod raw {
11271138
11281139
#[test]
11291140
fn test_str_multistring_parsing() {
1141+
use option::None;
11301142
unsafe {
11311143
let input = bytes!("zero", "\x00", "one", "\x00", "\x00");
11321144
let ptr = vec::raw::to_ptr(input);
1133-
let mut result = from_c_multistring(ptr as *libc::c_char);
1145+
let mut result = from_c_multistring(ptr as *libc::c_char, None);
11341146
assert!(result.len() == 2);
11351147
let mut ctr = 0;
11361148
for x in result.iter() {

0 commit comments

Comments
 (0)