Andreas Ronge created JRUBY-6461:
------------------------------------
Summary: FFI problem on linux 64bit
Key: JRUBY-6461
URL: https://jira.codehaus.org/browse/JRUBY-6461
Project: JRuby
Issue Type: Bug
Components: C Extensions
Affects Versions: JRuby 1.6.6, JRuby 1.6.5
Environment: Java version "1.6.0_29" Java(TM) SE Runtime Environment
(build 1.6.0_29-b11)
Linux x86/x64 3.0.0-16-generic #28-Ubuntu SMP Fri Jan 27 17:44:39 UTC 2012
x86_64 x86_64 x86_64 GNU/Linux
Reporter: Andreas Ronge
Assignee: Thomas E Enebo
Priority: Minor
Attachments: ffi_test.zip
Hi all,
We have a problem with JRuby 1.6.5 and 1.6.6 + FFI + Linux x64, it seems like a
bug.
We have a library, named xxx_decoder.so, include Linux x86/x64 edition.
The C/C++ declare:
--------
typedef struct S_Time
{
UINT32 Second;
UINT32 Usecond;
}S_Time;
extern "C" int DecodeProc(HandleType int, unsigned char* data, int Len, S_Time
s_time)
--------
The code (see attached test case):
--------
require 'ffi'
class S_Time < FFI::Struct
layout :seconds => :uint32, :useconds => :uint32
end
class Decoder
def initialize(lib)
extend FFI:Library
ffi_lib lib
attach_function :DecodeProc, [:int, :pointer, :int, S_Time.by_value], int
# .... Other functions
end
--------
And used like this:
# bit64 is a function to detect the OS bits.
lib = bit64 ? 'xxx_64_decoder.so' : 'xxx_32_decoder.so'
@decoder = Decoder.new(lib)
buf = "abcdef123456"
s_time = S_Time.new
s_time[:seconds], s[:useconds] = 1280196162, 138000
@decoder.DecodeProc(10, buf, buf.length, s_time)
These codes works fine under Linux 32, Windows 7(x64, JRuby is 32 bit), The
library
receive the s_time correctly, but under Linux x64, the FFI pass the s_time
address,
so the library can't receive the time value correctly.
We found, If we change the S_Time declare as pointer, we can pass the s_time
into
library correcly. But the libraries already used for many clients, we can't
change
the library interface declare, so I had to found a way to solve this issue with
JRuby/FFI myself.
To reproduce - see the attached test case, and run the
ruby ffi_struct_fail.rb
It should return something like this:
[1280196162, 138000]
[1280196162, 138000]
[1280196162, 139068]
[1280196162, 139588]
[1280196162, 139745]
[1280196162, 139745]
However, on my 64 bit linux it returns:
[1276791760, 32548]
[2545484410, 695521]
[2545484410, 696589]
[2545484410, 697109]
[2545484410, 697266]
[2545484410, 697266]
[2545484411, 241823]
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email