File tree 2 files changed +13
-20
lines changed
2 files changed +13
-20
lines changed Original file line number Diff line number Diff line change @@ -238,28 +238,14 @@ pub fn last_uv_error<H, W: Watcher + NativeHandle<*H>>(watcher: &W) -> UvError {
238
238
}
239
239
240
240
pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
241
-
242
- // XXX: Could go in str::raw
243
- unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
244
- let s = s as *u8;
245
- let mut (curr, len) = (s, 0u);
246
- while *curr != 0u8 {
247
- len += 1u;
248
- curr = ptr::offset(s, len);
249
- }
250
-
251
- str::raw::buf_as_slice(s, len, |d| cast::transmute(d))
252
- }
253
-
254
-
255
241
unsafe {
256
242
// Importing error constants
257
243
use rt::uv::uvll::*;
258
244
use rt::io::*;
259
245
260
246
// uv error descriptions are static
261
247
let c_desc = uvll::strerror(&*uverr);
262
- let desc = c_str_to_static_slice(c_desc);
248
+ let desc = str::raw:: c_str_to_static_slice(c_desc);
263
249
264
250
let kind = match uverr.code {
265
251
UNKNOWN => OtherIoError,
Original file line number Diff line number Diff line change @@ -1396,12 +1396,19 @@ pub mod raw {
1396
1396
/// Converts a byte to a string.
1397
1397
pub unsafe fn from_byte ( u : u8 ) -> ~str { raw:: from_bytes ( [ u] ) }
1398
1398
1399
- /// Form a slice from a *u8 buffer of the given length without copying.
1400
- pub unsafe fn buf_as_slice < T > ( buf : * u8 , len : uint ,
1401
- f : & fn ( v : & str ) -> T ) -> T {
1402
- let v = ( buf, len + 1 ) ;
1399
+ /// Form a slice from a C string. Unsafe because the caller must ensure the
1400
+ /// C string has the static lifetime, or else the return value may be
1401
+ /// invalidated later.
1402
+ pub unsafe fn c_str_to_static_slice ( s : * libc:: c_char ) -> & ' static str {
1403
+ let s = s as * u8 ;
1404
+ let mut ( curr, len) = ( s, 0 u) ;
1405
+ while * curr != 0u8 {
1406
+ len += 1 u;
1407
+ curr = ptr:: offset ( s, len) ;
1408
+ }
1409
+ let v = ( s, len + 1 ) ;
1403
1410
assert ! ( is_utf8( :: cast:: transmute( v) ) ) ;
1404
- f ( :: cast:: transmute ( v) )
1411
+ :: cast:: transmute ( v)
1405
1412
}
1406
1413
1407
1414
/**
You can’t perform that action at this time.
0 commit comments