Skip to content

Commit 8db20b7

Browse files
committed
---
yaml --- r: 145141 b: refs/heads/try2 c: 6bc48b6 h: refs/heads/master i: 145139: bd4bfcc v: v3
1 parent f740a85 commit 8db20b7

File tree

4 files changed

+81
-7
lines changed

4 files changed

+81
-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: 0635cb75b59fd99c59ee49fc4036e557de1f349f
8+
refs/heads/try2: 6bc48b63f376439801d43820f6df0990797b8787
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/mk/rt.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ else ifeq ($(OSTYPE_$(1)), apple-darwin)
102102
LIBUV_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/libuv/libuv.a
103103
JEMALLOC_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc/lib/libjemalloc_pic.a
104104
else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
105-
LIBUV_OSTYPE_$(1)_$(2) := unix/freebsd
105+
LIBUV_OSTYPE_$(1)_$(2) := freebsd
106106
LIBUV_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/libuv/libuv.a
107107
JEMALLOC_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc/lib/libjemalloc_pic.a
108108
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
109-
LIBUV_OSTYPE_$(1)_$(2) := unix/android
109+
LIBUV_OSTYPE_$(1)_$(2) := android
110110
LIBUV_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/libuv/libuv.a
111111
JEMALLOC_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc/lib/libjemalloc_pic.a
112112
else
113-
LIBUV_OSTYPE_$(1)_$(2) := unix/linux
113+
LIBUV_OSTYPE_$(1)_$(2) := linux
114114
LIBUV_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/libuv/libuv.a
115115
JEMALLOC_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc/lib/libjemalloc_pic.a
116116
endif
@@ -178,6 +178,7 @@ export PYTHONPATH := $(PYTHONPATH):$$(S)src/gyp/pylib
178178
$$(LIBUV_MAKEFILE_$(1)_$(2)): $$(LIBUV_DEPS)
179179
(cd $(S)src/libuv/ && \
180180
$$(CFG_PYTHON) ./gyp_uv -f make -Dtarget_arch=$$(LIBUV_ARCH_$(1)) -D ninja \
181+
-DOS=$$(LIBUV_OSTYPE_$(1)_$(2)) \
181182
-Goutput_dir=$$(@D) --generator-output $$(@D))
182183

183184
# XXX: Shouldn't need platform-specific conditions here

branches/try2/src/libstd/c_str.rs

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use ops::Drop;
1515
use option::{Option, Some, None};
1616
use ptr::RawPtr;
1717
use ptr;
18+
use str;
1819
use str::StrSlice;
1920
use vec::{ImmutableVector, CopyableVector};
2021
use container::Container;
@@ -97,15 +98,25 @@ impl CString {
9798
/// # Failure
9899
///
99100
/// Fails if the CString is null.
101+
#[inline]
100102
pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
101-
#[fixed_stack_segment]; #[inline(never)];
102103
if self.buf.is_null() { fail!("CString is null!"); }
103104
unsafe {
104-
let len = libc::strlen(self.buf) as uint;
105+
let len = ptr::position(self.buf, |c| *c == 0);
105106
cast::transmute((self.buf, len + 1))
106107
}
107108
}
108109

110+
/// Converts the CString into a `&str` without copying.
111+
/// Returns None if the CString is not UTF-8 or is null.
112+
#[inline]
113+
pub fn as_str<'a>(&'a self) -> Option<&'a str> {
114+
if self.buf.is_null() { return None; }
115+
let buf = self.as_bytes();
116+
let buf = buf.slice_to(buf.len()-1); // chop off the trailing NUL
117+
str::from_utf8_slice_opt(buf)
118+
}
119+
109120
/// Return a CString iterator.
110121
pub fn iter<'a>(&'a self) -> CStringIterator<'a> {
111122
CStringIterator {
@@ -238,7 +249,7 @@ mod tests {
238249
use option::{Some, None};
239250

240251
#[test]
241-
fn test_to_c_str() {
252+
fn test_str_to_c_str() {
242253
do "".to_c_str().with_ref |buf| {
243254
unsafe {
244255
assert_eq!(*ptr::offset(buf, 0), 0);
@@ -257,6 +268,37 @@ mod tests {
257268
}
258269
}
259270

271+
#[test]
272+
fn test_vec_to_c_str() {
273+
let b: &[u8] = [];
274+
do b.to_c_str().with_ref |buf| {
275+
unsafe {
276+
assert_eq!(*ptr::offset(buf, 0), 0);
277+
}
278+
}
279+
280+
do bytes!("hello").to_c_str().with_ref |buf| {
281+
unsafe {
282+
assert_eq!(*ptr::offset(buf, 0), 'h' as libc::c_char);
283+
assert_eq!(*ptr::offset(buf, 1), 'e' as libc::c_char);
284+
assert_eq!(*ptr::offset(buf, 2), 'l' as libc::c_char);
285+
assert_eq!(*ptr::offset(buf, 3), 'l' as libc::c_char);
286+
assert_eq!(*ptr::offset(buf, 4), 'o' as libc::c_char);
287+
assert_eq!(*ptr::offset(buf, 5), 0);
288+
}
289+
}
290+
291+
do bytes!("foo", 0xff).to_c_str().with_ref |buf| {
292+
unsafe {
293+
assert_eq!(*ptr::offset(buf, 0), 'f' as libc::c_char);
294+
assert_eq!(*ptr::offset(buf, 1), 'o' as libc::c_char);
295+
assert_eq!(*ptr::offset(buf, 2), 'o' as libc::c_char);
296+
assert_eq!(*ptr::offset(buf, 3), 0xff);
297+
assert_eq!(*ptr::offset(buf, 4), 0);
298+
}
299+
}
300+
}
301+
260302
#[test]
261303
fn test_is_null() {
262304
let c_str = unsafe { CString::new(ptr::null(), false) };
@@ -349,4 +391,33 @@ mod tests {
349391
}
350392
}
351393
}
394+
395+
#[test]
396+
fn test_as_bytes() {
397+
let c_str = "hello".to_c_str();
398+
assert_eq!(c_str.as_bytes(), bytes!("hello", 0));
399+
let c_str = "".to_c_str();
400+
assert_eq!(c_str.as_bytes(), bytes!(0));
401+
let c_str = bytes!("foo", 0xff).to_c_str();
402+
assert_eq!(c_str.as_bytes(), bytes!("foo", 0xff, 0));
403+
}
404+
405+
#[test]
406+
#[should_fail]
407+
fn test_as_bytes_fail() {
408+
let c_str = unsafe { CString::new(ptr::null(), false) };
409+
c_str.as_bytes();
410+
}
411+
412+
#[test]
413+
fn test_as_str() {
414+
let c_str = "hello".to_c_str();
415+
assert_eq!(c_str.as_str(), Some("hello"));
416+
let c_str = "".to_c_str();
417+
assert_eq!(c_str.as_str(), Some(""));
418+
let c_str = bytes!("foo", 0xff).to_c_str();
419+
assert_eq!(c_str.as_str(), None);
420+
let c_str = unsafe { CString::new(ptr::null(), false) };
421+
assert_eq!(c_str.as_str(), None);
422+
}
352423
}

branches/try2/src/test/run-pass/packed-struct-vec.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-android: FIXME(#9116) Bus error
12+
1113
use std::sys;
1214

1315
#[packed]

0 commit comments

Comments
 (0)