Skip to content

Commit cb52f15

Browse files
committed
make integer write and read only apply to types where we know they work
fixes #14274
1 parent f8ac2d4 commit cb52f15

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

base/io.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function write(io::IO, xs...)
5959
end
6060

6161
if ENDIAN_BOM == 0x01020304
62-
function write(s::IO, x::Integer)
62+
function write(s::IO, x::Union{Int8,Int16,UInt16,Int32,UInt32,Int64,UInt64,Int128,UInt128})
6363
sz = sizeof(x)
6464
local written::Int = 0
6565
for n = sz:-1:1
@@ -68,7 +68,7 @@ if ENDIAN_BOM == 0x01020304
6868
return written
6969
end
7070
else
71-
function write(s::IO, x::Integer)
71+
function write(s::IO, x::Union{Int8,Int16,UInt16,Int32,UInt32,Int64,UInt64,Int128,UInt128})
7272
sz = sizeof(x)
7373
local written::Int = 0
7474
for n = 1:sz
@@ -129,7 +129,7 @@ end
129129

130130
read(s::IO, ::Type{Int8}) = reinterpret(Int8, read(s,UInt8))
131131

132-
function read{T <: Integer}(s::IO, ::Type{T})
132+
function read{T <: Union{Int16,UInt16,Int32,UInt32,Int64,UInt64,Int128,UInt128}}(s::IO, ::Type{T})
133133
x = zero(T)
134134
for n = 1:sizeof(x)
135135
x |= (convert(T,read(s,UInt8))<<((n-1)<<3))

base/iostream.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function read(s::IOStream, ::Type{UInt8})
166166
b % UInt8
167167
end
168168

169-
function read{T<:Union{UInt16, Int16, UInt32, Int32, UInt64, Int64}}(s::IOStream, ::Type{T})
169+
function read{T<:Union{UInt16, Int16, UInt32, Int32, UInt64, Int64, UInt128, Int128}}(s::IOStream, ::Type{T})
170170
ccall(:jl_ios_get_nbyte_int, UInt64, (Ptr{Void}, Csize_t), s.ios, sizeof(T)) % T
171171
end
172172

0 commit comments

Comments
 (0)