Skip to content

Commit 19bc06a

Browse files
authored
add some needed local declarations to macros (#37219)
to avoid leaking globals
1 parent 834ab52 commit 19bc06a

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

base/c.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ function ccall_macro_lower(convention, func, rettype, types, args, nreq)
643643
sym = Symbol(string("arg", i, "root"))
644644
sym2 = Symbol(string("arg", i, ))
645645
earg, etype = esc(arg), esc(type)
646-
push!(lowering, :($sym = Base.cconvert($etype, $earg)))
647-
push!(lowering, :($sym2 = Base.unsafe_convert($etype, $sym)))
646+
push!(lowering, :(local $sym = $(GlobalRef(Base, :cconvert))($etype, $earg)))
647+
push!(lowering, :(local $sym2 = $(GlobalRef(Base, :unsafe_convert))($etype, $sym)))
648648
push!(realargs, sym2)
649649
push!(gcroots, sym)
650650
end

base/logging.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ default_group(file) = Symbol(splitext(basename(file))[1])
278278
function logmsg_code(_module, file, line, level, message, exs...)
279279
log_data = process_logmsg_exs(_module, file, line, level, message, exs...)
280280
quote
281+
let
281282
level = $level
282283
std_level = convert(LogLevel, level)
283284
if std_level >= getindex(_min_enabled_level)
@@ -305,6 +306,7 @@ function logmsg_code(_module, file, line, level, message, exs...)
305306
end
306307
nothing
307308
end
309+
end
308310
end
309311

310312
function process_logmsg_exs(_orig_module, _file, _line, level, message, exs...)

base/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ macro show(exs...)
888888
blk = Expr(:block)
889889
for ex in exs
890890
push!(blk.args, :(println($(sprint(show_unquoted,ex)*" = "),
891-
repr(begin value=$(esc(ex)) end))))
891+
repr(begin local value = $(esc(ex)) end))))
892892
end
893893
isempty(exs) || push!(blk.args, :value)
894894
return blk

stdlib/InteractiveUtils/src/macros.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ end
219219
macro code_typed(ex0...)
220220
thecall = gen_call_with_extracted_types_and_kwargs(__module__, :code_typed, ex0)
221221
quote
222-
results = $thecall
222+
local results = $thecall
223223
length(results) == 1 ? results[1] : results
224224
end
225225
end
226226

227227
macro code_lowered(ex0...)
228228
thecall = gen_call_with_extracted_types_and_kwargs(__module__, :code_lowered, ex0)
229229
quote
230-
results = $thecall
230+
local results = $thecall
231231
length(results) == 1 ? results[1] : results
232232
end
233233
end

test/ccall.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,12 +1605,12 @@ end
16051605
)::Cstring))...)
16061606
@test call == Base.remove_linenums!(
16071607
quote
1608-
arg1root = Base.cconvert($(Expr(:escape, :Cstring)), $(Expr(:escape, :str)))
1609-
arg1 = Base.unsafe_convert($(Expr(:escape, :Cstring)), arg1root)
1610-
arg2root = Base.cconvert($(Expr(:escape, :Cint)), $(Expr(:escape, :num1)))
1611-
arg2 = Base.unsafe_convert($(Expr(:escape, :Cint)), arg2root)
1612-
arg3root = Base.cconvert($(Expr(:escape, :Cint)), $(Expr(:escape, :num2)))
1613-
arg3 = Base.unsafe_convert($(Expr(:escape, :Cint)), arg3root)
1608+
local arg1root = $(GlobalRef(Base, :cconvert))($(Expr(:escape, :Cstring)), $(Expr(:escape, :str)))
1609+
local arg1 = $(GlobalRef(Base, :unsafe_convert))($(Expr(:escape, :Cstring)), arg1root)
1610+
local arg2root = $(GlobalRef(Base, :cconvert))($(Expr(:escape, :Cint)), $(Expr(:escape, :num1)))
1611+
local arg2 = $(GlobalRef(Base, :unsafe_convert))($(Expr(:escape, :Cint)), arg2root)
1612+
local arg3root = $(GlobalRef(Base, :cconvert))($(Expr(:escape, :Cint)), $(Expr(:escape, :num2)))
1613+
local arg3 = $(GlobalRef(Base, :unsafe_convert))($(Expr(:escape, :Cint)), arg3root)
16141614
$(Expr(:foreigncall,
16151615
:($(Expr(:escape, :((:func, libstring))))),
16161616
:($(Expr(:escape, :Cstring))),
@@ -1631,8 +1631,8 @@ end
16311631
throw(ArgumentError("interpolated function `$(name)` was not a Ptr{Cvoid}, but $(typeof(func))"))
16321632
end
16331633
end
1634-
arg1root = Base.cconvert($(Expr(:escape, :Cstring)), $(Expr(:escape, "bar")))
1635-
arg1 = Base.unsafe_convert($(Expr(:escape, :Cstring)), arg1root)
1634+
local arg1root = $(GlobalRef(Base, :cconvert))($(Expr(:escape, :Cstring)), $(Expr(:escape, "bar")))
1635+
local arg1 = $(GlobalRef(Base, :unsafe_convert))($(Expr(:escape, :Cstring)), arg1root)
16361636
$(Expr(:foreigncall, :func, :($(Expr(:escape, :Cvoid))), :($(Expr(:escape, :(($(Expr(:core, :svec)))(Cstring))))), 0, :(:ccall), :arg1, :arg1root))
16371637
end)
16381638

0 commit comments

Comments
 (0)