Skip to content

Commit ceee9c0

Browse files
authored
fix for varargs in ccall (#240)
1 parent 2824793 commit ceee9c0

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ CodeTracking = "0.3.2, 0.4, 0.5"
1414
[extras]
1515
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1616
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
17-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1817
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
1918
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
19+
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
20+
2021

2122
[targets]
22-
test = ["Test", "Distributed", "Random", "Dates", "SHA"]
23+
test = ["Test", "Distributed", "Dates", "SHA", "Mmap"]

src/optimize.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ end
232232

233233
function parametric_type_to_expr(t::Type)
234234
t isa Core.TypeofBottom && return t
235+
t isa UnionAll && (t = t.body)
236+
if t <: Vararg
237+
return Expr(:(...), t.parameters[1])
238+
end
235239
return t.hasfreetypevars ? Expr(:curly, t.name.name, ((tv-> tv isa TypeVar ? tv.name : tv).(t.parameters))...) : t
236240
end
237241

test/interpret.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using JuliaInterpreter
22
using JuliaInterpreter: enter_call_expr
33
using Test, InteractiveUtils, CodeTracking
4+
using Mmap
45

56
module Isolated end
67

@@ -482,4 +483,20 @@ compiled_calls = names(JuliaInterpreter.CompiledCalls; all=true)
482483

483484
# https://github.com/JuliaDebug/JuliaInterpreter.jl/issues/194
484485
f() = Meta.lower(Main, Meta.parse("(a=1,0)"))
485-
@test @interpret f() == f()
486+
@test @interpret f() == f()
487+
488+
# Test for vararg ccalls (used by mmap)
489+
function f_mmap()
490+
tmp = tempname()
491+
local b_mmap
492+
try
493+
x = rand(10)
494+
write(tmp, x)
495+
b_mmap = Mmap.mmap(tmp, Vector{Float64})
496+
@test b_mmap == x
497+
finally
498+
finalize(b_mmap)
499+
rm(tmp)
500+
end
501+
end
502+
@interpret f_mmap()

0 commit comments

Comments
 (0)