Skip to content

Commit

Permalink
Fix 0.7 type definition depwarn with minimum include_string/parse
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed May 25, 2017
1 parent d94f433 commit 271ac4e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ os:
- osx
julia:
- 0.5
- 0.6
- nightly
after_success:
- julia -e 'cd(Pkg.dir("FunctionWrappers")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
36 changes: 24 additions & 12 deletions src/FunctionWrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ Base.@pure get_cfunc_argtype(Obj, Args) =

# Call wrapper since `cfunction` does not support non-function
# or closures
immutable CallWrapper{Ret} <: Function
if VERSION >= v"0.6.0"
# Can in princeple be lower but 0.6 doesn't warn on this so it doesn't matter
include_string("struct CallWrapper{Ret} <: Function end")
else
include_string("immutable CallWrapper{Ret} <: Function end")
end
(::CallWrapper{Ret}){Ret}(f, args...)::Ret = f(args...)

Expand All @@ -46,18 +50,26 @@ for nargs in 0:128
f($((Symbol("arg", i) for i in 1:nargs)...))
end

type FunctionWrapper{Ret,Args<:Tuple}
ptr::Ptr{Void}
objptr::Ptr{Void}
obj
objT
function (::Type{FunctionWrapper{Ret,Args}}){Ret,Args,objT}(obj::objT)
objref = Base.cconvert(Ref{objT}, obj)
new{Ret,Args}(cfunction(CallWrapper{Ret}(), map_rettype(Ret),
get_cfunc_argtype(objT, Args)),
Base.unsafe_convert(Ref{objT}, objref), objref, objT)
let ex = if VERSION >= v"0.6.0"
# Can in princeple be lower but 0.6 doesn't warn on this so it doesn't matter
parse("mutable struct FunctionWrapper{Ret,Args<:Tuple} end")
else
parse("type FunctionWrapper{Ret,Args<:Tuple} end")
end
ex.args[3] = quote
ptr::Ptr{Void}
objptr::Ptr{Void}
obj
objT
function (::Type{FunctionWrapper{Ret,Args}}){Ret,Args,objT}(obj::objT)
objref = Base.cconvert(Ref{objT}, obj)
new{Ret,Args}(cfunction(CallWrapper{Ret}(), map_rettype(Ret),
get_cfunc_argtype(objT, Args)),
Base.unsafe_convert(Ref{objT}, objref), objref, objT)
end
(::Type{FunctionWrapper{Ret,Args}}){Ret,Args}(obj::FunctionWrapper{Ret,Args}) = obj
end
(::Type{FunctionWrapper{Ret,Args}}){Ret,Args}(obj::FunctionWrapper{Ret,Args}) = obj
eval(ex)
end

Base.convert{T<:FunctionWrapper}(::Type{T}, obj) = T(obj)
Expand Down
7 changes: 5 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import FunctionWrappers
import FunctionWrappers: FunctionWrapper
using Base.Test

immutable CallbackF64
f::FunctionWrapper{Float64,Tuple{Int}}
if VERSION >= v"0.6.0"
# Can in princeple be lower but 0.6 doesn't warn on this so it doesn't matter
include_string("struct CallbackF64 f::FunctionWrapper{Float64,Tuple{Int}} end")
else
include_string("immutable CallbackF64 f::FunctionWrapper{Float64,Tuple{Int}} end")
end
(cb::CallbackF64)(v) = cb.f(v)
gen_closure(x) = y->x + y
Expand Down

0 comments on commit 271ac4e

Please sign in to comment.