Skip to content

Commit b67b0d1

Browse files
committed
rename IOBuffer/SimpleIOBuffer to AbstractIOBuffer/IOBuffer, to minimize unnecessary API changes
1 parent f607ba2 commit b67b0d1

File tree

9 files changed

+84
-83
lines changed

9 files changed

+84
-83
lines changed

base/LineEdit.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using ..Terminals
77
import ..Terminals: raw!, width, height, cmove, getX,
88
getY, clear_line, beep
99

10-
import Base: ensureroom, peek, show, AnyDict, SimpleIOBuffer
10+
import Base: ensureroom, peek, show, AnyDict
1111

1212
abstract TextInterface
1313
abstract ModeState
@@ -56,7 +56,7 @@ end
5656
type PromptState <: ModeState
5757
terminal::TextTerminal
5858
p::Prompt
59-
input_buffer::SimpleIOBuffer
59+
input_buffer::IOBuffer
6060
ias::InputAreaState
6161
indent::Int
6262
end
@@ -996,8 +996,8 @@ type SearchState <: ModeState
996996
histprompt
997997
#rsearch (true) or ssearch (false)
998998
backward::Bool
999-
query_buffer::SimpleIOBuffer
1000-
response_buffer::SimpleIOBuffer
999+
query_buffer::IOBuffer
1000+
response_buffer::IOBuffer
10011001
ias::InputAreaState
10021002
#The prompt whose input will be replaced by the matched history
10031003
parent
@@ -1049,7 +1049,7 @@ type PrefixSearchState <: ModeState
10491049
terminal
10501050
histprompt
10511051
prefix::ByteString
1052-
response_buffer::SimpleIOBuffer
1052+
response_buffer::IOBuffer
10531053
ias::InputAreaState
10541054
indent::Int
10551055
#The prompt whose input will be replaced by the matched history

base/REPL.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import Base:
1717
Display,
1818
display,
1919
writemime,
20-
AnyDict,
21-
SimpleIOBuffer
20+
AnyDict
2221

2322
import ..LineEdit:
2423
CompletionProvider,
@@ -299,7 +298,7 @@ type REPLHistoryProvider <: HistoryProvider
299298
history_file
300299
cur_idx::Int
301300
last_idx::Int
302-
last_buffer::SimpleIOBuffer
301+
last_buffer::IOBuffer
303302
last_mode
304303
mode_mapping
305304
modes::Array{Symbol,1}

base/deprecated.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ end
501501

502502
# 11554
503503

504-
read!(from::IOBuffer, p::Ptr, nb::Integer) = read!(from, p, Int(nb))
505-
function read!(from::IOBuffer, p::Ptr, nb::Int)
504+
read!(from::AbstractIOBuffer, p::Ptr, nb::Integer) = read!(from, p, Int(nb))
505+
function read!(from::AbstractIOBuffer, p::Ptr, nb::Int)
506506
depwarn("read!(::IOBuffer, ::Ptr) is unsafe and therefore deprecated", :read!)
507507
from.readable || throw(ArgumentError("read failed, IOBuffer is not readable"))
508508
avail = nb_available(from)

base/iobuffer.jl

+60-58
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## work with AbstractVector{UInt8} via I/O primitives ##
44

55
# Stateful string
6-
type IOBuffer{T<:AbstractVector{UInt8}} <: IO
6+
type AbstractIOBuffer{T<:AbstractVector{UInt8}} <: IO
77
data::T # T should support: getindex, setindex!, length, copy!, resize!, and T()
88
readable::Bool
99
writable::Bool
@@ -14,22 +14,35 @@ type IOBuffer{T<:AbstractVector{UInt8}} <: IO
1414
ptr::Int # read (and maybe write) pointer
1515
mark::Int # reset mark location for ptr (or <0 for no mark)
1616

17-
IOBuffer(data::T,readable::Bool,writable::Bool,seekable::Bool,append::Bool,maxsize::Int) =
17+
AbstractIOBuffer(data::T,readable::Bool,writable::Bool,seekable::Bool,append::Bool,maxsize::Int) =
1818
new(data,readable,writable,seekable,append,length(data),maxsize,1,-1)
1919
end
20-
typealias SimpleIOBuffer IOBuffer{Vector{UInt8}}
21-
IOBuffer{T<:AbstractVector{UInt8}}(data::T, readable::Bool, writable::Bool, seekable::Bool, append::Bool, maxsize::Int) =
22-
IOBuffer{T}(data, readable, writable, seekable, append, maxsize)
20+
typealias IOBuffer AbstractIOBuffer{Vector{UInt8}}
2321

24-
function copy(b::IOBuffer)
22+
AbstractIOBuffer{T<:AbstractVector{UInt8}}(data::T, readable::Bool, writable::Bool, seekable::Bool, append::Bool, maxsize::Int) =
23+
AbstractIOBuffer{T}(data, readable, writable, seekable, append, maxsize)
24+
25+
# IOBuffers behave like Files. They are typically readable and writable. They are seekable. (They can be appendable).
26+
IOBuffer(data::AbstractVector{UInt8}, readable::Bool=true, writable::Bool=false, maxsize::Int=typemax(Int)) =
27+
AbstractIOBuffer(data, readable, writable, true, false, maxsize)
28+
IOBuffer(readable::Bool, writable::Bool) = IOBuffer(UInt8[], readable, writable)
29+
IOBuffer() = IOBuffer(true, true)
30+
IOBuffer(maxsize::Int) = (x=IOBuffer(Array(UInt8,maxsize), true, true, maxsize); x.size=0; x)
31+
32+
# PipeBuffers behave like Unix Pipes. They are typically readable and writable, they act appendable, and are not seekable.
33+
PipeBuffer(data::Vector{UInt8}=UInt8[], maxsize::Int=typemax(Int)) =
34+
AbstractIOBuffer(data,true,true,false,true,maxsize)
35+
PipeBuffer(maxsize::Int) = (x = PipeBuffer(Array(UInt8,maxsize),maxsize); x.size=0; x)
36+
37+
function copy(b::AbstractIOBuffer)
2538
ret = typeof(b)(b.writable ? copy(b.data) : b.data,
2639
b.readable, b.writable, b.seekable, b.append, b.maxsize)
2740
ret.size = b.size
2841
ret.ptr = b.ptr
2942
ret
3043
end
3144

32-
show(io::IO, b::IOBuffer) = print(io, "IOBuffer(data=UInt8[...], ",
45+
show(io::IO, b::AbstractIOBuffer) = print(io, "IOBuffer(data=UInt8[...], ",
3346
"readable=", b.readable, ", ",
3447
"writable=", b.writable, ", ",
3548
"seekable=", b.seekable, ", ",
@@ -39,23 +52,12 @@ show(io::IO, b::IOBuffer) = print(io, "IOBuffer(data=UInt8[...], ",
3952
"ptr=", b.ptr, ", ",
4053
"mark=", b.mark, ")")
4154

42-
# PipeBuffers behave like Unix Pipes. They are typically readable and writable, the act appendable, and not seekable.
43-
PipeBuffer(data::Vector{UInt8}=UInt8[], maxsize::Int=typemax(Int)) = IOBuffer(data,true,true,false,true,maxsize)
44-
PipeBuffer(maxsize::Int) = (x = PipeBuffer(Array(UInt8,maxsize),maxsize); x.size=0; x)
55+
is_maxsize_unlimited(io::AbstractIOBuffer) = (io.maxsize == typemax(Int))
56+
maxsize(io::AbstractIOBuffer) = io.maxsize
4557

46-
# IOBuffers behave like Files. They are typically readable and writable. They are seekable. (They can be appendable).
47-
IOBuffer(data::AbstractVector{UInt8}, readable::Bool=true, writable::Bool=false, maxsize::Int=typemax(Int)) =
48-
IOBuffer(data, readable, writable, true, false, maxsize)
49-
IOBuffer(readable::Bool, writable::Bool) = IOBuffer(UInt8[], readable, writable)
50-
IOBuffer() = IOBuffer(true, true)
51-
IOBuffer(maxsize::Int) = (x=IOBuffer(Array(UInt8,maxsize), true, true, maxsize); x.size=0; x)
52-
53-
is_maxsize_unlimited(io::IOBuffer) = (io.maxsize == typemax(Int))
54-
maxsize(io::IOBuffer) = io.maxsize
58+
read!(from::AbstractIOBuffer, a::Array) = read_sub(from, a, 1, length(a))
5559

56-
read!(from::IOBuffer, a::Array) = read_sub(from, a, 1, length(a))
57-
58-
function read_sub{T}(from::IOBuffer, a::AbstractArray{T}, offs, nel)
60+
function read_sub{T}(from::AbstractIOBuffer, a::AbstractArray{T}, offs, nel)
5961
from.readable || throw(ArgumentError("read failed, IOBuffer is not readable"))
6062
if offs+nel-1 > length(a) || offs < 1 || nel < 0
6163
throw(BoundsError())
@@ -81,7 +83,7 @@ function read_sub{T}(from::IOBuffer, a::AbstractArray{T}, offs, nel)
8183
return a
8284
end
8385

84-
function read(from::IOBuffer, ::Type{UInt8})
86+
function read(from::AbstractIOBuffer, ::Type{UInt8})
8587
from.readable || throw(ArgumentError("read failed, IOBuffer is not readable"))
8688
if from.ptr > from.size
8789
throw(EOFError())
@@ -91,51 +93,51 @@ function read(from::IOBuffer, ::Type{UInt8})
9193
return byte
9294
end
9395

94-
function peek(from::IOBuffer)
96+
function peek(from::AbstractIOBuffer)
9597
from.readable || throw(ArgumentError("read failed, IOBuffer is not readable"))
9698
if from.ptr > from.size
9799
throw(EOFError())
98100
end
99101
return from.data[from.ptr]
100102
end
101103

102-
read{T}(from::IOBuffer, ::Type{Ptr{T}}) = convert(Ptr{T}, read(from, UInt))
104+
read{T}(from::AbstractIOBuffer, ::Type{Ptr{T}}) = convert(Ptr{T}, read(from, UInt))
103105

104-
isreadable(io::IOBuffer) = io.readable
105-
iswritable(io::IOBuffer) = io.writable
106+
isreadable(io::AbstractIOBuffer) = io.readable
107+
iswritable(io::AbstractIOBuffer) = io.writable
106108

107-
# TODO: IOBuffer is not iterable, so doesn't really have a length.
109+
# TODO: AbstractIOBuffer is not iterable, so doesn't really have a length.
108110
# This should maybe be sizeof() instead.
109-
#length(io::IOBuffer) = (io.seekable ? io.size : nb_available(io))
110-
nb_available(io::IOBuffer) = io.size - io.ptr + 1
111-
position(io::IOBuffer) = io.ptr-1
111+
#length(io::AbstractIOBuffer) = (io.seekable ? io.size : nb_available(io))
112+
nb_available(io::AbstractIOBuffer) = io.size - io.ptr + 1
113+
position(io::AbstractIOBuffer) = io.ptr-1
112114

113-
function skip(io::IOBuffer, n::Integer)
115+
function skip(io::AbstractIOBuffer, n::Integer)
114116
seekto = io.ptr + n
115117
n < 0 && return seek(io, seekto-1) # Does error checking
116118
io.ptr = min(seekto, io.size+1)
117119
return io
118120
end
119121

120-
function seek(io::IOBuffer, n::Integer)
122+
function seek(io::AbstractIOBuffer, n::Integer)
121123
if !io.seekable
122124
ismarked(io) || throw(ArgumentError("seek failed, IOBuffer is not seekable and is not marked"))
123125
n == io.mark || throw(ArgumentError("seek failed, IOBuffer is not seekable and n != mark"))
124126
end
125127
# TODO: REPL.jl relies on the fact that this does not throw (by seeking past the beginning or end
126-
# of an IOBuffer), so that would need to be fixed in order to throw an error here
128+
# of an AbstractIOBuffer), so that would need to be fixed in order to throw an error here
127129
#(n < 0 || n > io.size) && throw(ArgumentError("Attempted to seek outside IOBuffer boundaries."))
128130
#io.ptr = n+1
129131
io.ptr = max(min(n+1, io.size+1), 1)
130132
return io
131133
end
132134

133-
function seekend(io::IOBuffer)
135+
function seekend(io::AbstractIOBuffer)
134136
io.ptr = io.size+1
135137
return io
136138
end
137139

138-
function truncate(io::IOBuffer, n::Integer)
140+
function truncate(io::AbstractIOBuffer, n::Integer)
139141
io.writable || throw(ArgumentError("truncate failed, IOBuffer is not writeable"))
140142
io.seekable || throw(ArgumentError("truncate failed, IOBuffer is not seekable"))
141143
n < 0 && throw(ArgumentError("truncate failed, n bytes must be ≥ 0, got $n"))
@@ -150,7 +152,7 @@ function truncate(io::IOBuffer, n::Integer)
150152
return io
151153
end
152154

153-
function compact(io::IOBuffer)
155+
function compact(io::AbstractIOBuffer)
154156
io.writable || throw(ArgumentError("compact failed, IOBuffer is not writeable"))
155157
io.seekable && throw(ArgumentError("compact failed, IOBuffer is seekable"))
156158
local ptr::Int, bytes_to_move::Int
@@ -169,7 +171,7 @@ function compact(io::IOBuffer)
169171
return io
170172
end
171173

172-
function ensureroom(io::IOBuffer, nshort::Int)
174+
function ensureroom(io::AbstractIOBuffer, nshort::Int)
173175
io.writable || throw(ArgumentError("ensureroom failed, IOBuffer is not writeable"))
174176
if !io.seekable
175177
nshort >= 0 || throw(ArgumentError("ensureroom failed, requested number of bytes must be ≥ 0, got $nshort"))
@@ -194,9 +196,9 @@ function ensureroom(io::IOBuffer, nshort::Int)
194196
return io
195197
end
196198

197-
eof(io::IOBuffer) = (io.ptr-1 == io.size)
199+
eof(io::AbstractIOBuffer) = (io.ptr-1 == io.size)
198200

199-
function close{T}(io::IOBuffer{T})
201+
function close{T}(io::AbstractIOBuffer{T})
200202
io.readable = false
201203
io.writable = false
202204
io.seekable = false
@@ -212,16 +214,16 @@ function close{T}(io::IOBuffer{T})
212214
nothing
213215
end
214216

215-
isopen(io::IOBuffer) = io.readable || io.writable || io.seekable || nb_available(io) > 0
217+
isopen(io::AbstractIOBuffer) = io.readable || io.writable || io.seekable || nb_available(io) > 0
216218

217-
function bytestring(io::IOBuffer)
219+
function bytestring(io::AbstractIOBuffer)
218220
io.readable || throw(ArgumentError("bytestring read failed, IOBuffer is not readable"))
219221
io.seekable || throw(ArgumentError("bytestring read failed, IOBuffer is not seekable"))
220222
b = copy!(Array(UInt8, io.size), 1, io.data, 1, io.size)
221223
return isvalid(ASCIIString, b) ? ASCIIString(b) : UTF8String(b)
222224
end
223225

224-
function takebuf_array(io::IOBuffer)
226+
function takebuf_array(io::AbstractIOBuffer)
225227
ismarked(io) && unmark(io)
226228
if io.seekable
227229
nbytes = io.size
@@ -236,7 +238,7 @@ function takebuf_array(io::IOBuffer)
236238
end
237239
data
238240
end
239-
function takebuf_array(io::SimpleIOBuffer)
241+
function takebuf_array(io::IOBuffer)
240242
ismarked(io) && unmark(io)
241243
if io.seekable
242244
data = io.data
@@ -258,12 +260,12 @@ function takebuf_array(io::SimpleIOBuffer)
258260
end
259261
data
260262
end
261-
function takebuf_string(io::IOBuffer)
263+
function takebuf_string(io::AbstractIOBuffer)
262264
b = takebuf_array(io)
263265
return isvalid(ASCIIString, b) ? ASCIIString(b) : UTF8String(b)
264266
end
265267

266-
function write(to::IOBuffer, from::IOBuffer)
268+
function write(to::AbstractIOBuffer, from::AbstractIOBuffer)
267269
if to === from
268270
from.ptr = from.size + 1
269271
return 0
@@ -273,8 +275,8 @@ function write(to::IOBuffer, from::IOBuffer)
273275
written
274276
end
275277

276-
write(to::IOBuffer, p::Ptr, nb::Integer) = write(to, p, Int(nb))
277-
function write(to::IOBuffer, p::Ptr, nb::Int)
278+
write(to::AbstractIOBuffer, p::Ptr, nb::Integer) = write(to, p, Int(nb))
279+
function write(to::AbstractIOBuffer, p::Ptr, nb::Int)
278280
ensureroom(to, nb)
279281
ptr = (to.append ? to.size+1 : to.ptr)
280282
written = min(nb, length(to.data) - ptr + 1)
@@ -287,7 +289,7 @@ function write(to::IOBuffer, p::Ptr, nb::Int)
287289
written
288290
end
289291

290-
function write_sub{T}(to::IOBuffer, a::AbstractArray{T}, offs, nel)
292+
function write_sub{T}(to::AbstractIOBuffer, a::AbstractArray{T}, offs, nel)
291293
if offs+nel-1 > length(a) || offs < 1 || nel < 0
292294
throw(BoundsError())
293295
end
@@ -313,9 +315,9 @@ function write_sub{T}(to::IOBuffer, a::AbstractArray{T}, offs, nel)
313315
written
314316
end
315317

316-
write(to::IOBuffer, a::Array) = write_sub(to, a, 1, length(a))
318+
write(to::AbstractIOBuffer, a::Array) = write_sub(to, a, 1, length(a))
317319

318-
function write(to::IOBuffer, a::UInt8)
320+
function write(to::AbstractIOBuffer, a::UInt8)
319321
ensureroom(to, 1)
320322
ptr = (to.append ? to.size+1 : to.ptr)
321323
if ptr > to.maxsize
@@ -328,26 +330,26 @@ function write(to::IOBuffer, a::UInt8)
328330
sizeof(UInt8)
329331
end
330332

331-
write(to::IOBuffer, p::Ptr) = write(to, convert(UInt, p))
333+
write(to::AbstractIOBuffer, p::Ptr) = write(to, convert(UInt, p))
332334

333-
function readbytes!(io::IOBuffer, b::Array{UInt8}, nb=length(b))
335+
function readbytes!(io::AbstractIOBuffer, b::Array{UInt8}, nb=length(b))
334336
nr = min(nb, nb_available(io))
335337
if length(b) < nr
336338
resize!(b, nr)
337339
end
338340
read_sub(io, b, 1, nr)
339341
return nr
340342
end
341-
readbytes(io::IOBuffer) = read!(io, Array(UInt8, nb_available(io)))
342-
readbytes(io::IOBuffer, nb) = read!(io, Array(UInt8, min(nb, nb_available(io))))
343+
readbytes(io::AbstractIOBuffer) = read!(io, Array(UInt8, nb_available(io)))
344+
readbytes(io::AbstractIOBuffer, nb) = read!(io, Array(UInt8, min(nb, nb_available(io))))
343345

344-
function search(buf::SimpleIOBuffer, delim::UInt8)
346+
function search(buf::IOBuffer, delim::UInt8)
345347
p = pointer(buf.data, buf.ptr)
346348
q = ccall(:memchr,Ptr{UInt8},(Ptr{UInt8},Int32,Csize_t),p,delim,nb_available(buf))
347349
nb = (q == C_NULL ? 0 : q-p+1)
348350
end
349351

350-
function search(buf::IOBuffer, delim::UInt8)
352+
function search(buf::AbstractIOBuffer, delim::UInt8)
351353
data = buf.data
352354
for i = buf.ptr : buf.size
353355
@inbounds b = data[i]
@@ -358,7 +360,7 @@ function search(buf::IOBuffer, delim::UInt8)
358360
return 0
359361
end
360362

361-
function readuntil(io::IOBuffer, delim::UInt8)
363+
function readuntil(io::AbstractIOBuffer, delim::UInt8)
362364
lb = 70
363365
A = Array(UInt8, lb)
364366
n = 0

base/markdown/Julia/interp.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: http://julialang.org/license
22

3-
function Base.parse(stream::IOBuffer; greedy::Bool = true, raise::Bool = true)
3+
function Base.parse(stream::IO; greedy::Bool = true, raise::Bool = true)
44
pos = position(stream)
55
ex, Δ = Base.parse(readall(stream), 1, greedy = greedy, raise = raise)
66
seek(stream, pos + Δ - 1)

base/socket.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ type TCPSocket <: Socket
254254
handle::Ptr{Void}
255255
status::Int
256256
line_buffered::Bool
257-
buffer::SimpleIOBuffer
257+
buffer::IOBuffer
258258
readcb::Callback
259259
readnotify::Condition
260260
ccb::Callback
261261
connectnotify::Condition
262262
closecb::Callback
263263
closenotify::Condition
264-
sendbuf::Nullable{SimpleIOBuffer}
264+
sendbuf::Nullable{IOBuffer}
265265
lock::ReentrantLock
266266

267267
TCPSocket(handle) = new(

0 commit comments

Comments
 (0)