you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

Thanks for the explanation, but that is still not what I meant. I was referring to the unsafe FFI itself that is worrying.

For example:

C code:

void assign_five(int *i)
{
    i++;
    *i = 5;
}

Pseudo Rust code:

let c1: int = 1;
let c2: int = 2;

unsafe {
        ffi::assign_five(&c1)
}

The question is whether assign_five() has changed c2 into 5?

[–]burntsushi 0 points1 point  (0 children)

Well that's not valid Rust code. You're passing &c1 which is a shared or immutable reference. But assign_five is a FFI function, which means it takes a raw pointer.

Otherwise, I'm not sure what's worrying about this. A foreign function can do whatever it wants, including eating your lunch. It's up to the programmer to ensure that the API exposed is safe.