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,37 +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 "functions with custom parameter types" do
9
- before :each do
10
-
11
- Custom_enum = Class.new do
12
- extend FFI::DataConverter
13
- ToNativeMap= { :a => 1, :b => 2 }
14
- FromNativeMap = { 1 => :a, 2 => :b }
15
-
16
- def self.native_type
17
- @native_type_called = true
18
- FFI::Type::INT32
19
- end
20
-
21
- def self.to_native(val, ctx)
22
- @to_native_called = true
23
- ToNativeMap[val]
24
- end
25
-
26
- def self.from_native(val, ctx)
27
- @from_native_called = true
28
- FromNativeMap[val]
29
- end
30
- def self.native_type_called?; @native_type_called; end
31
- def self.from_native_called?; @from_native_called; end
32
- def self.to_native_called?; @to_native_called; end
33
- end
34
-
35
- # FIXME add tests
36
- end
37
- end
@@ -1,74 +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 "functions with custom types" do
9
- class Custom_enum
10
- extend FFI::DataConverter
11
- ToNativeMap= { :a => 1, :b => 2, :c => 3 }
12
- FromNativeMap = { 1 => :a, 2 => :b, 3 => :c }
13
-
14
- def self.native_type
15
- @native_type_called = true
16
- FFI::Type::INT32
17
- end
18
-
19
- def self.to_native(val, ctx)
20
- @to_native_called = true
21
- ToNativeMap[val]
22
- end
23
-
24
- def self.from_native(val, ctx)
25
- @from_native_called = true
26
- FromNativeMap[val]
27
- end
28
- def self.native_type_called?; @native_type_called; end
29
- def self.from_native_called?; @from_native_called; end
30
- def self.to_native_called?; @to_native_called; end
31
- end
32
-
33
- it "can attach with custom return type" do
34
- expect do
35
- Module.new do
36
- extend FFI::Library
37
- ffi_lib TestLibrary::PATH
38
- attach_function :ret_s32, [ :int ], Custom_enum
39
- end
40
- end.not_to raise_error
41
- end
42
-
43
- it "should return object of correct type" do
44
-
45
- m = Module.new do
46
-
47
- extend FFI::Library
48
- ffi_lib TestLibrary::PATH
49
- attach_function :ret_s32, [ :int ], Custom_enum
50
- end
51
-
52
- expect(m.ret_s32(1).is_a?(Symbol)).to be true
53
- end
54
-
55
- it "from_native should be called for result" do
56
- m = Module.new do
57
- extend FFI::Library
58
- ffi_lib TestLibrary::PATH
59
- attach_function :ret_s32, [ :int ], Custom_enum
60
- end
61
- m.ret_s32(1)
62
- expect(Custom_enum.from_native_called?).to be true
63
- end
64
-
65
- it "to_native should be called for parameter" do
66
- m = Module.new do
67
- extend FFI::Library
68
- ffi_lib TestLibrary::PATH
69
- attach_function :ret_s32, [ Custom_enum ], :int
70
- end
71
- m.ret_s32(:a)
72
- expect(Custom_enum.to_native_called?).to be true
73
- end
74
- end
@@ -1,52 +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 "Pointer#dup" do
9
- it "clone should be independent" do
10
- p1 = FFI::MemoryPointer.new(:char, 1024)
11
- p1.put_string(0, "test123");
12
- p2 = p1.dup
13
- p1.put_string(0, "deadbeef")
14
-
15
- expect(p2.get_string(0)).to eq("test123")
16
- end
17
-
18
- it "sliced pointer can be cloned" do
19
- p1 = FFI::MemoryPointer.new(:char, 1024)
20
- p1.put_string(0, "test123");
21
- p2 = p1[1].dup
22
-
23
- # first char will be excised
24
- expect(p2.get_string(0)).to eq("est123")
25
- expect(p1.get_string(0)).to eq("test123")
26
- end
27
-
28
- it "sliced pointer when cloned is independent" do
29
- p1 = FFI::MemoryPointer.new(:char, 1024)
30
- p1.put_string(0, "test123");
31
- p2 = p1[1].dup
32
-
33
- p1.put_string(0, "deadbeef")
34
- # first char will be excised
35
- expect(p2.get_string(0)).to eq("est123")
36
- end
37
- end
38
-
39
-
40
- describe "Struct#dup" do
41
- it "clone should be independent" do
42
- s = Class.new(FFI::Struct) do
43
- layout :i, :int
44
- end
45
- s1 = s.new
46
- s1[:i] = 0x12345
47
- s2 = s1.dup
48
- s1[:i] = 0x98765
49
- expect(s2[:i]).to eq(0x12345)
50
- expect(s1[:i]).to eq(0x98765)
51
- end
52
- end
@@ -1,423 +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 TestEnum0
9
- extend FFI::Library
10
- end
11
-
12
- module TestEnum1
13
- extend FFI::Library
14
- ffi_lib TestLibrary::PATH
15
-
16
- enum [:c1, :c2, :c3, :c4]
17
- enum [:c5, 42, :c6, :c7, :c8]
18
- enum [:c9, 42, :c10, :c11, 4242, :c12]
19
- enum [:c13, 42, :c14, 4242, :c15, 424242, :c16, 42424242]
20
-
21
- attach_function :test_untagged_enum, [:int], :int
22
- end
23
-
24
- module TestEnum3
25
- extend FFI::Library
26
- ffi_lib TestLibrary::PATH
27
-
28
- enum :enum_type1, [:c1, :c2, :c3, :c4]
29
- enum :enum_type2, [:c5, 42, :c6, :c7, :c8]
30
- enum :enum_type3, [:c9, 42, :c10, :c11, 4242, :c12]
31
- enum :enum_type4, [:c13, 42, :c14, 4242, :c15, 424242, :c16, 42424242]
32
-
33
- attach_function :test_tagged_typedef_enum1, [:enum_type1], :enum_type1
34
- attach_function :test_tagged_typedef_enum2, [:enum_type2], :enum_type2
35
- attach_function :test_tagged_typedef_enum3, [:enum_type3], :enum_type3
36
- attach_function :test_tagged_typedef_enum4, [:enum_type4], :enum_type4
37
- end
38
-
39
- module TestEnum4
40
- extend FFI::Library
41
- ffi_lib TestLibrary::PATH
42
-
43
- enum [:c1, :c2, :c3, :c4]
44
- enum :enum_type1, [:c5, 0x42, :c6, :c7, :c8]
45
- enum :enum_type2, [:c9, 0x42, :c10, :c11, 0x4242, :c12]
46
- enum :enum_type3, [:c13, 0x42, :c14, 0x4242, :c15, 0x42424242, :c16, 0x4242424242424242]
47
- enum FFI::Type::UINT16, :enum_type4, [:c17, 0x42, :c18, :c19, :c20]
48
- enum FFI::Type::UINT32, :enum_type5, [:c21, 0x42, :c22, :c23, 0x4242, :c24]
49
- enum FFI::Type::UINT64, :enum_type6, [:c25, 0x42, :c26, 0x4242, :c27, 0x42424242, :c28, 0x4242424242424242]
50
- enum FFI::Type::UINT64, [:c29, 0x4242424242424242, :c30, :c31, :c32]
51
-
52
- attach_function :test_untagged_nonint_enum, [:uint8], :uint8
53
- attach_function :test_tagged_nonint_enum1, [:uint16], :uint16
54
- attach_function :test_tagged_nonint_enum2, [:uint32], :uint32
55
- attach_function :test_tagged_nonint_enum3, [:uint64], :uint64
56
- attach_function :test_tagged_nonint_enum4, :test_tagged_nonint_enum1, [:enum_type4], :enum_type4
57
- attach_function :test_tagged_nonint_enum5, :test_tagged_nonint_enum2, [:enum_type5], :enum_type5
58
- attach_function :test_tagged_nonint_enum6, :test_tagged_nonint_enum3, [:enum_type6], :enum_type6
59
- end
60
-
61
- describe "A library with no enum defined" do
62
- it "returns nil when asked for an enum" do
63
- expect(TestEnum0.enum_type(:foo)).to be_nil
64
- end
65
- end
66
-
67
- describe "An untagged enum" do
68
- it "constants can be used as function parameters and return value" do
69
- expect(TestEnum1.test_untagged_enum(:c1)).to eq(0)
70
- expect(TestEnum1.test_untagged_enum(:c2)).to eq(1)
71
- expect(TestEnum1.test_untagged_enum(:c3)).to eq(2)
72
- expect(TestEnum1.test_untagged_enum(:c4)).to eq(3)
73
- expect(TestEnum1.test_untagged_enum(:c5)).to eq(42)
74
- expect(TestEnum1.test_untagged_enum(:c6)).to eq(43)
75
- expect(TestEnum1.test_untagged_enum(:c7)).to eq(44)
76
- expect(TestEnum1.test_untagged_enum(:c8)).to eq(45)
77
- expect(TestEnum1.test_untagged_enum(:c9)).to eq(42)
78
- expect(TestEnum1.test_untagged_enum(:c10)).to eq(43)
79
- expect(TestEnum1.test_untagged_enum(:c11)).to eq(4242)
80
- expect(TestEnum1.test_untagged_enum(:c12)).to eq(4243)
81
- expect(TestEnum1.test_untagged_enum(:c13)).to eq(42)
82
- expect(TestEnum1.test_untagged_enum(:c14)).to eq(4242)
83
- expect(TestEnum1.test_untagged_enum(:c15)).to eq(424242)
84
- expect(TestEnum1.test_untagged_enum(:c16)).to eq(42424242)
85
- expect(TestEnum4.test_untagged_nonint_enum(:c1)).to eq(0)
86
- expect(TestEnum4.test_untagged_nonint_enum(:c2)).to eq(1)
87
- expect(TestEnum4.test_untagged_nonint_enum(:c3)).to eq(2)
88
- expect(TestEnum4.test_untagged_nonint_enum(:c4)).to eq(3)
89
- expect(TestEnum4.test_tagged_nonint_enum3(:c29)).to eq(0x4242424242424242)
90
- expect(TestEnum4.test_tagged_nonint_enum3(:c30)).to eq(0x4242424242424243)
91
- expect(TestEnum4.test_tagged_nonint_enum3(:c31)).to eq(0x4242424242424244)
92
- expect(TestEnum4.test_tagged_nonint_enum3(:c32)).to eq(0x4242424242424245)
93
- end
94
- end
95
-
96
- describe "A tagged typedef enum" do
97
- it "is accessible through its tag" do
98
- expect(TestEnum3.enum_type(:enum_type1)).not_to be_nil
99
- expect(TestEnum3.enum_type(:enum_type2)).not_to be_nil
100
- expect(TestEnum3.enum_type(:enum_type3)).not_to be_nil
101
- expect(TestEnum3.enum_type(:enum_type4)).not_to be_nil
102
- expect(TestEnum4.enum_type(:enum_type1)).not_to be_nil
103
- expect(TestEnum4.enum_type(:enum_type2)).not_to be_nil
104
- expect(TestEnum4.enum_type(:enum_type3)).not_to be_nil
105
- expect(TestEnum4.enum_type(:enum_type4)).not_to be_nil
106
- expect(TestEnum4.enum_type(:enum_type5)).not_to be_nil
107
- expect(TestEnum4.enum_type(:enum_type6)).not_to be_nil
108
- end
109
-
110
- it "contains enum constants" do
111
- expect(TestEnum3.enum_type(:enum_type1).symbols.length).to eq(4)
112
- expect(TestEnum3.enum_type(:enum_type2).symbols.length).to eq(4)
113
- expect(TestEnum3.enum_type(:enum_type3).symbols.length).to eq(4)
114
- expect(TestEnum3.enum_type(:enum_type4).symbols.length).to eq(4)
115
- expect(TestEnum4.enum_type(:enum_type1).symbols.length).to eq(4)
116
- expect(TestEnum4.enum_type(:enum_type2).symbols.length).to eq(4)
117
- expect(TestEnum4.enum_type(:enum_type3).symbols.length).to eq(4)
118
- expect(TestEnum4.enum_type(:enum_type4).symbols.length).to eq(4)
119
- expect(TestEnum4.enum_type(:enum_type5).symbols.length).to eq(4)
120
- expect(TestEnum4.enum_type(:enum_type6).symbols.length).to eq(4)
121
- end
122
-
123
- it "constants can be used as function parameters and return value" do
124
- expect(TestEnum3.test_tagged_typedef_enum1(:c1)).to be :c1
125
- expect(TestEnum3.test_tagged_typedef_enum1(:c2)).to be :c2
126
- expect(TestEnum3.test_tagged_typedef_enum1(:c3)).to be :c3
127
- expect(TestEnum3.test_tagged_typedef_enum1(:c4)).to be :c4
128
- expect(TestEnum3.test_tagged_typedef_enum2(:c5)).to be :c5
129
- expect(TestEnum3.test_tagged_typedef_enum2(:c6)).to be :c6
130
- expect(TestEnum3.test_tagged_typedef_enum2(:c7)).to be :c7
131
- expect(TestEnum3.test_tagged_typedef_enum2(:c8)).to be :c8
132
- expect(TestEnum3.test_tagged_typedef_enum3(:c9)).to be :c9
133
- expect(TestEnum3.test_tagged_typedef_enum3(:c10)).to be :c10
134
- expect(TestEnum3.test_tagged_typedef_enum3(:c11)).to be :c11
135
- expect(TestEnum3.test_tagged_typedef_enum3(:c12)).to be :c12
136
- expect(TestEnum3.test_tagged_typedef_enum4(:c13)).to be :c13
137
- expect(TestEnum3.test_tagged_typedef_enum4(:c14)).to be :c14
138
- expect(TestEnum3.test_tagged_typedef_enum4(:c15)).to be :c15
139
- expect(TestEnum3.test_tagged_typedef_enum4(:c16)).to be :c16
140
- expect(TestEnum4.test_tagged_nonint_enum1(:c5)).to eq(0x42)
141
- expect(TestEnum4.test_tagged_nonint_enum1(:c6)).to eq(0x43)
142
- expect(TestEnum4.test_tagged_nonint_enum1(:c7)).to eq(0x44)
143
- expect(TestEnum4.test_tagged_nonint_enum1(:c8)).to eq(0x45)
144
- expect(TestEnum4.test_tagged_nonint_enum2(:c9)).to eq(0x42)
145
- expect(TestEnum4.test_tagged_nonint_enum2(:c10)).to eq(0x43)
146
- expect(TestEnum4.test_tagged_nonint_enum2(:c11)).to eq(0x4242)
147
- expect(TestEnum4.test_tagged_nonint_enum2(:c12)).to eq(0x4243)
148
- expect(TestEnum4.test_tagged_nonint_enum3(:c13)).to eq(0x42)
149
- expect(TestEnum4.test_tagged_nonint_enum3(:c14)).to eq(0x4242)
150
- expect(TestEnum4.test_tagged_nonint_enum3(:c15)).to eq(0x42424242)
151
- expect(TestEnum4.test_tagged_nonint_enum3(:c16)).to eq(0x4242424242424242)
152
- expect(TestEnum4.test_tagged_nonint_enum4(:c17)).to eq(:c17)
153
- expect(TestEnum4.test_tagged_nonint_enum4(:c18)).to eq(:c18)
154
- expect(TestEnum4.test_tagged_nonint_enum4(:c19)).to eq(:c19)
155
- expect(TestEnum4.test_tagged_nonint_enum4(:c20)).to eq(:c20)
156
- expect(TestEnum4.test_tagged_nonint_enum5(:c21)).to eq(:c21)
157
- expect(TestEnum4.test_tagged_nonint_enum5(:c22)).to eq(:c22)
158
- expect(TestEnum4.test_tagged_nonint_enum5(:c23)).to eq(:c23)
159
- expect(TestEnum4.test_tagged_nonint_enum5(:c24)).to eq(:c24)
160
- expect(TestEnum4.test_tagged_nonint_enum6(:c25)).to eq(:c25)
161
- expect(TestEnum4.test_tagged_nonint_enum6(:c26)).to eq(:c26)
162
- expect(TestEnum4.test_tagged_nonint_enum6(:c27)).to eq(:c27)
163
- expect(TestEnum4.test_tagged_nonint_enum6(:c28)).to eq(:c28)
164
- end
165
-
166
- it "integers can be used instead of constants" do
167
- expect(TestEnum3.test_tagged_typedef_enum1(0)).to be :c1
168
- expect(TestEnum3.test_tagged_typedef_enum1(1)).to be :c2
169
- expect(TestEnum3.test_tagged_typedef_enum1(2)).to be :c3
170
- expect(TestEnum3.test_tagged_typedef_enum1(3)).to be :c4
171
- expect(TestEnum3.test_tagged_typedef_enum2(42)).to be :c5
172
- expect(TestEnum3.test_tagged_typedef_enum2(43)).to be :c6
173
- expect(TestEnum3.test_tagged_typedef_enum2(44)).to be :c7
174
- expect(TestEnum3.test_tagged_typedef_enum2(45)).to be :c8
175
- expect(TestEnum3.test_tagged_typedef_enum3(42)).to be :c9
176
- expect(TestEnum3.test_tagged_typedef_enum3(43)).to be :c10
177
- expect(TestEnum3.test_tagged_typedef_enum3(4242)).to be :c11
178
- expect(TestEnum3.test_tagged_typedef_enum3(4243)).to be :c12
179
- expect(TestEnum3.test_tagged_typedef_enum4(42)).to be :c13
180
- expect(TestEnum3.test_tagged_typedef_enum4(4242)).to be :c14
181
- expect(TestEnum3.test_tagged_typedef_enum4(424242)).to be :c15
182
- expect(TestEnum3.test_tagged_typedef_enum4(42424242)).to be :c16
183
- expect(TestEnum4.test_tagged_nonint_enum4(0x42)).to eq(:c17)
184
- expect(TestEnum4.test_tagged_nonint_enum4(0x43)).to eq(:c18)
185
- expect(TestEnum4.test_tagged_nonint_enum4(0x44)).to eq(:c19)
186
- expect(TestEnum4.test_tagged_nonint_enum4(0x45)).to eq(:c20)
187
- expect(TestEnum4.test_tagged_nonint_enum5(0x42)).to eq(:c21)
188
- expect(TestEnum4.test_tagged_nonint_enum5(0x43)).to eq(:c22)
189
- expect(TestEnum4.test_tagged_nonint_enum5(0x4242)).to eq(:c23)
190
- expect(TestEnum4.test_tagged_nonint_enum5(0x4243)).to eq(:c24)
191
- expect(TestEnum4.test_tagged_nonint_enum6(0x42)).to eq(:c25)
192
- expect(TestEnum4.test_tagged_nonint_enum6(0x4242)).to eq(:c26)
193
- expect(TestEnum4.test_tagged_nonint_enum6(0x42424242)).to eq(:c27)
194
- expect(TestEnum4.test_tagged_nonint_enum6(0x4242424242424242)).to eq(:c28)
195
- end
196
- end
197
-
198
- describe "All enums" do
199
- it "have autonumbered constants when defined with names only" do
200
- expect(TestEnum1.enum_value(:c1)).to eq(0)
201
- expect(TestEnum1.enum_value(:c2)).to eq(1)
202
- expect(TestEnum1.enum_value(:c3)).to eq(2)
203
- expect(TestEnum1.enum_value(:c4)).to eq(3)
204
-
205
- expect(TestEnum3.enum_value(:c1)).to eq(0)
206
- expect(TestEnum3.enum_value(:c2)).to eq(1)
207
- expect(TestEnum3.enum_value(:c3)).to eq(2)
208
- expect(TestEnum3.enum_value(:c4)).to eq(3)
209
-
210
- expect(TestEnum4.enum_value(:c1)).to eq(0)
211
- expect(TestEnum4.enum_value(:c2)).to eq(1)
212
- expect(TestEnum4.enum_value(:c3)).to eq(2)
213
- expect(TestEnum4.enum_value(:c4)).to eq(3)
214
- end
215
-
216
- it "can have an explicit first constant and autonumbered subsequent constants" do
217
- expect(TestEnum1.enum_value(:c5)).to eq(42)
218
- expect(TestEnum1.enum_value(:c6)).to eq(43)
219
- expect(TestEnum1.enum_value(:c7)).to eq(44)
220
- expect(TestEnum1.enum_value(:c8)).to eq(45)
221
-
222
- expect(TestEnum3.enum_value(:c5)).to eq(42)
223
- expect(TestEnum3.enum_value(:c6)).to eq(43)
224
- expect(TestEnum3.enum_value(:c7)).to eq(44)
225
- expect(TestEnum3.enum_value(:c8)).to eq(45)
226
-
227
- expect(TestEnum4.enum_value(:c5)).to eq(0x42)
228
- expect(TestEnum4.enum_value(:c6)).to eq(0x43)
229
- expect(TestEnum4.enum_value(:c7)).to eq(0x44)
230
- expect(TestEnum4.enum_value(:c8)).to eq(0x45)
231
-
232
- expect(TestEnum4.enum_value(:c29)).to eq(0x4242424242424242)
233
- expect(TestEnum4.enum_value(:c30)).to eq(0x4242424242424243)
234
- expect(TestEnum4.enum_value(:c31)).to eq(0x4242424242424244)
235
- expect(TestEnum4.enum_value(:c32)).to eq(0x4242424242424245)
236
- end
237
-
238
- it "can have a mix of explicit and autonumbered constants" do
239
- expect(TestEnum1.enum_value(:c9)).to eq(42)
240
- expect(TestEnum1.enum_value(:c10)).to eq(43)
241
- expect(TestEnum1.enum_value(:c11)).to eq(4242)
242
- expect(TestEnum1.enum_value(:c12)).to eq(4243)
243
-
244
- expect(TestEnum3.enum_value(:c9)).to eq(42)
245
- expect(TestEnum3.enum_value(:c10)).to eq(43)
246
- expect(TestEnum3.enum_value(:c11)).to eq(4242)
247
- expect(TestEnum3.enum_value(:c12)).to eq(4243)
248
-
249
- expect(TestEnum4.enum_value(:c9)).to eq(0x42)
250
- expect(TestEnum4.enum_value(:c10)).to eq(0x43)
251
- expect(TestEnum4.enum_value(:c11)).to eq(0x4242)
252
- expect(TestEnum4.enum_value(:c12)).to eq(0x4243)
253
-
254
- expect(TestEnum4.enum_value(:c21)).to eq(0x42)
255
- expect(TestEnum4.enum_value(:c22)).to eq(0x43)
256
- expect(TestEnum4.enum_value(:c23)).to eq(0x4242)
257
- expect(TestEnum4.enum_value(:c24)).to eq(0x4243)
258
- end
259
-
260
- it "can have all its constants explicitely valued" do
261
- expect(TestEnum1.enum_value(:c13)).to eq(42)
262
- expect(TestEnum1.enum_value(:c14)).to eq(4242)
263
- expect(TestEnum1.enum_value(:c15)).to eq(424242)
264
- expect(TestEnum1.enum_value(:c16)).to eq(42424242)
265
-
266
- expect(TestEnum3.enum_value(:c13)).to eq(42)
267
- expect(TestEnum3.enum_value(:c14)).to eq(4242)
268
- expect(TestEnum3.enum_value(:c15)).to eq(424242)
269
- expect(TestEnum3.enum_value(:c16)).to eq(42424242)
270
-
271
- expect(TestEnum4.enum_value(:c13)).to eq(0x42)
272
- expect(TestEnum4.enum_value(:c14)).to eq(0x4242)
273
- expect(TestEnum4.enum_value(:c15)).to eq(0x42424242)
274
- expect(TestEnum4.enum_value(:c16)).to eq(0x4242424242424242)
275
-
276
- expect(TestEnum4.enum_value(:c25)).to eq(0x42)
277
- expect(TestEnum4.enum_value(:c26)).to eq(0x4242)
278
- expect(TestEnum4.enum_value(:c27)).to eq(0x42424242)
279
- expect(TestEnum4.enum_value(:c28)).to eq(0x4242424242424242)
280
- end
281
-
282
- it "return the constant corresponding to a specific value" do
283
- enum = TestEnum3.enum_type(:enum_type1)
284
- expect(enum[0]).to be :c1
285
- expect(enum[1]).to be :c2
286
- expect(enum[2]).to be :c3
287
- expect(enum[3]).to be :c4
288
-
289
- enum = TestEnum3.enum_type(:enum_type2)
290
- expect(enum[42]).to be :c5
291
- expect(enum[43]).to be :c6
292
- expect(enum[44]).to be :c7
293
- expect(enum[45]).to be :c8
294
-
295
- enum = TestEnum3.enum_type(:enum_type3)
296
- expect(enum[42]).to be :c9
297
- expect(enum[43]).to be :c10
298
- expect(enum[4242]).to be :c11
299
- expect(enum[4243]).to be :c12
300
-
301
- enum = TestEnum3.enum_type(:enum_type4)
302
- expect(enum[42]).to be :c13
303
- expect(enum[4242]).to be :c14
304
- expect(enum[424242]).to be :c15
305
- expect(enum[42424242]).to be :c16
306
-
307
- enum = TestEnum4.enum_type(:enum_type1)
308
- expect(enum[0x42]).to eq(:c5)
309
- expect(enum[0x43]).to eq(:c6)
310
- expect(enum[0x44]).to eq(:c7)
311
- expect(enum[0x45]).to eq(:c8)
312
-
313
- enum = TestEnum4.enum_type(:enum_type2)
314
- expect(enum[0x42]).to eq(:c9)
315
- expect(enum[0x43]).to eq(:c10)
316
- expect(enum[0x4242]).to eq(:c11)
317
- expect(enum[0x4243]).to eq(:c12)
318
-
319
- enum = TestEnum4.enum_type(:enum_type3)
320
- expect(enum[0x42]).to eq(:c13)
321
- expect(enum[0x4242]).to eq(:c14)
322
- expect(enum[0x42424242]).to eq(:c15)
323
- expect(enum[0x4242424242424242]).to eq(:c16)
324
-
325
- enum = TestEnum4.enum_type(:enum_type4)
326
- expect(enum[0x42]).to eq(:c17)
327
- expect(enum[0x43]).to eq(:c18)
328
- expect(enum[0x44]).to eq(:c19)
329
- expect(enum[0x45]).to eq(:c20)
330
-
331
- enum = TestEnum4.enum_type(:enum_type5)
332
- expect(enum[0x42]).to eq(:c21)
333
- expect(enum[0x43]).to eq(:c22)
334
- expect(enum[0x4242]).to eq(:c23)
335
- expect(enum[0x4243]).to eq(:c24)
336
-
337
- enum = TestEnum4.enum_type(:enum_type6)
338
- expect(enum[0x42]).to eq(:c25)
339
- expect(enum[0x4242]).to eq(:c26)
340
- expect(enum[0x42424242]).to eq(:c27)
341
- expect(enum[0x4242424242424242]).to eq(:c28)
342
- end
343
-
344
- it "return nil for values that don't have a symbol" do
345
- enum = TestEnum3.enum_type(:enum_type1)
346
- expect(enum[-1]).to be_nil
347
- expect(enum[4]).to be_nil
348
-
349
- enum = TestEnum3.enum_type(:enum_type2)
350
- expect(enum[0]).to be_nil
351
- expect(enum[41]).to be_nil
352
- expect(enum[46]).to be_nil
353
-
354
- enum = TestEnum3.enum_type(:enum_type3)
355
- expect(enum[0]).to be_nil
356
- expect(enum[41]).to be_nil
357
- expect(enum[44]).to be_nil
358
- expect(enum[4241]).to be_nil
359
- expect(enum[4244]).to be_nil
360
-
361
- enum = TestEnum3.enum_type(:enum_type4)
362
- expect(enum[0]).to be_nil
363
- expect(enum[41]).to be_nil
364
- expect(enum[43]).to be_nil
365
- expect(enum[4241]).to be_nil
366
- expect(enum[4243]).to be_nil
367
- expect(enum[424241]).to be_nil
368
- expect(enum[424243]).to be_nil
369
- expect(enum[42424241]).to be_nil
370
- expect(enum[42424243]).to be_nil
371
-
372
- enum = TestEnum4.enum_type(:enum_type1)
373
- expect(enum[0x0]).to be_nil
374
- expect(enum[0x41]).to be_nil
375
- expect(enum[0x46]).to be_nil
376
-
377
- enum = TestEnum4.enum_type(:enum_type2)
378
- expect(enum[0x0]).to be_nil
379
- expect(enum[0x41]).to be_nil
380
- expect(enum[0x44]).to be_nil
381
- expect(enum[0x4241]).to be_nil
382
- expect(enum[0x4244]).to be_nil
383
-
384
- enum = TestEnum4.enum_type(:enum_type3)
385
- expect(enum[0x0]).to be_nil
386
- expect(enum[0x41]).to be_nil
387
- expect(enum[0x43]).to be_nil
388
- expect(enum[0x4241]).to be_nil
389
- expect(enum[0x4243]).to be_nil
390
- expect(enum[0x42424241]).to be_nil
391
- expect(enum[0x42424243]).to be_nil
392
- expect(enum[0x4242424242424241]).to be_nil
393
- expect(enum[0x4242424242424243]).to be_nil
394
-
395
- enum = TestEnum4.enum_type(:enum_type4)
396
- expect(enum[0x0]).to be_nil
397
- expect(enum[0x41]).to be_nil
398
- expect(enum[0x46]).to be_nil
399
-
400
- enum = TestEnum4.enum_type(:enum_type5)
401
- expect(enum[0x0]).to be_nil
402
- expect(enum[0x41]).to be_nil
403
- expect(enum[0x44]).to be_nil
404
- expect(enum[0x4241]).to be_nil
405
- expect(enum[0x4244]).to be_nil
406
-
407
- enum = TestEnum4.enum_type(:enum_type6)
408
- expect(enum[0x0]).to be_nil
409
- expect(enum[0x41]).to be_nil
410
- expect(enum[0x43]).to be_nil
411
- expect(enum[0x4241]).to be_nil
412
- expect(enum[0x4243]).to be_nil
413
- expect(enum[0x42424241]).to be_nil
414
- expect(enum[0x42424243]).to be_nil
415
- expect(enum[0x4242424242424241]).to be_nil
416
- expect(enum[0x4242424242424243]).to be_nil
417
- end
418
-
419
- it "duplicate enum keys rejected" do
420
- expect { enum [ :a, 0xfee1dead, :b, 0xdeadbeef, :a, 0 ] }.to raise_error
421
- expect { enum FFI::Type::UINT64, [ :a, 0xfee1dead, :b, 0xdeadbeef, :a, 0 ] }.to raise_error
422
- end
423
- end