3 ms·
I don't quite follow the argument: > it’s on you to ensure the foreignptr’s lifetime becomes interlinked with the returned b Yes; the simplest way to do that
by nh2 3y ago
I don't quite follow the argument:
> it’s on you to ensure the foreignptr’s lifetime becomes interlinked with the returned b
Yes; the simplest way to do that is to make sure that your data types never contain raw `Ptr`, only `ForeignPtr` -- same as in C++, where seeing `mytype * x` should ring the alarm bells.
You could say "but what if I call another FFI function that needs the Ptr as an argument"? In that case, surely the function needs to document if it takes ownership of the pointer. If it doesn't document that, yes, it'll crash; but that's unrelated to finalizers (the "impossibility of composing" of which which is what the post claimed); it would also crash if no finalizers were involved.