Skip to content

Commit

Permalink
Add GC.@preserve in _jcall to partly address #95
Browse files Browse the repository at this point in the history
  • Loading branch information
mkitti committed May 30, 2020
1 parent 8782ac7 commit eb43d3e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ for (x, y, z) in [(:jboolean, :(JNI.CallBooleanMethodA), :(JNI.CallStaticBoolean
@assert jmethodId != C_NULL
isnull(obj) && throw(JavaCallError("Attempt to call method on Java NULL"))
savedArgs, convertedArgs = convert_args(argtypes, args...)
result = callmethod(obj.ptr, jmethodId, Array{JNI.jvalue}(jvalue.(convertedArgs)))
GC.@preserve savedArgs begin
result = callmethod(obj.ptr, jmethodId, Array{JNI.jvalue}(jvalue.(convertedArgs)))
end
deleteref.(filter(x->isa(x,JavaObject),convertedArgs))
result==C_NULL && geterror()
result == nothing && (return)
Expand All @@ -221,7 +223,9 @@ function _jcall(obj, jmethodId::Ptr{Nothing}, callmethod::Union{Function,Ptr{Not
@assert jmethodId != C_NULL
isnull(obj) && error("Attempt to call method on Java NULL")
savedArgs, convertedArgs = convert_args(argtypes, args...)
result = callmethod(obj.ptr, jmethodId, Array{JNI.jvalue}(jvalue.(convertedArgs)))
GC.@preserve savedArgs begin
result = callmethod(obj.ptr, jmethodId, Array{JNI.jvalue}(jvalue.(convertedArgs)))
end
deleteref.(filter(x->isa(x,JavaObject),convertedArgs))
result==C_NULL && geterror()
return convert_result(rettype, result)
Expand Down

0 comments on commit eb43d3e

Please sign in to comment.