Skip to content

Commit eb83294

Browse files
committed
change read(::IO, ::Ref) to read!`, fix fix #21592
deprecate `read(io, type, dims)`, fix #21450
1 parent 236e486 commit eb83294

File tree

6 files changed

+18
-21
lines changed

6 files changed

+18
-21
lines changed

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ Deprecated or removed
110110
implementations is now in AbstractFFTs.jl, the bindings to the FFTW library are in FFTW.jl,
111111
and the Base signal processing functions which used FFTs are now in DSP.jl ([#21956]).
112112

113+
* `read(io, type, dims)` is deprecated to `read!(io, Array{type}(dims))` ([#21450]).
114+
115+
* `read(::IO, ::Ref)` is now a method of `read!`, since it mutates its `Ref` argument ([#21592]).
116+
113117

114118
Julia v0.6.0 Release Notes
115119
==========================

base/deprecated.jl

+6
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,12 @@ end
14851485
using .DSP
14861486
export conv, conv2, deconv, filt, filt!, xcorr
14871487

1488+
@deprecate read(s::IO, x::Ref) read!(s, x)
1489+
1490+
@deprecate read(s::IO, t::Type, d1::Int, dims::Int...) read!(s, Array{t}(tuple(d1,dims...)))
1491+
@deprecate read(s::IO, t::Type, d1::Integer, dims::Integer...) read!(s, Array{t}(convert(Tuple{Vararg{Int}},tuple(d1,dims...))))
1492+
@deprecate read(s::IO, t::Type, dims::Dims) read!(s, Array{t}(dims))
1493+
14881494
# END 0.7 deprecations
14891495

14901496
# BEGIN 1.0 deprecations

base/distributed/messages.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function serialize_hdr_raw(io, hdr)
167167
end
168168

169169
function deserialize_hdr_raw(io)
170-
data = read(io, Ref{NTuple{4,Int}}())[]
170+
data = read!(io, Ref{NTuple{4,Int}}())[]
171171
return MsgHeader(RRID(data[1], data[2]), RRID(data[3], data[4]))
172172
end
173173

base/io.jl

+3-16
Original file line numberDiff line numberDiff line change
@@ -361,29 +361,16 @@ end
361361

362362
@noinline unsafe_read(s::IO, p::Ref{T}, n::Integer) where {T} = unsafe_read(s, unsafe_convert(Ref{T}, p)::Ptr, n) # mark noinline to ensure ref is gc-rooted somewhere (by the caller)
363363
unsafe_read(s::IO, p::Ptr, n::Integer) = unsafe_read(s, convert(Ptr{UInt8}, p), convert(UInt, n))
364-
read(s::IO, x::Ref{T}) where {T} = (unsafe_read(s, x, Core.sizeof(T)); x)
364+
read!(s::IO, x::Ref{T}) where {T} = (unsafe_read(s, x, Core.sizeof(T)); x)
365365

366366
read(s::IO, ::Type{Int8}) = reinterpret(Int8, read(s, UInt8))
367367
function read(s::IO, T::Union{Type{Int16},Type{UInt16},Type{Int32},Type{UInt32},Type{Int64},Type{UInt64},Type{Int128},Type{UInt128},Type{Float16},Type{Float32},Type{Float64}})
368-
return read(s, Ref{T}(0))[]::T
368+
return read!(s, Ref{T}(0))[]::T
369369
end
370370

371371
read(s::IO, ::Type{Bool}) = (read(s, UInt8) != 0)
372372
read(s::IO, ::Type{Ptr{T}}) where {T} = convert(Ptr{T}, read(s, UInt))
373373

374-
read(s::IO, t::Type{T}, d1::Int, dims::Int...) where {T} = read(s, t, tuple(d1,dims...))
375-
read(s::IO, t::Type{T}, d1::Integer, dims::Integer...) where {T} =
376-
read(s, t, convert(Tuple{Vararg{Int}},tuple(d1,dims...)))
377-
378-
"""
379-
read(stream::IO, T, dims)
380-
381-
Read a series of values of type `T` from `stream`, in canonical binary representation.
382-
`dims` is either a tuple or a series of integer arguments specifying the size of the `Array{T}`
383-
to return.
384-
"""
385-
read(s::IO, ::Type{T}, dims::Dims) where {T} = read!(s, Array{T}(dims))
386-
387374
@noinline function read!(s::IO, a::Array{UInt8}) # mark noinline to ensure the array is gc-rooted somewhere (by the caller)
388375
unsafe_read(s, pointer(a), sizeof(a))
389376
return a
@@ -523,7 +510,7 @@ end
523510
524511
Read at most `nb` bytes from `s`, returning a `Vector{UInt8}` of the bytes read.
525512
"""
526-
function read(s::IO, nb=typemax(Int))
513+
function read(s::IO, nb::Integer = typemax(Int))
527514
# Let readbytes! grow the array progressively by default
528515
# instead of taking of risk of over-allocating
529516
b = Vector{UInt8}(nb == typemax(Int) ? 1024 : nb)

base/serialize.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ function deserialize_array(s::AbstractSerializer)
862862
end
863863
end
864864
else
865-
A = read(s.io, elty, dims)
865+
A = read!(s.io, Array{elty}(dims))
866866
end
867867
s.table[slot] = A
868868
return A

test/read.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ for (name, f) in l
149149
@test read(io(), Int) == read(filename,Int)
150150
s1 = io()
151151
s2 = IOBuffer(text)
152-
@test read(s1, UInt32, 2) == read(s2, UInt32, 2)
152+
@test read!(s1, Array{UInt32}(2)) == read!(s2, Array{UInt32}(2))
153153
@test !eof(s1)
154-
@test read(s1, UInt8, 5) == read(s2, UInt8, 5)
154+
@test read!(s1, Array{UInt8}(5)) == read!(s2, Array{UInt8}(5))
155155
@test !eof(s1)
156-
@test read(s1, UInt8, 1) == read(s2, UInt8, 1)
156+
@test read!(s1, Array{UInt8}(1)) == read!(s2, Array{UInt8}(1))
157157
@test eof(s1)
158158
@test_throws EOFError read(s1, UInt8)
159159
@test eof(s1)

0 commit comments

Comments
 (0)