Skip to content

Commit

Permalink
allow IOBuffer to be created with any subtype of AbstractVector{UInt8…
Browse files Browse the repository at this point in the history
…} as the underlying buffer (ref #9888)
  • Loading branch information
vtjnash committed Jun 4, 2015
1 parent c09aebf commit 4af7c6f
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 135 deletions.
10 changes: 5 additions & 5 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using ..Terminals
import ..Terminals: raw!, width, height, cmove, getX,
getY, clear_line, beep

import Base: ensureroom, peek, show, AnyDict
import Base: ensureroom, peek, show, AnyDict, SimpleIOBuffer

abstract TextInterface
abstract ModeState
Expand Down Expand Up @@ -56,7 +56,7 @@ end
type PromptState <: ModeState
terminal::TextTerminal
p::Prompt
input_buffer::IOBuffer
input_buffer::SimpleIOBuffer
ias::InputAreaState
indent::Int
end
Expand Down Expand Up @@ -996,8 +996,8 @@ type SearchState <: ModeState
histprompt
#rsearch (true) or ssearch (false)
backward::Bool
query_buffer::IOBuffer
response_buffer::IOBuffer
query_buffer::SimpleIOBuffer
response_buffer::SimpleIOBuffer
ias::InputAreaState
#The prompt whose input will be replaced by the matched history
parent
Expand Down Expand Up @@ -1049,7 +1049,7 @@ type PrefixSearchState <: ModeState
terminal
histprompt
prefix::ByteString
response_buffer::IOBuffer
response_buffer::SimpleIOBuffer
ias::InputAreaState
indent::Int
#The prompt whose input will be replaced by the matched history
Expand Down
5 changes: 3 additions & 2 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import Base:
Display,
display,
writemime,
AnyDict
AnyDict,
SimpleIOBuffer

import ..LineEdit:
CompletionProvider,
Expand Down Expand Up @@ -298,7 +299,7 @@ type REPLHistoryProvider <: HistoryProvider
history_file
cur_idx::Int
last_idx::Int
last_buffer::IOBuffer
last_buffer::SimpleIOBuffer
last_mode
mode_mapping
modes::Array{Symbol,1}
Expand Down
23 changes: 0 additions & 23 deletions base/build.h

This file was deleted.

16 changes: 16 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,19 @@ function _unsafe_setindex!(l::LinearIndexing, A::AbstractArray, x, J::Union(Real
depwarn("multidimensional indexed assignment with multidimensional arrays is deprecated, use vec to convert indices to vectors", :_unsafe_setindex!)
_unsafe_setindex!(l, A, x, _ensure_vectors(J...)...)
end

# 11554

read!(from::IOBuffer, p::Ptr, nb::Integer) = read!(from, p, Int(nb))
function read!(from::IOBuffer, p::Ptr, nb::Int)
depwarn("read!(::IOBuffer, ::Ptr) is unsafe and therefore deprecated", :read!)
from.readable || throw(ArgumentError("read failed, IOBuffer is not readable"))
avail = nb_available(from)
adv = min(avail, nb)
ccall(:memcpy, Ptr{Void}, (Ptr{Void}, Ptr{Void}, UInt), p, pointer(from.data, from.ptr), adv)
from.ptr += adv
if nb > avail
throw(EOFError())
end
p
end
43 changes: 21 additions & 22 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ write(io::IO, xs...) = for x in xs write(io, x) end
if ENDIAN_BOM == 0x01020304
function write(s::IO, x::Integer)
sz = sizeof(x)
local written::Int = 0
for n = sz:-1:1
write(s, (x>>>((n-1)<<3))%UInt8)
written += write(s, (x>>>((n-1)<<3))%UInt8)
end
sz
return written
end
else
function write(s::IO, x::Integer)
sz = sizeof(x)
local written::Int = 0
for n = 1:sz
write(s, (x>>>((n-1)<<3))%UInt8)
written += write(s, (x>>>((n-1)<<3))%UInt8)
end
sz
return written
end
end

Expand All @@ -62,44 +64,41 @@ function write(s::IO, a::AbstractArray)
for i in eachindex(a)
nb += write(s, a[i])
end
nb
return nb
end

function write(s::IO, ch::Char)
c = reinterpret(UInt32, ch)
if c < 0x80
write(s, c%UInt8)
return 1
return write(s, c%UInt8)
elseif c < 0x800
write(s, (( c >> 6 ) | 0xC0)%UInt8)
write(s, (( c & 0x3F ) | 0x80)%UInt8)
return 2
return (write(s, (( c >> 6 ) | 0xC0)%UInt8)) +
(write(s, (( c & 0x3F ) | 0x80)%UInt8))
elseif c < 0x10000
write(s, (( c >> 12 ) | 0xE0)%UInt8)
write(s, (((c >> 6) & 0x3F ) | 0x80)%UInt8)
write(s, (( c & 0x3F ) | 0x80)%UInt8)
return 3
return (write(s, (( c >> 12 ) | 0xE0)%UInt8)) +
(write(s, (((c >> 6) & 0x3F ) | 0x80)%UInt8)) +
(write(s, (( c & 0x3F ) | 0x80)%UInt8))
elseif c < 0x110000
write(s, (( c >> 18 ) | 0xF0)%UInt8)
write(s, (((c >> 12) & 0x3F ) | 0x80)%UInt8)
write(s, (((c >> 6) & 0x3F ) | 0x80)%UInt8)
write(s, (( c & 0x3F ) | 0x80)%UInt8)
return 4
return (write(s, (( c >> 18 ) | 0xF0)%UInt8)) +
(write(s, (((c >> 12) & 0x3F ) | 0x80)%UInt8)) +
(write(s, (((c >> 6) & 0x3F ) | 0x80)%UInt8)) +
(write(s, (( c & 0x3F ) | 0x80)%UInt8))
else
return write(s, '\ufffd')
end
end

function write(s::IO, p::Ptr, n::Integer)
local written::Int = 0
for i=1:n
write(s, unsafe_load(p, i))
written += write(s, unsafe_load(p, i))
end
n
return written
end

function write(io::IO, s::Symbol)
pname = unsafe_convert(Ptr{UInt8}, s)
write(io, pname, Int(ccall(:strlen, Csize_t, (Ptr{UInt8},), pname)))
return write(io, pname, Int(ccall(:strlen, Csize_t, (Ptr{UInt8},), pname)))
end

# all subtypes should implement this
Expand Down
Loading

0 comments on commit 4af7c6f

Please sign in to comment.