From 59a67a46897f6ed8a3b8abf688985284623181f0 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Wed, 6 Jun 2018 22:13:28 +0200 Subject: [PATCH] fix cfunction escaping bug (#566) --- src/Compat.jl | 2 +- test/runtests.jl | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Compat.jl b/src/Compat.jl index 268b347f7..22ffca76f 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1914,7 +1914,7 @@ end # 0.7.0-DEV.4762 @static if !isdefined(Base, Symbol("@cfunction")) macro cfunction(f, rt, tup) - :(Base.cfunction($f, $rt, Tuple{$tup...})) + :(Base.cfunction($(esc(f)), $(esc(rt)), Tuple{$(esc(tup))...})) end export @cfunction end diff --git a/test/runtests.jl b/test/runtests.jl index f6cedcd55..9c8d36020 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1749,6 +1749,14 @@ let ptr = @cfunction(+, Int, (Int, Int)) @test ptr != C_NULL @test ccall(ptr, Int, (Int, Int), 2, 3) == 5 end +# issue #565 +issue565(x) = x + 1 +const Issue565 = Int +let bar() = @cfunction(issue565, Issue565, (Issue565,)), ptr = bar() + @test ptr isa Ptr{Cvoid} + @test ptr != C_NULL + @test ccall(ptr, Int, (Int,), 2) === 3 +end # 0.7.0-DEV.5278 @test something(nothing, 1) === 1