Ruby DL extension and x86_64

Hi,

I’ve been trying to use the new GD2 bindings (http://
gd2.rubyforge.org), which have worked great… until I deployed on an
x86_64 server.

Under 64bit, Ruby’s DL extension doesn’t pass the parameters to the
shared lib functions correctly as (upto 6, integer/pointer)
parameters get passed via registers instead of on the stack. Which is
in contrast to 32bit/x86 where everything gets passed on the stack.

When using gdImageStringFTEx which took 10 parameters, 2 of which are
doubles. This caused junk to be passed in the parameters from the
first double parameters onwards to the GD function and subsequently
segfaulted:

0x0000000800ed8239 in gdImageStringFTEx (im=0x0, brect=0x5e3bc0,
fg=0, fontlist=0x5c60b0 “./verdana.ttf”, ptsize=9, angle=5600, x=0, y=6,
string=0x7fffffffabe0 “”, strex=0x800dc1a56) at gdft.c:937

The parameters should be ptsize=1.0, angle=2.0, x=3, y=4. The
pointers for string, and strex were also incorrect.

I have attached a patch that allows DL to work correctly on x86_64
(only) with functions that take floating point parameters, but it has
a caveat in that you cannot call a function that takes more than 8
floats/doubles.

The patch isn’t portable, so it seems like it would be a good idea to
convert DL to using Libffi (http://sourceware.org/libffi/) for the
future (Ruby 2.0?). Using Libffi would make the DL extension much
simpler and portable across many more platforms.

Thanks to Perry Lorier for being the brains behind the patch!

Cheers

Philip Murray