On 16/11/2011 20:27, Phil Clayton wrote:
On 16/11/11 18:27, David Matthews wrote:
On 16/11/2011 18:07, Phil Clayton wrote: Right. Those preprocessor symbols are wrong. I think I changed them elsewhere in the code and somehow those got missed. I think the issue is that on X86/32 all arguments are passed on the stack but on the X86/64 integer-like arguments are passed in the general registers but floating point values are passed in floating-point registers. The code in apply_rec casts everything to (void*) which means that the foreign function will always be called with the arguments in the general registers even if it is expecting them in FP registers. This is frankly horrible and really this should be changed. Instead of interpreting the type information when the foreign function is called it should compile a stub which will convert the arguments into the correct format. I did find a project that would do something like that but it didn't deal with call-backs at all.
Thanks - knowing that everything is cast to (void *) makes the issue much clearer.
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.
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.
Regards, David