closure: fix handling of ENUMs and integral return types on 64-bit BE platforms
closure: fix handling of ENUMs and integral return types on 64-bit BE platforms

enums are stored in v_long but need to be marshalled as signed
integers.  On platforms where int is 32 bits, taking the
address of v_long resulted in the wrong 32 bits being marshalled.
So we need to stuff the enum's int-sized value to a temporary
int-sized variable and marshall that instead.

Second, on return, libffi actually returns a pointer to a value
that's sized according to platform conventions, not according to
what the caller requested.  ie if ffi_type_sint was requested, the
value can still be a 64-bit sign-extended long on a 64-bit
architecture like PPC64, thus the caller cannot simply cast
the return value as a pointer to the desired type, but must cast
as a pointer to an integral type and then cast to the desired
type to remove any sign extension complications.

For more information on how to correctly handle libffi return
values, see the following bug, specifically comment 35:

https://bugzilla.redhat.com/show_bug.cgi?id=736489

"For 64-bit ABIs that extend integral returns types to 64-bits, libffi always
returns full 64-bit values that you can truncate in the calling code.   It's
just the way it is has always been.  Please don't change libffi.  I'll document
this clearly for the next version (perhaps there is a mention of this, I
haven't looked yet).

The same is true for returning 8-bit values, for instance, on 32-bit systems.
All ABIs extend those results to the full 32-bits so you need to provide a
properly aligned buffer that's big enough to hold the result."

https://bugzilla.gnome.org/show_bug.cgi?id=659881

MathieuDuponchelle/glib,mzabaluev/glib,ieei/glib,darren-clark/android_platform_external_bluetooth_glib,johne53/MB3Glib,iConsole/Console-OS_external_bluetooth_glib,mzabaluev/glib,djdeath/glib,tamaskenez/glib,gale320/glib,iConsole/Console-OS_external_bluetooth_glib,ieei/glib,djdeath/glib,lukasz-skalski/glib,endlessm/glib,pstglia/platform-external-bluetooth-glib,pstglia/external-bluetooth-glib,cosimoc/glib,djdeath/glib,bluez-android/glib,djdeath/glib,tamaskenez/glib,pstglia/external-bluetooth-glib,pstglia/platform-external-bluetooth-glib,krichter722/glib,01org/android-bluez-glib,johne53/MB3Glib,johne53/MB3Glib,iConsole/Console-OS_external_bluetooth_glib,gale320/glib,darren-clark/android_platform_external_bluetooth_glib,iConsole/Console-OS_external_bluetooth_glib,bluez-android/glib,johne53/MB3Glib,tamaskenez/glib,lukasz-skalski/glib,johne53/MB3Glib,antono/glib,johne53/MB3Glib,krichter722/glib,cention-sany/glib,Distrotech/glib,tamaskenez/glib,cosimoc/glib,Distrotech/glib,gale320/glib,lukasz-skalski/glib,mzabaluev/glib,justinkb/aosp-bluez.glib,ieei/glib,justinkb/aosp-bluez.glib,Distrotech/glib,iConsole/Console-OS_external_bluetooth_glib,01org/android-bluez-glib,lukasz-skalski/glib,krichter722/glib,tchakabam/glib,cosimoc/glib,justinkb/aosp-bluez.glib,darren-clark/android_platform_external_bluetooth_glib,tchakabam/glib,krichter722/glib,cention-sany/glib,bluez-android/glib,bluez-android/glib,cention-sany/glib,tchakabam/glib,gale320/glib,antono/glib,pstglia/external-bluetooth-glib,pstglia/platform-external-bluetooth-glib,01org/android-bluez-glib,pstglia/external-bluetooth-glib,Distrotech/glib,gale320/glib,bluez-android/glib,tchakabam/glib,ieei/glib,MathieuDuponchelle/glib,pstglia/platform-external-bluetooth-glib,MathieuDuponchelle/glib,Distrotech/glib,01org/android-bluez-glib,tamaskenez/glib,darren-clark/android_platform_external_bluetooth_glib,antono/glib,pstglia/external-bluetooth-glib,endlessm/glib,mzabaluev/glib,darren-clark/android_platform_external_bluetooth_glib,lukasz-skalski/glib,justinkb/aosp-bluez.glib,ieei/glib,endlessm/glib,antono/glib,cosimoc/glib,mzabaluev/glib,endlessm/glib,01org/android-bluez-glib,tchakabam/glib,justinkb/aosp-bluez.glib,endlessm/glib,MathieuDuponchelle/glib,cosimoc/glib,pstglia/platform-external-bluetooth-glib,cention-sany/glib,krichter722/glib,MathieuDuponchelle/glib,cention-sany/glib,djdeath/glib