From 6c5d6d366016b34589109bf146abe1a84bba1d3e Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Wed, 6 Jun 2018 13:34:50 -0400 Subject: [PATCH 1/2] fix cfunction escaping bug --- src/Compat.jl | 2 +- test/runtests.jl | 6 ++++++ 2 files changed, 7 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..68616c08b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1749,6 +1749,12 @@ let ptr = @cfunction(+, Int, (Int, Int)) @test ptr != C_NULL @test ccall(ptr, Int, (Int, Int), 2, 3) == 5 end +# issue #565 +let foo(x)=x+1, Foo=Int, bar() = @cfunction(foo, Foo, (Foo,)), 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 From b1d50c5c5c72741d4c6795bf14551362a759e292 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Wed, 6 Jun 2018 13:47:42 -0400 Subject: [PATCH 2/2] julia 0.7 doesn't like at-cfunction on let variable --- test/runtests.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 68616c08b..9c8d36020 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1750,7 +1750,9 @@ let ptr = @cfunction(+, Int, (Int, Int)) @test ccall(ptr, Int, (Int, Int), 2, 3) == 5 end # issue #565 -let foo(x)=x+1, Foo=Int, bar() = @cfunction(foo, Foo, (Foo,)), ptr = bar() +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