Skip to content

Commit 68fa8be

Browse files
authored
NFC: harden some internal ccalls (#595)
* NFC: harden some internal ccalls * jl_method_def lies about only accepting `CodeInfo`
1 parent ccc1c95 commit 68fa8be

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/interpret.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@ function evaluate_methoddef(frame, node)
295295
end
296296
length(node.args) == 1 && return f
297297
sig = @lookup(frame, node.args[2])::SimpleVector
298-
body = @lookup(frame, node.args[3])
298+
body = @lookup(frame, node.args[3])::Union{CodeInfo, Expr}
299299
# branching on https://github.com/JuliaLang/julia/pull/41137
300300
@static if isdefined(Core.Compiler, :OverlayMethodTable)
301-
ccall(:jl_method_def, Cvoid, (Any, Ptr{Cvoid}, Any, Any), sig, C_NULL, body, moduleof(frame))
301+
ccall(:jl_method_def, Cvoid, (Any, Ptr{Cvoid}, Any, Any), sig, C_NULL, body, moduleof(frame)::Module)
302302
else
303-
ccall(:jl_method_def, Cvoid, (Any, Any, Any), sig, body, moduleof(frame))
303+
ccall(:jl_method_def, Cvoid, (Any, Any, Any), sig, body, moduleof(frame)::Module)
304304
end
305305
return f
306306
end
@@ -318,8 +318,8 @@ function structname(frame, node)
318318
end
319319

320320
function set_structtype_const(mod::Module, name::Symbol)
321-
dt = Base.unwrap_unionall(getfield(mod, name))
322-
ccall(:jl_set_const, Cvoid, (Any, Any, Any), mod, dt.name.name, dt.name.wrapper)
321+
dt = Base.unwrap_unionall(getfield(mod, name))::DataType
322+
ccall(:jl_set_const, Cvoid, (Any, Any, Any), mod, dt.name.name::Symbol, dt.name.wrapper)
323323
end
324324

325325
function inplace_lookup!(ex, i, frame)
@@ -378,12 +378,14 @@ function eval_rhs(@nospecialize(recurse), frame, node::Expr)
378378
args = let mod=mod
379379
Any[@lookup(mod, frame, arg) for arg in node.args]
380380
end
381-
T = popfirst!(args)
381+
T = popfirst!(args)::DataType
382382
rhs = ccall(:jl_new_structv, Any, (Any, Ptr{Any}, UInt32), T, args, length(args))
383383
return rhs
384384
elseif head === :splatnew # Julia 1.2+
385385
mod = moduleof(frame)
386-
rhs = ccall(:jl_new_structt, Any, (Any, Any), @lookup(mod, frame, node.args[1]), @lookup(mod, frame, node.args[2]))
386+
T = @lookup(mod, frame, node.args[1])::DataType
387+
args = @lookup(mod, frame, node.args[2])::Tuple
388+
rhs = ccall(:jl_new_structt, Any, (Any, Any), T, args)
387389
return rhs
388390
elseif head === :isdefined
389391
return check_isdefined(frame, node.args[1])

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ function whichtt(@nospecialize(tt))
4040
match === nothing && return nothing
4141
return match.method
4242
else
43-
m = ccall(:jl_gf_invoke_lookup, Any, (Any, UInt), tt, get_world_counter())
43+
m = ccall(:jl_gf_invoke_lookup, Any, (Any, Csize_t), tt, get_world_counter())
4444
m === nothing && return nothing
4545
isa(m, Method) && return m
4646
return m.func::Method
4747
end
4848
end
4949

50-
instantiate_type_in_env(arg, spsig, spvals) =
50+
instantiate_type_in_env(arg, spsig::UnionAll, spvals::Vector{Any}) =
5151
ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), arg, spsig, spvals)
5252

5353
function sparam_syms(meth::Method)

0 commit comments

Comments
 (0)