ffi 1.9.5 → 1.9.6
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.
- checksums.yaml +4 -4
- data/Rakefile +13 -6
- data/ext/ffi_c/extconf.rb +2 -2
- data/lib/ffi.rb +2 -0
- data/lib/ffi/version.rb +1 -1
- data/spec/ffi/async_callback_spec.rb +4 -5
- data/spec/ffi/bool_spec.rb +9 -8
- data/spec/ffi/buffer_spec.rb +64 -37
- data/spec/ffi/callback_spec.rb +195 -116
- data/spec/ffi/custom_param_type.rb +1 -1
- data/spec/ffi/custom_type_spec.rb +5 -6
- data/spec/ffi/dup_spec.rb +6 -8
- data/spec/ffi/enum_spec.rb +135 -129
- data/spec/ffi/errno_spec.rb +2 -2
- data/spec/ffi/ffi_spec.rb +4 -6
- data/spec/ffi/fixtures/EnumTest.o +0 -0
- data/spec/ffi/function_spec.rb +22 -11
- data/spec/ffi/io_spec.rb +0 -1
- data/spec/ffi/library_spec.rb +71 -36
- data/spec/ffi/long_double.rb +3 -4
- data/spec/ffi/managed_struct_spec.rb +14 -4
- data/spec/ffi/memorypointer_spec.rb +7 -1
- data/spec/ffi/number_spec.rb +43 -34
- data/spec/ffi/platform_spec.rb +76 -59
- data/spec/ffi/pointer_spec.rb +35 -31
- data/spec/ffi/rbx/attach_function_spec.rb +3 -4
- data/spec/ffi/rbx/memory_pointer_spec.rb +24 -22
- data/spec/ffi/rbx/spec_helper.rb +0 -1
- data/spec/ffi/rbx/struct_spec.rb +1 -2
- data/spec/ffi/spec_helper.rb +5 -2
- data/spec/ffi/string_spec.rb +22 -14
- data/spec/ffi/strptr_spec.rb +6 -7
- data/spec/ffi/struct_by_ref_spec.rb +4 -5
- data/spec/ffi/struct_callback_spec.rb +6 -7
- data/spec/ffi/struct_initialize_spec.rb +2 -3
- data/spec/ffi/struct_packed_spec.rb +12 -14
- data/spec/ffi/struct_spec.rb +203 -129
- data/spec/ffi/typedef_spec.rb +11 -10
- data/spec/ffi/union_spec.rb +8 -7
- data/spec/ffi/variadic_spec.rb +13 -10
- metadata +2 -2
data/spec/ffi/typedef_spec.rb
CHANGED
@@ -4,8 +4,6 @@
|
|
4
4
|
#
|
5
5
|
|
6
6
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
7
|
-
require 'ffi'
|
8
|
-
|
9
7
|
describe "Custom type definitions" do
|
10
8
|
it "attach_function with custom typedef" do
|
11
9
|
module CustomTypedef
|
@@ -14,8 +12,9 @@ describe "Custom type definitions" do
|
|
14
12
|
typedef :uint, :fubar_t
|
15
13
|
attach_function :ret_u32, [ :fubar_t ], :fubar_t
|
16
14
|
end
|
17
|
-
CustomTypedef.ret_u32(0x12345678).
|
15
|
+
expect(CustomTypedef.ret_u32(0x12345678)).to eq(0x12345678)
|
18
16
|
end
|
17
|
+
|
19
18
|
it "variadic invoker with custom typedef" do
|
20
19
|
module VariadicCustomTypedef
|
21
20
|
extend FFI::Library
|
@@ -25,8 +24,9 @@ describe "Custom type definitions" do
|
|
25
24
|
end
|
26
25
|
buf = FFI::Buffer.new :uint, 10
|
27
26
|
VariadicCustomTypedef.pack_varargs(buf, "i", :fubar_t, 0x12345678)
|
28
|
-
buf.get_int64(0).
|
27
|
+
expect(buf.get_int64(0)).to eq(0x12345678)
|
29
28
|
end
|
29
|
+
|
30
30
|
it "Callback with custom typedef parameter" do
|
31
31
|
module CallbackCustomTypedef
|
32
32
|
extend FFI::Library
|
@@ -37,7 +37,7 @@ describe "Custom type definitions" do
|
|
37
37
|
end
|
38
38
|
i = 0
|
39
39
|
CallbackCustomTypedef.testCallbackU32rV(0xdeadbeef) { |v| i = v }
|
40
|
-
i.
|
40
|
+
expect(i).to eq(0xdeadbeef)
|
41
41
|
end
|
42
42
|
module StructCustomTypedef
|
43
43
|
extend FFI::Library
|
@@ -47,14 +47,15 @@ describe "Custom type definitions" do
|
|
47
47
|
layout :a, :fubar3_t
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
50
51
|
it "Struct with custom typedef field" do
|
51
52
|
s = StructCustomTypedef::S.new
|
52
53
|
s[:a] = 0x12345678
|
53
|
-
s.pointer.get_uint(0).
|
54
|
+
expect(s.pointer.get_uint(0)).to eq(0x12345678)
|
54
55
|
end
|
55
56
|
|
56
57
|
it "attach_function after a typedef should not reject normal types" do
|
57
|
-
|
58
|
+
expect do
|
58
59
|
Module.new do
|
59
60
|
extend FFI::Library
|
60
61
|
# enum() will insert a custom typedef called :foo for the enum
|
@@ -69,11 +70,11 @@ describe "Custom type definitions" do
|
|
69
70
|
attach_function :ptr_ret_int32_t, :ptr_ret___int32_t, [ :string, :foo ], :bar
|
70
71
|
end
|
71
72
|
end
|
72
|
-
end.
|
73
|
+
end.not_to raise_error
|
73
74
|
end
|
74
75
|
|
75
76
|
it "detects the correct type for size_t" do
|
76
|
-
|
77
|
+
expect do
|
77
78
|
Module.new do
|
78
79
|
extend FFI::Library
|
79
80
|
ffi_lib "c"
|
@@ -85,6 +86,6 @@ describe "Custom type definitions" do
|
|
85
86
|
attach_function :read, [:int, :pointer, :size_t], :ssize_t
|
86
87
|
end
|
87
88
|
end
|
88
|
-
end.
|
89
|
+
end.not_to raise_error
|
89
90
|
end
|
90
91
|
end
|
data/spec/ffi/union_spec.rb
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
#
|
5
5
|
|
6
6
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
7
|
-
require 'ffi'
|
8
7
|
|
9
8
|
module LibTest
|
10
9
|
Types = {
|
@@ -37,16 +36,17 @@ describe 'Union' do
|
|
37
36
|
before do
|
38
37
|
@u = LibTest::TestUnion.new
|
39
38
|
end
|
39
|
+
|
40
40
|
it 'should place all the fields at offset 0' do
|
41
|
-
LibTest::TestUnion.members.all? { |m| LibTest::TestUnion.offset_of(m) == 0 }.
|
41
|
+
expect(LibTest::TestUnion.members.all? { |m| LibTest::TestUnion.offset_of(m) == 0 }).to be true
|
42
42
|
end
|
43
43
|
LibTest::Types.each do |k, type|
|
44
44
|
it "should correctly align/write a #{type[0]} value" do
|
45
45
|
@u[type[1]] = type[2]
|
46
46
|
if k == 'f32' or k == 'f64'
|
47
|
-
(@u[type[1]] - LibTest.send("union_align_#{k}", @u.to_ptr)).abs.
|
47
|
+
expect((@u[type[1]] - LibTest.send("union_align_#{k}", @u.to_ptr)).abs).to be < 0.00001
|
48
48
|
else
|
49
|
-
@u[type[1]].
|
49
|
+
expect(@u[type[1]]).to eq(LibTest.send("union_align_#{k}", @u.to_ptr))
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -54,13 +54,14 @@ describe 'Union' do
|
|
54
54
|
it "should read a #{type[0]} value from memory" do
|
55
55
|
@u = LibTest::TestUnion.new(LibTest.send("union_make_union_with_#{k}", type[2]))
|
56
56
|
if k == 'f32' or k == 'f64'
|
57
|
-
(@u[type[1]] - type[2]).abs.
|
57
|
+
expect((@u[type[1]] - type[2]).abs).to be < 0.00001
|
58
58
|
else
|
59
|
-
@u[type[1]].
|
59
|
+
expect(@u[type[1]]).to eq(type[2])
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
63
64
|
it 'should return a size equals to the size of the biggest field' do
|
64
|
-
LibTest::TestUnion.size.
|
65
|
+
expect(LibTest::TestUnion.size).to eq(LibTest.union_size)
|
65
66
|
end
|
66
67
|
end
|
data/spec/ffi/variadic_spec.rb
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
#
|
5
5
|
|
6
6
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
7
|
-
require 'ffi'
|
8
7
|
|
9
8
|
describe "Function with variadic arguments" do
|
10
9
|
module LibTest
|
@@ -19,41 +18,44 @@ describe "Function with variadic arguments" do
|
|
19
18
|
it "takes enum arguments" do
|
20
19
|
buf = FFI::Buffer.new :long_long, 2
|
21
20
|
LibTest.pack_varargs(buf, "ii", :int, :c3, :int, :c4)
|
22
|
-
buf.get_int64(0).
|
23
|
-
buf.get_int64(8).
|
21
|
+
expect(buf.get_int64(0)).to eq(42)
|
22
|
+
expect(buf.get_int64(8)).to eq(43)
|
24
23
|
end
|
25
24
|
|
26
25
|
it "returns symbols for enums" do
|
27
26
|
buf = FFI::Buffer.new :long_long, 2
|
28
|
-
LibTest.pack_varargs2(buf, :c1, "ii", :int, :c3, :int, :c4).
|
27
|
+
expect(LibTest.pack_varargs2(buf, :c1, "ii", :int, :c3, :int, :c4)).to eq(:c2)
|
29
28
|
end
|
30
29
|
|
31
30
|
[ 0, 127, -128, -1 ].each do |i|
|
32
31
|
it "call variadic with (:char (#{i})) argument" do
|
33
32
|
buf = FFI::Buffer.new :long_long
|
34
33
|
LibTest.pack_varargs(buf, "c", :char, i)
|
35
|
-
buf.get_int64(0).
|
34
|
+
expect(buf.get_int64(0)).to eq(i)
|
36
35
|
end
|
37
36
|
end
|
37
|
+
|
38
38
|
[ 0, 0x7f, 0x80, 0xff ].each do |i|
|
39
39
|
it "call variadic with (:uchar (#{i})) argument" do
|
40
40
|
buf = FFI::Buffer.new :long_long
|
41
41
|
LibTest.pack_varargs(buf, "C", :uchar, i)
|
42
|
-
buf.get_int64(0).
|
42
|
+
expect(buf.get_int64(0)).to eq(i)
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
45
46
|
[ 0, 1.234567, 9.87654321 ].each do |v|
|
46
47
|
it "call variadic with (:float (#{v})) argument" do
|
47
48
|
buf = FFI::Buffer.new :long_long
|
48
49
|
LibTest.pack_varargs(buf, "f", :float, v.to_f)
|
49
|
-
buf.get_float64(0).
|
50
|
+
expect(buf.get_float64(0)).to eq(v)
|
50
51
|
end
|
51
52
|
end
|
53
|
+
|
52
54
|
[ 0, 1.234567, 9.87654321 ].each do |v|
|
53
55
|
it "call variadic with (:double (#{v})) argument" do
|
54
56
|
buf = FFI::Buffer.new :long_long
|
55
57
|
LibTest.pack_varargs(buf, "f", :double, v.to_f)
|
56
|
-
buf.get_float64(0).
|
58
|
+
expect(buf.get_float64(0)).to eq(v)
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
@@ -71,6 +73,7 @@ describe "Function with variadic arguments" do
|
|
71
73
|
'f' => [ 1.23456789 ],
|
72
74
|
'd' => [ 9.87654321 ]
|
73
75
|
}
|
76
|
+
|
74
77
|
TYPE_MAP = {
|
75
78
|
'c' => :char, 'C' => :uchar, 's' => :short, 'S' => :ushort,
|
76
79
|
'i' => :int, 'I' => :uint, 'j' => :long_long, 'J' => :ulong_long,
|
@@ -80,9 +83,9 @@ describe "Function with variadic arguments" do
|
|
80
83
|
|
81
84
|
def verify(p, off, v)
|
82
85
|
if v.kind_of?(Float)
|
83
|
-
p.get_float64(off).
|
86
|
+
expect(p.get_float64(off)).to eq(v)
|
84
87
|
else
|
85
|
-
p.get_int64(off).
|
88
|
+
expect(p.get_int64(off)).to eq(v)
|
86
89
|
end
|
87
90
|
end
|
88
91
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wayne Meissner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09
|
11
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|