Project

General

Profile

Bug #11579 ยป fix-fiddle-win32_last_error.diff

cremno (cremno phobia), 10/10/2015 11:22 AM

View differences:

ext/fiddle/function.c
186 186

  
187 187
    rb_funcall(mFiddle, rb_intern("last_error="), 1, INT2NUM(errno));
188 188
#if defined(_WIN32)
189
    rb_funcall(mFiddle, rb_intern("win32_last_error="), 1, INT2NUM(errno));
189
    rb_funcall(mFiddle, rb_intern("win32_last_error="), 1, ULONG2NUM(GetLastError()));
190 190
#endif
191 191

  
192 192
    ALLOCV_END(alloc_buffer);
test/fiddle/test_function.rb
10 10
    def setup
11 11
      super
12 12
      Fiddle.last_error = nil
13
      Fiddle.win32_last_error = nil if WINDOWS
13 14
    end
14 15

  
15 16
    def test_default_abi
......
65 66
      refute_nil Fiddle.last_error
66 67
    end
67 68

  
69
    def test_win32_last_error
70
      kernel32 = dlopen('kernel32')
71
      args = [kernel32['SetLastError'], [TYPE_LONG], TYPE_VOID]
72
      args << Function::STDCALL if Function.const_defined?(:STDCALL)
73
      func = Function.new(*args)
74

  
75
      assert_nil(Fiddle.win32_last_error)
76
      n = 1 << 29 | 1
77
      func.call(n)
78
      assert_equal(n, Fiddle.win32_last_error)
79
    end if WINDOWS
80

  
68 81
    def test_strcpy
69 82
      f = Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP)
70 83
      buff = "000"