File tree 2 files changed +15
-4
lines changed
2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 10
10
11
11
use core:: io:: { Reader , BytesReader } ;
12
12
use core:: io;
13
+ use core:: cast;
13
14
14
15
/// An implementation of the io::Reader interface which reads a buffer of bytes
15
16
pub struct BufReader {
@@ -29,10 +30,13 @@ impl BufReader {
29
30
}
30
31
31
32
fn as_bytes_reader < A > ( & self , f : & fn ( & BytesReader ) -> A ) -> A {
33
+ // XXX FIXME(#5723)
34
+ let bytes = :: core:: util:: id :: < & [ u8 ] > ( self . buf ) ;
35
+ let bytes: & ' static [ u8 ] = unsafe { cast:: transmute ( bytes) } ;
32
36
// Recreating the BytesReader state every call since
33
37
// I can't get the borrowing to work correctly
34
38
let bytes_reader = BytesReader {
35
- bytes : :: core :: util :: id :: < & [ u8 ] > ( self . buf ) ,
39
+ bytes : bytes ,
36
40
pos : @mut * self . pos
37
41
} ;
38
42
Original file line number Diff line number Diff line change @@ -1042,12 +1042,14 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
1042
1042
1043
1043
1044
1044
// Byte readers
1045
- pub struct BytesReader<'self> {
1046
- bytes: &'self [u8],
1045
+ pub struct BytesReader {
1046
+ // FIXME(#5723) see other FIXME below
1047
+ // FIXME(#7268) this should also be parameterized over <'self>
1048
+ bytes: &'static [u8],
1047
1049
pos: @mut uint
1048
1050
}
1049
1051
1050
- impl<'self> Reader for BytesReader<'self> {
1052
+ impl Reader for BytesReader {
1051
1053
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
1052
1054
let count = uint::min(len, self.bytes.len() - *self.pos);
1053
1055
@@ -1084,13 +1086,18 @@ impl<'self> Reader for BytesReader<'self> {
1084
1086
}
1085
1087
1086
1088
pub fn with_bytes_reader<T>(bytes: &[u8], f: &fn(@Reader) -> T) -> T {
1089
+ // XXX XXX XXX this is glaringly unsound
1090
+ // FIXME(#5723) Use a &Reader for the callback's argument. Should be:
1091
+ // fn with_bytes_reader<'r, T>(bytes: &'r [u8], f: &fn(&'r Reader) -> T) -> T
1092
+ let bytes: &'static [u8] = unsafe { cast::transmute(bytes) };
1087
1093
f(@BytesReader {
1088
1094
bytes: bytes,
1089
1095
pos: @mut 0
1090
1096
} as @Reader)
1091
1097
}
1092
1098
1093
1099
pub fn with_str_reader<T>(s: &str, f: &fn(@Reader) -> T) -> T {
1100
+ // FIXME(#5723): As above.
1094
1101
with_bytes_reader(s.as_bytes(), f)
1095
1102
}
1096
1103
You can’t perform that action at this time.
0 commit comments