On 18/11/2011 13:49, Phil Clayton wrote:
On 17/11/11 19:40, David Matthews wrote:
Well, having decided that the existing code is horrible I bit the bullet and investigated libffi more closely. It turns out that it does everything we need including callbacks. I've now modified the foreign-function interface so that it will use libffi if it is available. As with GMP there is a configure option to control whether it is used and the default is to use it if it is there. It may need the development version of the libffi package with all the headers in order for configure to detect it.
Fantastic news! It makes a huge difference to me so I am very grateful. libffi seems like a neat idea - I hadn't heard of it.
libffi-devel is required for the headers on Fedora. (The rpm was already present on my system due to the presence of some GHC devel rpm.)
With Fedora, there is a minor configuration issue: like many packages, libffi headers are not installed on a standard path, so relies on pkg-config to supply cflags/libs arguments. I was able to build by simply adding symbolic links in /usr/include. After some investigation, it seems a more general solution can be achieved with the PKG_CHECK_MODULES macro in configure but I don't know whether Fedora is just an unusual case regarding libffi setup.
So far I've tested callbacks on X86/32 and X86/64 and it all works. I haven't yet tested floating point on X86/64 but I'd expect it to work as well.
In my mini-suite of FFI tests, all now work without issue on x86_64. This includes doubles as arguments. Great to see structs can now be used too!
Phil
I'm glad it works for you. When I tested it with Debian and Ubuntu I had to install the development packages but otherwise it went smoothly. I'm considering adding libffi to the poly source since it's licensed under the BSD licence. I need to look at the configure script and see how easy it would be to merge it into the existing script. Relying on the packages complicates things particularly on Windows and it would be really nice to be able to get rid of the old FFI code.
David