ffi 1.9.21 → 1.9.22

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

Files changed (151) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +3 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +22 -0
  5. data/.gitmodules +3 -0
  6. data/.travis.yml +52 -0
  7. data/.yardopts +5 -0
  8. data/Gemfile +15 -0
  9. data/{spec/ffi/LICENSE.SPECS → LICENSE.SPECS} +1 -1
  10. data/README.md +1 -1
  11. data/Rakefile +28 -3
  12. data/appveyor.yml +22 -0
  13. data/ext/ffi_c/Call.c +1 -22
  14. data/ext/ffi_c/Call.h +0 -9
  15. data/ext/ffi_c/Closure.c +54 -0
  16. data/ext/ffi_c/{ClosurePool.h → Closure.h} +13 -23
  17. data/ext/ffi_c/Function.c +16 -25
  18. data/ext/ffi_c/Function.h +1 -2
  19. data/ext/ffi_c/FunctionInfo.c +0 -4
  20. data/ext/ffi_c/MethodHandle.c +33 -268
  21. data/ext/ffi_c/extconf.rb +3 -3
  22. data/ext/ffi_c/ffi.c +2 -2
  23. data/ext/ffi_c/libffi.bsd.mk +3 -3
  24. data/ext/ffi_c/libffi.darwin.mk +1 -1
  25. data/ext/ffi_c/libffi.gnu.mk +1 -1
  26. data/ext/ffi_c/libffi.mk +2 -2
  27. data/ext/ffi_c/libffi.vc.mk +1 -1
  28. data/ext/ffi_c/libffi.vc64.mk +1 -1
  29. data/ext/ffi_c/libffi/.appveyor.yml +48 -0
  30. data/ext/ffi_c/libffi/.gitignore +36 -0
  31. data/ext/ffi_c/libffi/.travis.yml +30 -0
  32. data/ext/ffi_c/libffi/.travis/install.sh +14 -0
  33. data/ext/ffi_c/libffi/Makefile.am +5 -3
  34. data/ext/ffi_c/libffi/acinclude.m4 +6 -0
  35. data/ext/ffi_c/libffi/autogen.sh +1 -1
  36. data/ext/ffi_c/libffi/config.guess +1466 -0
  37. data/ext/ffi_c/libffi/config.sub +1836 -0
  38. data/ext/ffi_c/libffi/configure.ac +2 -2
  39. data/ext/ffi_c/libffi/configure.host +15 -3
  40. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +11 -15
  41. data/ext/ffi_c/libffi/include/ffi.h.in +6 -1
  42. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +465 -59
  43. data/ext/ffi_c/libffi/src/aarch64/ffi.c +33 -10
  44. data/ext/ffi_c/libffi/src/aarch64/sysv.S +2 -2
  45. data/ext/ffi_c/libffi/src/arm/ffi.c +12 -1
  46. data/ext/ffi_c/libffi/src/arm/sysv.S +1 -1
  47. data/ext/ffi_c/libffi/src/closures.c +143 -97
  48. data/ext/ffi_c/libffi/src/ia64/unix.S +2 -0
  49. data/ext/ffi_c/libffi/src/mips/ffi.c +8 -0
  50. data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
  51. data/ext/ffi_c/libffi/src/mips/n32.S +2 -0
  52. data/ext/ffi_c/libffi/src/powerpc/aix.S +239 -1
  53. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +250 -3
  54. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +86 -5
  55. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +3 -0
  56. data/ext/ffi_c/libffi/src/x86/ffi.c +3 -1
  57. data/ext/ffi_c/libffi/src/x86/ffi64.c +26 -5
  58. data/ext/ffi_c/libffi/src/x86/sysv.S +2 -2
  59. data/ext/ffi_c/libffi/src/x86/unix64.S +1 -1
  60. data/ext/ffi_c/libffi/src/x86/win64.S +1 -1
  61. data/ext/ffi_c/libffi/testsuite/Makefile.am +2 -1
  62. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +2 -1
  63. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3float.c +95 -0
  64. data/ffi.gemspec +14 -1
  65. data/lib/ffi/library.rb +1 -1
  66. data/lib/ffi/version.rb +1 -1
  67. data/samples/getlogin.rb +8 -0
  68. data/samples/getpid.rb +8 -0
  69. data/samples/gettimeofday.rb +18 -0
  70. data/samples/hello.rb +7 -0
  71. data/samples/inotify.rb +60 -0
  72. data/samples/pty.rb +76 -0
  73. data/samples/qsort.rb +21 -0
  74. data/samples/sample_helper.rb +6 -0
  75. metadata +59 -81
  76. metadata.gz.sig +0 -0
  77. data/ext/ffi_c/ClosurePool.c +0 -283
  78. data/gen/Rakefile +0 -30
  79. data/libtest/Benchmark.c +0 -52
  80. data/libtest/BoolTest.c +0 -34
  81. data/libtest/BufferTest.c +0 -31
  82. data/libtest/ClosureTest.c +0 -205
  83. data/libtest/EnumTest.c +0 -51
  84. data/libtest/FunctionTest.c +0 -70
  85. data/libtest/GNUmakefile +0 -149
  86. data/libtest/GlobalVariable.c +0 -62
  87. data/libtest/LastErrorTest.c +0 -21
  88. data/libtest/NumberTest.c +0 -132
  89. data/libtest/PointerTest.c +0 -63
  90. data/libtest/ReferenceTest.c +0 -23
  91. data/libtest/StringTest.c +0 -34
  92. data/libtest/StructTest.c +0 -243
  93. data/libtest/UnionTest.c +0 -43
  94. data/libtest/VariadicTest.c +0 -99
  95. data/spec/ffi/async_callback_spec.rb +0 -35
  96. data/spec/ffi/bitmask_spec.rb +0 -575
  97. data/spec/ffi/bool_spec.rb +0 -32
  98. data/spec/ffi/buffer_spec.rb +0 -279
  99. data/spec/ffi/callback_spec.rb +0 -773
  100. data/spec/ffi/custom_param_type.rb +0 -37
  101. data/spec/ffi/custom_type_spec.rb +0 -74
  102. data/spec/ffi/dup_spec.rb +0 -52
  103. data/spec/ffi/enum_spec.rb +0 -423
  104. data/spec/ffi/errno_spec.rb +0 -20
  105. data/spec/ffi/ffi_spec.rb +0 -28
  106. data/spec/ffi/fixtures/Benchmark.c +0 -52
  107. data/spec/ffi/fixtures/BitmaskTest.c +0 -51
  108. data/spec/ffi/fixtures/BoolTest.c +0 -34
  109. data/spec/ffi/fixtures/BufferTest.c +0 -31
  110. data/spec/ffi/fixtures/ClosureTest.c +0 -205
  111. data/spec/ffi/fixtures/EnumTest.c +0 -51
  112. data/spec/ffi/fixtures/FunctionTest.c +0 -142
  113. data/spec/ffi/fixtures/GNUmakefile +0 -149
  114. data/spec/ffi/fixtures/GlobalVariable.c +0 -62
  115. data/spec/ffi/fixtures/LastErrorTest.c +0 -21
  116. data/spec/ffi/fixtures/NumberTest.c +0 -132
  117. data/spec/ffi/fixtures/PipeHelper.h +0 -21
  118. data/spec/ffi/fixtures/PipeHelperPosix.c +0 -41
  119. data/spec/ffi/fixtures/PipeHelperWindows.c +0 -72
  120. data/spec/ffi/fixtures/PointerTest.c +0 -63
  121. data/spec/ffi/fixtures/ReferenceTest.c +0 -23
  122. data/spec/ffi/fixtures/StringTest.c +0 -34
  123. data/spec/ffi/fixtures/StructTest.c +0 -243
  124. data/spec/ffi/fixtures/UnionTest.c +0 -43
  125. data/spec/ffi/fixtures/VariadicTest.c +0 -99
  126. data/spec/ffi/fixtures/classes.rb +0 -438
  127. data/spec/ffi/function_spec.rb +0 -97
  128. data/spec/ffi/io_spec.rb +0 -16
  129. data/spec/ffi/library_spec.rb +0 -286
  130. data/spec/ffi/long_double.rb +0 -30
  131. data/spec/ffi/managed_struct_spec.rb +0 -68
  132. data/spec/ffi/memorypointer_spec.rb +0 -78
  133. data/spec/ffi/number_spec.rb +0 -247
  134. data/spec/ffi/platform_spec.rb +0 -114
  135. data/spec/ffi/pointer_spec.rb +0 -285
  136. data/spec/ffi/rbx/attach_function_spec.rb +0 -34
  137. data/spec/ffi/rbx/memory_pointer_spec.rb +0 -198
  138. data/spec/ffi/rbx/spec_helper.rb +0 -6
  139. data/spec/ffi/rbx/struct_spec.rb +0 -18
  140. data/spec/ffi/spec_helper.rb +0 -93
  141. data/spec/ffi/string_spec.rb +0 -118
  142. data/spec/ffi/strptr_spec.rb +0 -50
  143. data/spec/ffi/struct_by_ref_spec.rb +0 -43
  144. data/spec/ffi/struct_callback_spec.rb +0 -69
  145. data/spec/ffi/struct_initialize_spec.rb +0 -35
  146. data/spec/ffi/struct_packed_spec.rb +0 -50
  147. data/spec/ffi/struct_spec.rb +0 -882
  148. data/spec/ffi/typedef_spec.rb +0 -91
  149. data/spec/ffi/union_spec.rb +0 -67
  150. data/spec/ffi/variadic_spec.rb +0 -132
  151. data/spec/spec.opts +0 -4
@@ -1,91 +0,0 @@
1
- #
2
- # This file is part of ruby-ffi.
3
- # For licensing, see LICENSE.SPECS
4
- #
5
-
6
- require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
- describe "Custom type definitions" do
8
- it "attach_function with custom typedef" do
9
- module CustomTypedef
10
- extend FFI::Library
11
- ffi_lib TestLibrary::PATH
12
- typedef :uint, :fubar_t
13
- attach_function :ret_u32, [ :fubar_t ], :fubar_t
14
- end
15
- expect(CustomTypedef.ret_u32(0x12345678)).to eq(0x12345678)
16
- end
17
-
18
- it "variadic invoker with custom typedef" do
19
- module VariadicCustomTypedef
20
- extend FFI::Library
21
- ffi_lib TestLibrary::PATH
22
- typedef :uint, :fubar_t
23
- attach_function :pack_varargs, [ :buffer_out, :string, :varargs ], :void
24
- end
25
- buf = FFI::Buffer.new :uint, 10
26
- VariadicCustomTypedef.pack_varargs(buf, "i", :fubar_t, 0x12345678)
27
- expect(buf.get_int64(0)).to eq(0x12345678)
28
- end
29
-
30
- it "Callback with custom typedef parameter" do
31
- module CallbackCustomTypedef
32
- extend FFI::Library
33
- ffi_lib TestLibrary::PATH
34
- typedef :uint, :fubar3_t
35
- callback :cbIrV, [ :fubar3_t ], :void
36
- attach_function :testCallbackU32rV, :testClosureIrV, [ :cbIrV, :fubar3_t ], :void
37
- end
38
- i = 0
39
- CallbackCustomTypedef.testCallbackU32rV(0xdeadbeef) { |v| i = v }
40
- expect(i).to eq(0xdeadbeef)
41
- end
42
- module StructCustomTypedef
43
- extend FFI::Library
44
- ffi_lib TestLibrary::PATH
45
- typedef :uint, :fubar3_t
46
- class S < FFI::Struct
47
- layout :a, :fubar3_t
48
- end
49
- end
50
-
51
- it "Struct with custom typedef field" do
52
- s = StructCustomTypedef::S.new
53
- s[:a] = 0x12345678
54
- expect(s.pointer.get_uint(0)).to eq(0x12345678)
55
- end
56
-
57
- it "attach_function after a typedef should not reject normal types" do
58
- expect do
59
- Module.new do
60
- extend FFI::Library
61
- # enum() will insert a custom typedef called :foo for the enum
62
- enum :foo, [ :a, :b ]
63
- typedef :int, :bar
64
-
65
- ffi_lib TestLibrary::PATH
66
- begin
67
- attach_function :ptr_ret_int32_t, [ :string, :foo ], :bar
68
- rescue FFI::NotFoundError
69
- # NetBSD uses #define instead of typedef for these
70
- attach_function :ptr_ret_int32_t, :ptr_ret___int32_t, [ :string, :foo ], :bar
71
- end
72
- end
73
- end.not_to raise_error
74
- end
75
-
76
- it "detects the correct type for size_t" do
77
- expect do
78
- Module.new do
79
- extend FFI::Library
80
- ffi_lib "c"
81
- if FFI::Platform.windows?
82
- # _read() is a function of msvcrt.dll
83
- attach_function :_read, [:int, :pointer, :uint], :int
84
- else
85
- # read(2) is a standard UNIX function
86
- attach_function :read, [:int, :pointer, :size_t], :ssize_t
87
- end
88
- end
89
- end.not_to raise_error
90
- end
91
- end
@@ -1,67 +0,0 @@
1
- #
2
- # This file is part of ruby-ffi.
3
- # For licensing, see LICENSE.SPECS
4
- #
5
-
6
- require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
-
8
- module LibTest
9
- Types = {
10
- 's8' => [:char, :c, 1],
11
- 's16' => [:short, :s, 0xff0],
12
- 's32' => [:int, :i, 0xff00],
13
- 's64' => [:long_long, :j, 0xffff00],
14
- 'long' => [:long, :l, 0xffff],
15
- 'f32' => [:float, :f, 1.0001],
16
- 'f64' => [:double, :d, 1.000000001]
17
- }
18
- class TestUnion < FFI::Union
19
- layout( :a, [:char, 10],
20
- :i, :int,
21
- :f, :float,
22
- :d, :double,
23
- :s, :short,
24
- :l, :long,
25
- :j, :long_long,
26
- :c, :char )
27
- end
28
- Types.keys.each do |k|
29
- attach_function "union_align_#{k}", [ :pointer ], Types[k][0]
30
- attach_function "union_make_union_with_#{k}", [ Types[k][0] ], :pointer
31
- end
32
- attach_function :union_size, [], :uint
33
- end
34
-
35
- describe 'Union' do
36
- before do
37
- @u = LibTest::TestUnion.new
38
- end
39
-
40
- it 'should place all the fields at offset 0' do
41
- expect(LibTest::TestUnion.members.all? { |m| LibTest::TestUnion.offset_of(m) == 0 }).to be true
42
- end
43
- LibTest::Types.each do |k, type|
44
- it "should correctly align/write a #{type[0]} value" do
45
- @u[type[1]] = type[2]
46
- if k == 'f32' or k == 'f64'
47
- expect((@u[type[1]] - LibTest.send("union_align_#{k}", @u.to_ptr)).abs).to be < 0.00001
48
- else
49
- expect(@u[type[1]]).to eq(LibTest.send("union_align_#{k}", @u.to_ptr))
50
- end
51
- end
52
- end
53
- LibTest::Types.each do |k, type|
54
- it "should read a #{type[0]} value from memory" do
55
- @u = LibTest::TestUnion.new(LibTest.send("union_make_union_with_#{k}", type[2]))
56
- if k == 'f32' or k == 'f64'
57
- expect((@u[type[1]] - type[2]).abs).to be < 0.00001
58
- else
59
- expect(@u[type[1]]).to eq(type[2])
60
- end
61
- end
62
- end
63
-
64
- it 'should return a size equals to the size of the biggest field' do
65
- expect(LibTest::TestUnion.size).to eq(LibTest.union_size)
66
- end
67
- end
@@ -1,132 +0,0 @@
1
- #
2
- # This file is part of ruby-ffi.
3
- # For licensing, see LICENSE.SPECS
4
- #
5
-
6
- require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
-
8
- describe "Function with variadic arguments" do
9
- module LibTest
10
- extend FFI::Library
11
- ffi_lib TestLibrary::PATH
12
- enum :enum_type1, [:c1, :c2]
13
- enum :enum_type2, [:c3, 42, :c4]
14
- attach_function :pack_varargs, [ :buffer_out, :string, :varargs ], :void
15
- attach_function :pack_varargs2, [ :buffer_out, :enum_type1, :string, :varargs ], :enum_type1
16
-
17
- attach_function :testBlockingOpen, [ ], :pointer
18
- attach_function :testBlockingRWva, [ :pointer, :char, :varargs ], :char, :blocking => true
19
- attach_function :testBlockingWRva, [ :pointer, :char, :varargs ], :char, :blocking => true
20
- attach_function :testBlockingClose, [ :pointer ], :void
21
- end
22
-
23
- it "takes enum arguments" do
24
- buf = FFI::Buffer.new :long_long, 2
25
- LibTest.pack_varargs(buf, "ii", :int, :c3, :int, :c4)
26
- expect(buf.get_int64(0)).to eq(42)
27
- expect(buf.get_int64(8)).to eq(43)
28
- end
29
-
30
- it "returns symbols for enums" do
31
- buf = FFI::Buffer.new :long_long, 2
32
- expect(LibTest.pack_varargs2(buf, :c1, "ii", :int, :c3, :int, :c4)).to eq(:c2)
33
- end
34
-
35
- it 'can wrap a blocking function with varargs' do
36
- pending("not supported in 1.8") if RUBY_VERSION =~ /^1\.8\..*/
37
- handle = LibTest.testBlockingOpen
38
- expect(handle).not_to be_null
39
- begin
40
- thWR = Thread.new { LibTest.testBlockingWRva(handle, 63, :int, 40, :int, 23, :int, 0) }
41
- thRW = Thread.new { LibTest.testBlockingRWva(handle, 64, :int, 40, :int, 24, :int, 0) }
42
- expect(thWR.value).to eq(64)
43
- expect(thRW.value).to eq(63)
44
- ensure
45
- LibTest.testBlockingClose(handle)
46
- end
47
- end
48
-
49
- [ 0, 127, -128, -1 ].each do |i|
50
- it "call variadic with (:char (#{i})) argument" do
51
- buf = FFI::Buffer.new :long_long
52
- LibTest.pack_varargs(buf, "c", :char, i)
53
- expect(buf.get_int64(0)).to eq(i)
54
- end
55
- end
56
-
57
- [ 0, 0x7f, 0x80, 0xff ].each do |i|
58
- it "call variadic with (:uchar (#{i})) argument" do
59
- buf = FFI::Buffer.new :long_long
60
- LibTest.pack_varargs(buf, "C", :uchar, i)
61
- expect(buf.get_int64(0)).to eq(i)
62
- end
63
- end
64
-
65
- [ 0, 1.234567, 9.87654321 ].each do |v|
66
- it "call variadic with (:float (#{v})) argument" do
67
- buf = FFI::Buffer.new :long_long
68
- LibTest.pack_varargs(buf, "f", :float, v.to_f)
69
- expect(buf.get_float64(0)).to eq(v)
70
- end
71
- end
72
-
73
- [ 0, 1.234567, 9.87654321 ].each do |v|
74
- it "call variadic with (:double (#{v})) argument" do
75
- buf = FFI::Buffer.new :long_long
76
- LibTest.pack_varargs(buf, "f", :double, v.to_f)
77
- expect(buf.get_float64(0)).to eq(v)
78
- end
79
- end
80
-
81
- module Varargs
82
- PACK_VALUES = {
83
- 'c' => [ 0x12 ],
84
- 'C' => [ 0x34 ],
85
- 's' => [ 0x5678 ],
86
- 'S' => [ 0x9abc ],
87
- 'i' => [ 0x7654321f ],
88
- 'I' => [ 0xfee1babe ],
89
- 'l' => [ 0x1f2e3d4c ],
90
- 'L' => [ 0xf7e8d9ca ],
91
- 'j' => [ 0x1eafdeadbeefa1b2 ],
92
- 'f' => [ 1.23456789 ],
93
- 'd' => [ 9.87654321 ]
94
- }
95
-
96
- TYPE_MAP = {
97
- 'c' => :char, 'C' => :uchar, 's' => :short, 'S' => :ushort,
98
- 'i' => :int, 'I' => :uint, 'j' => :long_long, 'J' => :ulong_long,
99
- 'l' => :long, 'L' => :ulong, 'f' => :float, 'd' => :double
100
- }
101
- end
102
-
103
- def verify(p, off, v)
104
- if v.kind_of?(Float)
105
- expect(p.get_float64(off)).to eq(v)
106
- else
107
- expect(p.get_int64(off)).to eq(v)
108
- end
109
- end
110
-
111
- Varargs::PACK_VALUES.keys.each do |t1|
112
- Varargs::PACK_VALUES.keys.each do |t2|
113
- Varargs::PACK_VALUES.keys.each do |t3|
114
- Varargs::PACK_VALUES[t1].each do |v1|
115
- Varargs::PACK_VALUES[t2].each do |v2|
116
- Varargs::PACK_VALUES[t3].each do |v3|
117
- fmt = "#{t1}#{t2}#{t3}"
118
- params = [ Varargs::TYPE_MAP[t1], v1, Varargs::TYPE_MAP[t2], v2, Varargs::TYPE_MAP[t3], v3 ]
119
- it "call(#{fmt}, #{params.join(',')})" do
120
- buf = FFI::Buffer.new :long_long, 3
121
- LibTest.pack_varargs(buf, fmt, *params)
122
- verify(buf, 0, v1)
123
- verify(buf, 8, v2)
124
- verify(buf, 16, v3)
125
- end
126
- end
127
- end
128
- end
129
- end
130
- end
131
- end
132
- end
@@ -1,4 +0,0 @@
1
- --color
2
- -w
3
- --format
4
- documentation