Replies: 1 comment 2 replies
-
|
You can't return Julia data from the scope whose frame roots it. You can either perform all operations you need inside a scope, or if the data is an isbits type you can unbox it and return it because it won't have any lifetimes after it has been unboxed. However, in that second case you will need to convert it to Julia data again in another scope if you want to call some Julia function with it as an argument. The reason is that while data is rooted in a frame, it won't be freed by the GC until you leave that scope. When you leave a scope, all the roots hat belong to it are cleared and can be freed by the GC if it can't be found through another root which is still valid. By inheriting the lifetime of the frame (or more generally, the target), Julia data can't be returned from the scope in which it has been rooted, which avoids use-after-free bugs. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello again,
how can I call multiple different julia functions in Rust so that it could be modular and I don't have to call them in same frame.
For example I have this julia function that I want to call:
function my_fu(x::Int)
return x + 1
end
I have tried to call it in here and return the result:
pub fn call_my_fu(p: i32) -> JlrsResult {
// Initialize the Julia runtime
let mut frame = StackFrame::new();
let mut pending = unsafe { RuntimeBuilder::new().start().expect("Could not init Julia") };
let mut julia = pending.instance(&mut frame);
}
So I could use the result later on as parameter for example in this julia function:
function my_ofu(f::Function, x::Int)
result = f(x)
println("The result is: ", result)
end
Beta Was this translation helpful? Give feedback.
All reactions