File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 1010
1111use core:: io:: { Reader , BytesReader } ;
1212use core:: io;
13+ use core:: cast;
1314
1415/// An implementation of the io::Reader interface which reads a buffer of bytes
1516pub struct BufReader {
@@ -29,10 +30,13 @@ impl BufReader {
2930 }
3031
3132 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) } ;
3236 // Recreating the BytesReader state every call since
3337 // I can't get the borrowing to work correctly
3438 let bytes_reader = BytesReader {
35- bytes : :: core :: util :: id :: < & [ u8 ] > ( self . buf ) ,
39+ bytes : bytes ,
3640 pos : @mut * self . pos
3741 } ;
3842
Original file line number Diff line number Diff line change @@ -1042,12 +1042,14 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
10421042
10431043
10441044// 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],
10471049 pos: @mut uint
10481050}
10491051
1050- impl<'self> Reader for BytesReader<'self> {
1052+ impl Reader for BytesReader {
10511053 fn read(&self, bytes: &mut [u8], len: uint) -> uint {
10521054 let count = uint::min(len, self.bytes.len() - *self.pos);
10531055
@@ -1084,13 +1086,18 @@ impl<'self> Reader for BytesReader<'self> {
10841086}
10851087
10861088pub 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) };
10871093 f(@BytesReader {
10881094 bytes: bytes,
10891095 pos: @mut 0
10901096 } as @Reader)
10911097}
10921098
10931099pub fn with_str_reader<T>(s: &str, f: &fn(@Reader) -> T) -> T {
1100+ // FIXME(#5723): As above.
10941101 with_bytes_reader(s.as_bytes(), f)
10951102}
10961103
You can’t perform that action at this time.
0 commit comments