Skip to content

Commit 59a67a4

Browse files
stevengjararslan
authored andcommitted
fix cfunction escaping bug (#566)
1 parent e991ead commit 59a67a4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Compat.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ end
19141914
# 0.7.0-DEV.4762
19151915
@static if !isdefined(Base, Symbol("@cfunction"))
19161916
macro cfunction(f, rt, tup)
1917-
:(Base.cfunction($f, $rt, Tuple{$tup...}))
1917+
:(Base.cfunction($(esc(f)), $(esc(rt)), Tuple{$(esc(tup))...}))
19181918
end
19191919
export @cfunction
19201920
end

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,14 @@ let ptr = @cfunction(+, Int, (Int, Int))
17491749
@test ptr != C_NULL
17501750
@test ccall(ptr, Int, (Int, Int), 2, 3) == 5
17511751
end
1752+
# issue #565
1753+
issue565(x) = x + 1
1754+
const Issue565 = Int
1755+
let bar() = @cfunction(issue565, Issue565, (Issue565,)), ptr = bar()
1756+
@test ptr isa Ptr{Cvoid}
1757+
@test ptr != C_NULL
1758+
@test ccall(ptr, Int, (Int,), 2) === 3
1759+
end
17521760

17531761
# 0.7.0-DEV.5278
17541762
@test something(nothing, 1) === 1

0 commit comments

Comments
 (0)