diff --git a/.travis.yml b/.travis.yml index 8160ba5..66f2d04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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())' diff --git a/appveyor.yml b/appveyor.yml index 6f2b10f..eb05d8d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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" diff --git a/src/FunctionWrappers.jl b/src/FunctionWrappers.jl index af69127..06f97f2 100644 --- a/src/FunctionWrappers.jl +++ b/src/FunctionWrappers.jl @@ -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...) @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 7c9fcc9..10d6cd5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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