Skip to content

Commit

Permalink
Fix for removal of limit_output
Browse files Browse the repository at this point in the history
This does something useful only for multiple versions of julia-0.5, since `limit_output(io)` was introduced (+1936) and then removed (+4305). Prior to that, you couldn't call `limit_output` on an `io` object.
For earlier julia versions, this just evaluates as `false`.

For, e.g., BenchmarkTools, it seems important to be able to support a range of julia-0.5 versions.
  • Loading branch information
timholy committed May 26, 2016
1 parent b2bb3ab commit 0a3c29c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,26 @@ function rewrite_pairs_to_tuples!(expr::Expr)
return expr
end

# rewrites accesses to IOContext dicts
function rewrite_iocontext!(expr::Expr)
if expr.head == :call && expr.args[1] == :get
key = expr.args[3]
if (((isa(key, QuoteNode) && key.value == :limit) ||
(isa(key, Expr) && key.head == :quote && key.args[1] == :limit))
&& expr.args[4] == false)
if VERSION >= v"0.5.0-dev+1936" && VERSION < v"0.5.0-dev+4305"
expr.args[1] = :(Base.limit_output)
deleteat!(expr.args, 3:4)
elseif VERSION < v"0.5.0-dev+1936"
expr.head = :quote
expr.args[1] = false
deleteat!(expr.args, 3:4)
end
end
end
expr
end

if VERSION < v"0.4.0-dev+707"
macro inline(ex)
esc(ex)
Expand Down Expand Up @@ -515,6 +535,9 @@ function _compat(ex::Expr)
elseif VERSION < v"0.4.0-dev+1246" && f == :String
ex = Expr(:call, :bytestring, ex.args[2:end]...)
end
if VERSION < v"0.5.0-dev+4305"
rewrite_iocontext!(ex)
end
elseif ex.head === :curly
f = ex.args[1]
if VERSION < v"0.4.0-dev+4319" && f === :Tuple
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1183,3 +1183,6 @@ if VERSION < v"0.5.0-dev+4267"
else
@test Compat.KERNEL == Sys.KERNEL
end

io = IOBuffer()
@test @compat(get(io, :limit, false)) == false

0 comments on commit 0a3c29c

Please sign in to comment.