Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Use invokelatest in jl_Function_call #416

Merged
merged 1 commit into from
Jul 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,31 @@ function jl_Function_call(self_::PyPtr, args_::PyPtr, kw_::PyPtr)
args = PyObject(args_) # don't need pyincref because of finally clause below
try
f = unsafe_pyjlwrap_to_objref(self_)::Function
if kw_ == C_NULL
ret = PyObject(f(convert(PyAny, args)...))
else
kw = PyDict{Symbol,PyAny}(pyincref(kw_))
kwargs = [ (k,v) for (k,v) in kw ]
ret = PyObject(f(convert(PyAny, args)...; kwargs...))

# on 0.6 we need to use invokelatest to get execution in newest world
@static if isdefined(Base, :invokelatest)
if kw_ == C_NULL
ret = PyObject(Base.invokelatest(f, convert(PyAny, args)...))
else
kw = PyDict{Symbol,PyAny}(pyincref(kw_))
kwargs = [ (k,v) for (k,v) in kw ]

# 0.6 `invokelatest` doesn't support kwargs, instead
# use a closure over kwargs. see:
# https://github.com/JuliaLang/julia/pull/22646
f_kw_closure() = f(convert(PyAny, args)...; kwargs...)
ret = PyObject(Core._apply_latest(f_kw_closure))
end
else # 0.5 support
if kw_ == C_NULL
ret = PyObject(f(convert(PyAny, args)...))
else
kw = PyDict{Symbol,PyAny}(pyincref(kw_))
kwargs = [ (k,v) for (k,v) in kw ]
ret = PyObject(f(convert(PyAny, args)...; kwargs...))
end
end

return pystealref!(ret)
catch e
pyraise(e)
Expand Down