3 ms·
We have this same problem in Ruby - implementing the Ruby C extension API if you aren't exactly the same as the reference Ruby implementation is extremely chall
by chrisseaton 6y ago
We have this same problem in Ruby - implementing the Ruby C extension API if you aren't exactly the same as the reference Ruby implementation is extremely challenging. I think Charlie Nutter proposed something like this for Ruby in the past https://github.com/headius/xni https://github.com/headius/xni.
- dragonwriter 6y ago> We have this same problem in Ruby - implementing the Ruby C extension API if you aren't exactly the same as the reference Ruby implementation is extremely challenging. Isn't that (plus, also, cross-interpreter native extensions) what the FFI [0] gem (first implemented for Rubinius, then JRuby, and now pretty much every Ruby interpreter that matters except Opal.) AFAIK, FFI has been the recommended way of writing C-exts for Ruby for sometime, as FFI exts are both cleaner to write and portable across Ruby implementations. [0] https://github.com/ffi/ffi https://github.com/ffi/ffi
- chrisseaton 6y agoIt'd be great if people used FFI, or the standard built-in equivalent, Fiddle, but they generally don't, so it doesn't really practically solve the problem at the moment. I think there's something like half a billion lines of C extension code using the traditional API out there. However, note that the FFI isn't really applicable with one very common use-case of C extensions anyway - increased performance through reaching through abstractions. See fast_blank for example. Can you reimplement that effectively using a cross-platform FFI? I'm not sure you can. The FFI also adds a bit of runtime overhead for each call, which you may not want.
- sitkack 6y agoOnly support extensions in Wasm? Change build tooling (I don't Ruby, I am sure it has an equivalent) so that setup.py builds the C extension into a Wasm module. Or grab the fn that the FFI points to and lightly decompile and inline into the interpreter? Compile the typed subset of dynamic language of the day into Wasm and inline that into the interpreter? I am sure something here is the Holy Grail of native-ish extension mechanism.
- chrisseaton 6y agoGraalPython and TruffleRuby are trying this exact idea, but with LLVM bitcode rather than WASM.