=begin
Running the test suite for 1.9.2 on sparc64 on OpenBSD, the following errors on received:
Failure:
test_callback(DL::TestDL)
[/usr/ports/pobj/ruby-1.9.2-p0/ruby-1.9.2-p0/test/dl/test_dl2.rb:144]:
<"aabbfoorz"> expected but was
<"zabrfbooa">.
Failure:
test_isdigit(DL::TestFunc)
[/usr/ports/pobj/ruby-1.9.2-p0/ruby-1.9.2-p0/test/dl/test_func.rb:67]:
Expected 0 to be > 0.
Failure:
test_qsort1(DL::TestFunc)
[/usr/ports/pobj/ruby-1.9.2-p0/ruby-1.9.2-p0/test/dl/test_func.rb:95]:
<"1349"> expected but was
<"9341">.
Failure:
test_qsort2(DL::TestFunc)
[/usr/ports/pobj/ruby-1.9.2-p0/ruby-1.9.2-p0/test/dl/test_func.rb:105]:
<"1349"> expected but was
<"9341">.
Failure:
test_isdigit(DL::TestImport)
[/usr/ports/pobj/ruby-1.9.2-p0/ruby-1.9.2-p0/test/dl/test_import.rb:126]:
Expected 0 to be > 0.
It's possible this is an upstream issue with libffi. If so, please let me know and I'll report it to the libffi developers.
=end
ruby -v changed from ruby 1.9.2p0 (2010-08-18 revision 29036) [sparc64-openbsd4.8] to ruby 1.9.4dev (2011-08-05 trunk 32863) [sparc64-solaris2.10]
This is also reproduced on sparc64 Solaris10 with latest Ruby.
This is not because of endian, nor libffi bug, but a bug of Fiddle.
Patch is attached.
The manpage of ffi_call(3) (http://linux.die.net/man/3/ffi_call ) says:
"rvalue must point to storage that is sizeof(long) or larger. For smaller return value sizes, the ffi_arg or ffi_sarg integral type must be used to hold the return value."
but Fiddle did not use ffi_arg nor ffi_sarg for getting the "rvalue" after ffi_call and closure callback.
Note that value_to_generic and generic_to_value are asymmetric after the patch.
In addition, to avoid potential bug in big-endian architecture, the patch also modifies value_to_generic() to strictly distinguish char, short and int.
This issue was solved with changeset r32895.
Jeremy, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
ext/fiddle/conversions.c (generic_to_value): ffi_arg and ffi_sarg
should be used to handle shorter return value. fix [Bug #3861] [ruby-core:32504]
ext/fiddle/closure.c (callback): ditto
ext/fiddle/conversions.h (fiddle_generic): ditto
ext/fiddle/conversions.c (value_to_generic): char, short and int
are strictly distinguished on big-endian CPU, e.g. sparc64.