| ▲ | Panzerschrek 3 days ago | ||||||||||||||||
Extern "fil-C" can't be compatible with Rust code or something similar. It requires a metadata block attached to each allocation. So, if a memory block has been allocated in Rust and a pointer to it is passed to a fil-C function, it can't access it correctly. The only way to allow such cross-langauge-and-abi calls is to compile Rust code itself like fil-C, which requires doubled memory consumption, expensive runtime checks and GC overhead. | |||||||||||||||||
| ▲ | jaen 2 days ago | parent | next [-] | ||||||||||||||||
Naah. Solvable by turning the usual C library allocation pattern inside-out: Only the C side allocates, Rust gets views of that memory. Also well established - calling WebAssembly components requires exactly the same pattern, as the only way to malloc is to call into the WASM side. | |||||||||||||||||
| ▲ | CyberDildonics 3 days ago | parent | prev | next [-] | ||||||||||||||||
Why would it double memory consumption just for a metadata block? Why not just wrap the memory allocation function so it makes that block? | |||||||||||||||||
| ▲ | tracnar 3 days ago | parent | prev [-] | ||||||||||||||||
Another way would be to enforce a copy, adding the metadata, at the boundary with fil-C, right? Of course that makes the FFI way less useful... | |||||||||||||||||
| |||||||||||||||||