Skip to content

Commit

Permalink
fix JuliaLang#27546 by using jl_set_global instead of eval to set Mai…
Browse files Browse the repository at this point in the history
…n.ans (JuliaLang#27562)
  • Loading branch information
jrevels committed Jun 18, 2018
1 parent 404e0fe commit 7744985
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function eval_user_input(@nospecialize(ast), show_value::Bool)
else
ast = Meta.lower(Main, ast)
value = Core.eval(Main, ast)
Core.eval(Main, Expr(:body, Expr(:(=), :ans, QuoteNode(value)), Expr(:return, nothing)))
ccall(:jl_set_global, Cvoid, (Any, Any, Any), Main, :ans, value)
if !(value === nothing) && show_value
if have_color
print(answer_color())
Expand Down
2 changes: 1 addition & 1 deletion stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function eval_user_input(@nospecialize(ast), backend::REPLBackend)
value = Core.eval(Main, ast)
backend.in_eval = false
# note: value wrapped carefully here to ensure it doesn't get passed through expand
Core.eval(Main, Expr(:body, Expr(:(=), :ans, QuoteNode(value)), Expr(:return, nothing)))
ccall(:jl_set_global, Cvoid, (Any, Any, Any), Main, :ans, value)
put!(backend.response_channel, (value, nothing))
end
break
Expand Down
16 changes: 16 additions & 0 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -961,3 +961,19 @@ for (line, expr) in Pair[
buf = IOBuffer()
@test Base.eval(REPL._helpmode(buf, line)) isa Union{Markdown.MD,Nothing}
end

# PR #27562
fake_repl() do stdin_write, stdout_read, repl
repltask = @async begin
REPL.run_repl(repl)
end
write(stdin_write, "Expr(:call, GlobalRef(Base.Math, :float), Core.SlotNumber(1))\n")
readline(stdout_read)
@test readline(stdout_read) == "\e[0m:((Base.Math.float)(_1))"
write(stdin_write, "ans\n")
readline(stdout_read)
readline(stdout_read)
@test readline(stdout_read) == "\e[0m:((Base.Math.float)(_1))"
write(stdin_write, '\x04')
Base._wait(repltask)
end

0 comments on commit 7744985

Please sign in to comment.