Why not use FFI? Here's why.

Jun 02, 2010 19:22

On the FFI wiki there's a nice list of reasons why you should use FFI. That's the foreign function interface for Ruby. I imagine other languages have some similar facility ( Read more... )

ruby, ffi

Leave a comment

Comments 6

That was a great article ext_236047 June 3 2010, 03:26:07 UTC
You have a lot of good points! I've had issues with plugins that use FFI on solaris, and it is extremely frustrating having to deal with these cross-compatibility issues. Good job, once again!

Reply


Good points, wrong conclusion ext_236128 June 3 2010, 20:18:27 UTC
These aren't reasons not to use FFI...these are things that need to be improved in FFI ( ... )

Reply


Thank You! ext_236138 June 3 2010, 23:32:36 UTC
I've run in to pretty much all of these problems. It sucks. Problems like these make developing with FFI an incredible pain.

Even worse is I think you've missed a few problems:

1. Struct layouts differ not only per platform but *per version* of a particular library too! That means you have to do platform *and* version detection.

2. Since the extension isn't compiled, you can't do feature detection using the preprocessor. Many libraries will define preprocessor macros so that you can detect which functions it makes available. With FFI, you have to find some sort of test you can perform at runtime.

3. Even if you make your extension work on all those ruby platforms, it *still* won't work on Google App Engine or Android.

I definitely think FFI has it's place. It is a good tool to have in the toolbox. But it is not the cross implementation savior it's been billed as.

Reply

Re: Thank You! djberg96 June 6 2010, 06:31:14 UTC
1. Actually I did mention the per version issue. But, yeah, that's going to be a pain. Not that it's not a pain with C extensions, but it's going to be worse with FFI.

2. That was actually the motivation for mkmf-lite. Mind you, it still requires a C compiler on your system.

3. I'm not familiar with either platform, but thanks for the info.

Agreed, having FFI is certainly a good thing. It's certainly better than nothing!

Reply


GNU Toolchain anonymous June 4 2010, 03:17:09 UTC
One thing we could start working on is freeing libffi from autoconf. A CMake build system would be just as good, and would allow easier building on Windows with Visual Studios (http://stackoverflow.com/questions/395169/using-cmake-to-generate-visual-studio-c-project-files). Many projects ship with both configure.ac and CMakeLists.txt files (http://src.opensolaris.org/source/xref/webstack/webstack/trunk/src/mysql-5.0.45/CMakeLists.txt).

I just successfully compiled libffi using clang (from the LLVM project). So libffi isn't in that horrible of a state.

Dynamic struct layout detection would be *awesome*.

Reply

Re: GNU Toolchain djberg96 June 6 2010, 06:32:15 UTC
Any reason we can't use rake-compiler? But, if that's not an option, CMake would be nice.

Reply


Leave a comment

Up