Skip to content

Commit

Permalink
Merge pull request #11554 from JuliaLang/jn/iobuffer_parameterized
Browse files Browse the repository at this point in the history
allow IOBuffer to be parameterized, and remove the need for explicit start/stop_reading in user code
  • Loading branch information
vtjnash committed Jun 8, 2015
2 parents 0a2dc35 + 38888d5 commit 22b5c9d
Show file tree
Hide file tree
Showing 17 changed files with 333 additions and 242 deletions.
4 changes: 0 additions & 4 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,6 @@ function prompt!(term, prompt, s = init_state(term, prompt))
raw!(term, true)
enable_bracketed_paste(term)
try
Base.start_reading(term)
activate(prompt, s, term)
while true
map = keymap(s, prompt)
Expand All @@ -1585,14 +1584,11 @@ function prompt!(term, prompt, s = init_state(term, prompt))
state = :done
end
if state == :abort
Base.stop_reading(term)
return buffer(s), false, false
elseif state == :done
Base.stop_reading(term)
return buffer(s), true, false
elseif state == :suspend
@unix_only begin
Base.stop_reading(term)
return buffer(s), true, true
end
else
Expand Down
2 changes: 0 additions & 2 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,9 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
LineEdit.commit_line(s)
# This is slightly ugly but ok for now
terminal = LineEdit.terminal(s)
Base.stop_reading(terminal)
raw!(terminal, false) && disable_bracketed_paste(terminal)
LineEdit.mode(s).on_done(s, LineEdit.buffer(s), true)
raw!(terminal, true) && enable_bracketed_paste(terminal)
Base.start_reading(terminal)
else
break
end
Expand Down
23 changes: 0 additions & 23 deletions base/build.h

This file was deleted.

8 changes: 0 additions & 8 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ function eval_user_input(ast::ANY, show_value)
isa(STDIN,TTY) && println()
end

function repl_callback(ast::ANY, show_value)
global _repl_enough_stdin = true
Base.stop_reading(STDIN)
put!(repl_channel, (ast, show_value))
end

_repl_start = Condition()

syntax_deprecation_warnings(warn::Bool) =
ccall(:jl_parse_depwarn, Cint, (Cint,), warn)!=0

Expand Down
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::AbstractIOBuffer, p::Ptr, nb::Integer) = read!(from, p, Int(nb))
function read!(from::AbstractIOBuffer, 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 22b5c9d

Please sign in to comment.