@@ -98,10 +98,10 @@ mod value;
98
98
use std:: convert:: TryFrom ;
99
99
use std:: fmt;
100
100
use std:: io;
101
+ use std:: io:: { Read , Write } ;
101
102
use std:: num:: NonZeroU32 ;
102
103
use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
103
104
104
- use byteorder:: { BigEndian , LittleEndian , ReadBytesExt , WriteBytesExt } ;
105
105
use rustc_ast:: LitKind ;
106
106
use rustc_data_structures:: fx:: FxHashMap ;
107
107
use rustc_data_structures:: sync:: { HashMapExt , Lock } ;
@@ -561,19 +561,33 @@ pub fn write_target_uint(
561
561
mut target : & mut [ u8 ] ,
562
562
data : u128 ,
563
563
) -> Result < ( ) , io:: Error > {
564
- let len = target. len ( ) ;
564
+ // This u128 holds an "any-size uint" (since smaller uints can fits in it)
565
+ // So we do not write all bytes of the u128, just the "payload".
565
566
match endianness {
566
- Endian :: Little => target. write_uint128 :: < LittleEndian > ( data, len) ,
567
- Endian :: Big => target. write_uint128 :: < BigEndian > ( data, len) ,
568
- }
567
+ Endian :: Little => target. write ( & data. to_le_bytes ( ) ) ?,
568
+ Endian :: Big => target. write ( & data. to_be_bytes ( ) [ 16 - target. len ( ) ..] ) ?,
569
+ } ;
570
+ debug_assert ! ( target. len( ) == 0 ) ; // We should have filled the target buffer.
571
+ Ok ( ( ) )
569
572
}
570
573
571
574
#[ inline]
572
575
pub fn read_target_uint ( endianness : Endian , mut source : & [ u8 ] ) -> Result < u128 , io:: Error > {
573
- match endianness {
574
- Endian :: Little => source. read_uint128 :: < LittleEndian > ( source. len ( ) ) ,
575
- Endian :: Big => source. read_uint128 :: < BigEndian > ( source. len ( ) ) ,
576
- }
576
+ // This u128 holds an "any-size uint" (since smaller uints can fits in it)
577
+ let mut buf = [ 0u8 ; std:: mem:: size_of :: < u128 > ( ) ] ;
578
+ // So we do not read exactly 16 bytes into the u128, just the "payload".
579
+ let uint = match endianness {
580
+ Endian :: Little => {
581
+ source. read ( & mut buf) ?;
582
+ Ok ( u128:: from_le_bytes ( buf) )
583
+ }
584
+ Endian :: Big => {
585
+ source. read ( & mut buf[ 16 - source. len ( ) ..] ) ?;
586
+ Ok ( u128:: from_be_bytes ( buf) )
587
+ }
588
+ } ;
589
+ debug_assert ! ( source. len( ) == 0 ) ; // We should have consumed the source buffer.
590
+ uint
577
591
}
578
592
579
593
////////////////////////////////////////////////////////////////////////////////
0 commit comments