-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Is convert_args safe with finalizer? #95
Comments
Could we use |
Yes, this use of savedArgs looks likely incorrect. If it's possible to overload If for some reason the |
So here is the commit that added This change was done deliberately, and did fix some reported segfaults, so it did help. And we've not had any reports of JavaCall segfaults in years (not that this is foolproof evidence, but we used to get regular crash reports earlier, but this fix, and another around casting, made all of that go away) Still, I can sorta see why this might be problematic, and |
Absolutely, it's very likely that this fixed the crashes in practice! But if so, this is an implementation detail of the Julia runtime. In the future, it's very likely that Julia codegen will aggressively elide roots more and more often, and these crashes will emerge again. I don't think it much matters whether you use the Note also that julia> @macroexpand @ccall foo(x::A, y::B)::C
quote
var"#15#arg1root" = Base.cconvert(A, x)
var"#16#arg1" = Base.unsafe_convert(A, var"#15#arg1root")
var"#17#arg2root" = Base.cconvert(B, y)
var"#18#arg2" = Base.unsafe_convert(B, var"#17#arg2root")
$(Expr(:foreigncall,
:(:foo),
:C,
:(Core.svec(A, B)),
0,
:(:ccall),
Symbol("#16#arg1"),
Symbol("#18#arg2"),
Symbol("#15#arg1root"),
Symbol("#17#arg2root")
))
end The things named |
Now JavaCall tries to use
saved_args
to keep reference of JavaObject while passarg.ptr
into JNI FFI.JavaCall.jl/src/core.jl
Lines 244 to 248 in d6c3678
But
saved_args
is not referenced after it created, it might be garbage collected at any time (even beforeccall
).I learnt from this
gc
would only occurs when allocates memory (so current code might work now), but it is hard to trace memory allocation.Is there any better solution that telling gc not to collect
saved_args
?The text was updated successfully, but these errors were encountered: