Skip to content

Commit 2dd8469

Browse files
committed
move code that converts input code to a String into its own function
1 parent 46723f0 commit 2dd8469

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/hooks.jl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,22 @@ end
137137
const _debug_log = Ref{Union{Nothing,IO}}(nothing)
138138

139139
function core_parser_hook(code, filename::String, lineno::Int, offset::Int, options::Symbol)
140+
# TODO: Check that we do all this input wrangling without copying the
141+
# code buffer
142+
if code isa Core.SimpleVector
143+
# The C entry points will pass us this form.
144+
(ptr,len) = code
145+
code = String(unsafe_wrap(Array, ptr, len))
146+
elseif !(code isa String || code isa SubString || code isa Vector{UInt8})
147+
# For non-Base string types, convert to UTF-8 encoding, using an
148+
# invokelatest to avoid world age issues.
149+
code = Base.invokelatest(String, code)::String
150+
end
151+
core_parser_hook(code, filename, lineno, offset, options)
152+
end
153+
154+
function core_parser_hook(code::String, filename::String, lineno::Int, offset::Int, options::Symbol)::Core.SimpleVector
140155
try
141-
# TODO: Check that we do all this input wrangling without copying the
142-
# code buffer
143-
if code isa Core.SimpleVector
144-
# The C entry points will pass us this form.
145-
(ptr,len) = code
146-
code = String(unsafe_wrap(Array, ptr, len))
147-
elseif !(code isa String || code isa SubString || code isa Vector{UInt8})
148-
# For non-Base string types, convert to UTF-8 encoding, using an
149-
# invokelatest to avoid world age issues.
150-
code = Base.invokelatest(String, code)
151-
end
152156
if !isnothing(_debug_log[])
153157
print(_debug_log[], """
154158
#-#-#-------------------------------
@@ -213,7 +217,7 @@ function core_parser_hook(code, filename::String, lineno::Int, offset::Int, opti
213217
# * appends the error message
214218
topex = Expr(tree)
215219
@assert topex.head == :toplevel
216-
i = findfirst(_has_nested_error, topex.args)
220+
i = findfirst(_has_nested_error, topex.args)::Int
217221
if i > 1 && topex.args[i-1] isa LineNumberNode
218222
i -= 1
219223
end
@@ -399,4 +403,3 @@ end
399403
# Convenience functions to mirror `JuliaSyntax.parsestmt(Expr, ...)` in simple cases.
400404
fl_parse(::Type{Expr}, args...; kws...) = fl_parse(args...; kws...)
401405
fl_parseall(::Type{Expr}, args...; kws...) = fl_parseall(args...; kws...)
402-

src/precompile.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ let filename = joinpath(@__DIR__, "literal_parsing.jl")
66
if _has_v1_6_hooks
77
enable_in_core!()
88
Meta.parse("1 + 2")
9+
Meta.parse(SubString("1+2"))
910
enable_in_core!(false)
1011
end
1112
end

0 commit comments

Comments
 (0)