[FFI] GetLastError always returns 0 on Windows
----------------------------------------------

                 Key: JRUBY-4388
                 URL: http://jira.codehaus.org/browse/JRUBY-4388
             Project: JRuby
          Issue Type: Bug
          Components: Extensions, Windows
    Affects Versions: JRuby 1.4
            Reporter: Vladimir Sizikov


I've noticed that when tweaking jnr-posix on Windows, no matter what I do, 
GetLastError() or errno() always return 0.

So I tried to reproduce the same with standalnoe FFI, and the same problem with 
FFI on JRuby. (Works fine with ruby-fii on MRI though!).

Here's the example:

{code}
require 'ffi'
module MyFFI
  FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
  FORMAT_MESSAGE_FROM_HMODULE = 0x00000800

  extend FFI::Library
  ffi_lib 'msvcrt', 'kernel32'
  ffi_convention :stdcall

  attach_function :GetFileType, [:int], :int
  attach_function :GetLastError, [], :int
  attach_function :FormatMessageA, [:int, :pointer, :int, :int, :string, :int, 
:pointer], :int
end

MyFFI.GetFileType(-100)
errno = MyFFI.GetLastError
p "GetLastError: #{errno} (should be 6)"

msg = " " * 1024
p len =  MyFFI.FormatMessageA(MyFFI::FORMAT_MESSAGE_FROM_SYSTEM, nil, errno, 0, 
msg, 1024, nil)
p msg[0..len-3] # remove \r\n\000
{code}

MRI prints:
{noformat}
D:\work\jruby-dev\jruby>ruby -rubygems link-ffi.rb
"GetLastError: 6 (should be 6)"
24
"The handle is invalid."
{noformat}

JRuby prints:
{code}
D:\work\jruby-dev\jruby>jruby -rubygems link-ffi.rb
"GetLastError: 0 (should be 6)"
39
"                                     "
{code}

Note the last error under JRuby is 0.

The second problem with JRuby's FFI is that the error message is empty (albeit 
of correct size for errno 0).

So, both, GetLastError() and FormatMessage() are not working right.

Any hints would be appreciated!


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.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


Reply via email to