Search code examples
ffipharo

Pharo 4 FFI current state and the future


I would like to know which FFI interfaces are supported and functional in Pharo 4, which ones are recommended (if any), and if there are some big changes planned in the future Pharo versions.

Especially I would like to know which stable FFI callback mechanism is available, and what are its restrictions and limitations.


Solution

  • Sorry for taking so long.

    Currently, in Pharo you have two possibilities (and three packages –projects– to tackle them).

    • Out of the box in Pharo 4 you have NativeBoost-FFI who uses ASMJIT as a backend to generate native calls. That means super fast calls, but not so fast callbacks (because it uses some hard trick to make the VM calls back properly). You can find examples of it all around the source-code, you can take a look specially at NBBasicExamples class.

    • You also have FFI plugin which implements a more traditional approach. You have to packages to handle this:

      • FFI, who implements callouts using pragmas (no callbacks). You can install it from the configurations browser and it comes with a set of examples.
      • AlienFFI, another package to handle same library FFI handles, but implementen a more "alien" approach (each function is an object, not a method). This implements callbacks properly and with good performance. Installation is a bit more tricky because it has not been (yet) tested in Pharo 4 (so it is not in the configurations browser) but it should load fine. You can find it here: http://catalog.pharo.org, along with instructions on how to install it (name is OldAlien, because of historical reasons).

    All of them are very stable, but we will do some changes in the close future:

    We will add a backend for NativeBoost-FFI to use the FFI plugin. The reason is our difficulty to maintain current version and the fact we can find more maintainers willing to work in C than in ASM :)

    This change should be backward compatible so you are safe-to-go with NativeBoost.

    Hope this info works for you.