ffi 1.9.6 → 1.9.8
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/README.md +1 -1
- data/Rakefile +9 -9
- data/ext/ffi_c/Call.c +85 -20
- data/ext/ffi_c/Variadic.c +6 -2
- data/ext/ffi_c/libffi/src/x86/win32.S +2 -2
- data/ffi.gemspec +1 -1
- data/lib/ffi.rb +6 -4
- data/lib/ffi/enum.rb +12 -6
- data/lib/ffi/library.rb +21 -1
- data/lib/ffi/platform.rb +2 -0
- data/lib/ffi/platform/aarch64-linux/types.conf +104 -0
- data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
- data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
- data/lib/ffi/platform/x86_64-darwin/types.conf +30 -4
- data/lib/ffi/struct.rb +6 -0
- data/lib/ffi/version.rb +1 -1
- data/libtest/EnumTest.c +17 -0
- data/spec/ffi/enum_spec.rb +196 -0
- data/spec/ffi/fixtures/EnumTest.c +17 -0
- data/spec/ffi/function_spec.rb +7 -4
- metadata +6 -18
- data/spec/ffi/fixtures/Benchmark.o +0 -0
- data/spec/ffi/fixtures/BoolTest.o +0 -0
- data/spec/ffi/fixtures/BufferTest.o +0 -0
- data/spec/ffi/fixtures/ClosureTest.o +0 -0
- data/spec/ffi/fixtures/EnumTest.o +0 -0
- data/spec/ffi/fixtures/FunctionTest.o +0 -0
- data/spec/ffi/fixtures/GlobalVariable.o +0 -0
- data/spec/ffi/fixtures/LastErrorTest.o +0 -0
- data/spec/ffi/fixtures/NumberTest.o +0 -0
- data/spec/ffi/fixtures/PointerTest.o +0 -0
- data/spec/ffi/fixtures/ReferenceTest.o +0 -0
- data/spec/ffi/fixtures/StringTest.o +0 -0
- data/spec/ffi/fixtures/StructTest.o +0 -0
- data/spec/ffi/fixtures/UnionTest.o +0 -0
- data/spec/ffi/fixtures/VariadicTest.o +0 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
rbx.platform.typedef.__u_char = uchar
|
2
|
+
rbx.platform.typedef.__u_short = ushort
|
3
|
+
rbx.platform.typedef.__u_int = uint
|
4
|
+
rbx.platform.typedef.__u_long = ulong
|
5
|
+
rbx.platform.typedef.__int8_t = char
|
6
|
+
rbx.platform.typedef.__uint8_t = uchar
|
7
|
+
rbx.platform.typedef.__int16_t = short
|
8
|
+
rbx.platform.typedef.__uint16_t = ushort
|
9
|
+
rbx.platform.typedef.__int32_t = int
|
10
|
+
rbx.platform.typedef.__uint32_t = uint
|
11
|
+
rbx.platform.typedef.__int64_t = long
|
12
|
+
rbx.platform.typedef.__uint64_t = ulong
|
13
|
+
rbx.platform.typedef.__quad_t = long
|
14
|
+
rbx.platform.typedef.__u_quad_t = ulong
|
15
|
+
rbx.platform.typedef.__dev_t = ulong
|
16
|
+
rbx.platform.typedef.__uid_t = uint
|
17
|
+
rbx.platform.typedef.__gid_t = uint
|
18
|
+
rbx.platform.typedef.__ino_t = ulong
|
19
|
+
rbx.platform.typedef.__ino64_t = ulong
|
20
|
+
rbx.platform.typedef.__mode_t = uint
|
21
|
+
rbx.platform.typedef.__nlink_t = ulong
|
22
|
+
rbx.platform.typedef.__off_t = long
|
23
|
+
rbx.platform.typedef.__off64_t = long
|
24
|
+
rbx.platform.typedef.__pid_t = int
|
25
|
+
rbx.platform.typedef.__clock_t = long
|
26
|
+
rbx.platform.typedef.__rlim_t = ulong
|
27
|
+
rbx.platform.typedef.__rlim64_t = ulong
|
28
|
+
rbx.platform.typedef.__id_t = uint
|
29
|
+
rbx.platform.typedef.__time_t = long
|
30
|
+
rbx.platform.typedef.__useconds_t = uint
|
31
|
+
rbx.platform.typedef.__suseconds_t = long
|
32
|
+
rbx.platform.typedef.__daddr_t = int
|
33
|
+
rbx.platform.typedef.__key_t = int
|
34
|
+
rbx.platform.typedef.__clockid_t = int
|
35
|
+
rbx.platform.typedef.__timer_t = pointer
|
36
|
+
rbx.platform.typedef.__blksize_t = long
|
37
|
+
rbx.platform.typedef.__blkcnt_t = long
|
38
|
+
rbx.platform.typedef.__blkcnt64_t = long
|
39
|
+
rbx.platform.typedef.__fsblkcnt_t = ulong
|
40
|
+
rbx.platform.typedef.__fsblkcnt64_t = ulong
|
41
|
+
rbx.platform.typedef.__fsfilcnt_t = ulong
|
42
|
+
rbx.platform.typedef.__fsfilcnt64_t = ulong
|
43
|
+
rbx.platform.typedef.__fsword_t = long
|
44
|
+
rbx.platform.typedef.__ssize_t = long
|
45
|
+
rbx.platform.typedef.__syscall_slong_t = long
|
46
|
+
rbx.platform.typedef.__syscall_ulong_t = ulong
|
47
|
+
rbx.platform.typedef.__loff_t = long
|
48
|
+
rbx.platform.typedef.*__qaddr_t = long
|
49
|
+
rbx.platform.typedef.*__caddr_t = char
|
50
|
+
rbx.platform.typedef.__intptr_t = long
|
51
|
+
rbx.platform.typedef.__socklen_t = uint
|
52
|
+
rbx.platform.typedef.u_char = uchar
|
53
|
+
rbx.platform.typedef.u_short = ushort
|
54
|
+
rbx.platform.typedef.u_int = uint
|
55
|
+
rbx.platform.typedef.u_long = ulong
|
56
|
+
rbx.platform.typedef.quad_t = long
|
57
|
+
rbx.platform.typedef.u_quad_t = ulong
|
58
|
+
rbx.platform.typedef.loff_t = long
|
59
|
+
rbx.platform.typedef.ino_t = ulong
|
60
|
+
rbx.platform.typedef.dev_t = ulong
|
61
|
+
rbx.platform.typedef.gid_t = uint
|
62
|
+
rbx.platform.typedef.mode_t = uint
|
63
|
+
rbx.platform.typedef.nlink_t = ulong
|
64
|
+
rbx.platform.typedef.uid_t = uint
|
65
|
+
rbx.platform.typedef.off_t = long
|
66
|
+
rbx.platform.typedef.pid_t = int
|
67
|
+
rbx.platform.typedef.id_t = uint
|
68
|
+
rbx.platform.typedef.ssize_t = long
|
69
|
+
rbx.platform.typedef.daddr_t = int
|
70
|
+
rbx.platform.typedef.key_t = int
|
71
|
+
rbx.platform.typedef.clock_t = long
|
72
|
+
rbx.platform.typedef.time_t = long
|
73
|
+
rbx.platform.typedef.clockid_t = int
|
74
|
+
rbx.platform.typedef.timer_t = pointer
|
75
|
+
rbx.platform.typedef.size_t = ulong
|
76
|
+
rbx.platform.typedef.ulong = ulong
|
77
|
+
rbx.platform.typedef.ushort = ushort
|
78
|
+
rbx.platform.typedef.uint = uint
|
79
|
+
rbx.platform.typedef.int8_t = char
|
80
|
+
rbx.platform.typedef.int16_t = short
|
81
|
+
rbx.platform.typedef.int32_t = int
|
82
|
+
rbx.platform.typedef.int64_t = long_long
|
83
|
+
rbx.platform.typedef.u_int8_t = uchar
|
84
|
+
rbx.platform.typedef.u_int16_t = ushort
|
85
|
+
rbx.platform.typedef.u_int32_t = uint
|
86
|
+
rbx.platform.typedef.u_int64_t = ulong_long
|
87
|
+
rbx.platform.typedef.register_t = long
|
88
|
+
rbx.platform.typedef.__sig_atomic_t = int
|
89
|
+
rbx.platform.typedef.suseconds_t = long
|
90
|
+
rbx.platform.typedef.__fd_mask = long
|
91
|
+
rbx.platform.typedef.fd_mask = long
|
92
|
+
rbx.platform.typedef.blksize_t = long
|
93
|
+
rbx.platform.typedef.blkcnt_t = long
|
94
|
+
rbx.platform.typedef.fsblkcnt_t = ulong
|
95
|
+
rbx.platform.typedef.fsfilcnt_t = ulong
|
96
|
+
rbx.platform.typedef.pthread_t = ulong
|
97
|
+
rbx.platform.typedef.pthread_key_t = uint
|
98
|
+
rbx.platform.typedef.pthread_once_t = int
|
99
|
+
rbx.platform.typedef.socklen_t = uint
|
100
|
+
rbx.platform.typedef.sa_family_t = ushort
|
101
|
+
rbx.platform.typedef.rlim_t = ulong
|
102
|
+
rbx.platform.typedef.__rlimit_resource_t = int
|
103
|
+
rbx.platform.typedef.__rusage_who_t = int
|
104
|
+
rbx.platform.typedef.__priority_which_t = int
|
@@ -0,0 +1,104 @@
|
|
1
|
+
rbx.platform.typedef.__u_char = uchar
|
2
|
+
rbx.platform.typedef.__u_short = ushort
|
3
|
+
rbx.platform.typedef.__u_int = uint
|
4
|
+
rbx.platform.typedef.__u_long = ulong
|
5
|
+
rbx.platform.typedef.__int8_t = char
|
6
|
+
rbx.platform.typedef.__uint8_t = uchar
|
7
|
+
rbx.platform.typedef.__int16_t = short
|
8
|
+
rbx.platform.typedef.__uint16_t = ushort
|
9
|
+
rbx.platform.typedef.__int32_t = int
|
10
|
+
rbx.platform.typedef.__uint32_t = uint
|
11
|
+
rbx.platform.typedef.__int64_t = long
|
12
|
+
rbx.platform.typedef.__uint64_t = ulong
|
13
|
+
rbx.platform.typedef.__quad_t = long
|
14
|
+
rbx.platform.typedef.__u_quad_t = ulong
|
15
|
+
rbx.platform.typedef.__dev_t = ulong
|
16
|
+
rbx.platform.typedef.__uid_t = uint
|
17
|
+
rbx.platform.typedef.__gid_t = uint
|
18
|
+
rbx.platform.typedef.__ino_t = ulong
|
19
|
+
rbx.platform.typedef.__ino64_t = ulong
|
20
|
+
rbx.platform.typedef.__mode_t = uint
|
21
|
+
rbx.platform.typedef.__nlink_t = ulong
|
22
|
+
rbx.platform.typedef.__off_t = long
|
23
|
+
rbx.platform.typedef.__off64_t = long
|
24
|
+
rbx.platform.typedef.__pid_t = int
|
25
|
+
rbx.platform.typedef.__clock_t = long
|
26
|
+
rbx.platform.typedef.__rlim_t = ulong
|
27
|
+
rbx.platform.typedef.__rlim64_t = ulong
|
28
|
+
rbx.platform.typedef.__id_t = uint
|
29
|
+
rbx.platform.typedef.__time_t = long
|
30
|
+
rbx.platform.typedef.__useconds_t = uint
|
31
|
+
rbx.platform.typedef.__suseconds_t = long
|
32
|
+
rbx.platform.typedef.__daddr_t = int
|
33
|
+
rbx.platform.typedef.__key_t = int
|
34
|
+
rbx.platform.typedef.__clockid_t = int
|
35
|
+
rbx.platform.typedef.__timer_t = pointer
|
36
|
+
rbx.platform.typedef.__blksize_t = long
|
37
|
+
rbx.platform.typedef.__blkcnt_t = long
|
38
|
+
rbx.platform.typedef.__blkcnt64_t = long
|
39
|
+
rbx.platform.typedef.__fsblkcnt_t = ulong
|
40
|
+
rbx.platform.typedef.__fsblkcnt64_t = ulong
|
41
|
+
rbx.platform.typedef.__fsfilcnt_t = ulong
|
42
|
+
rbx.platform.typedef.__fsfilcnt64_t = ulong
|
43
|
+
rbx.platform.typedef.__fsword_t = long
|
44
|
+
rbx.platform.typedef.__ssize_t = long
|
45
|
+
rbx.platform.typedef.__syscall_slong_t = long
|
46
|
+
rbx.platform.typedef.__syscall_ulong_t = ulong
|
47
|
+
rbx.platform.typedef.__loff_t = long
|
48
|
+
rbx.platform.typedef.*__qaddr_t = long
|
49
|
+
rbx.platform.typedef.*__caddr_t = char
|
50
|
+
rbx.platform.typedef.__intptr_t = long
|
51
|
+
rbx.platform.typedef.__socklen_t = uint
|
52
|
+
rbx.platform.typedef.u_char = uchar
|
53
|
+
rbx.platform.typedef.u_short = ushort
|
54
|
+
rbx.platform.typedef.u_int = uint
|
55
|
+
rbx.platform.typedef.u_long = ulong
|
56
|
+
rbx.platform.typedef.quad_t = long
|
57
|
+
rbx.platform.typedef.u_quad_t = ulong
|
58
|
+
rbx.platform.typedef.loff_t = long
|
59
|
+
rbx.platform.typedef.ino_t = ulong
|
60
|
+
rbx.platform.typedef.dev_t = ulong
|
61
|
+
rbx.platform.typedef.gid_t = uint
|
62
|
+
rbx.platform.typedef.mode_t = uint
|
63
|
+
rbx.platform.typedef.nlink_t = ulong
|
64
|
+
rbx.platform.typedef.uid_t = uint
|
65
|
+
rbx.platform.typedef.off_t = long
|
66
|
+
rbx.platform.typedef.pid_t = int
|
67
|
+
rbx.platform.typedef.id_t = uint
|
68
|
+
rbx.platform.typedef.ssize_t = long
|
69
|
+
rbx.platform.typedef.daddr_t = int
|
70
|
+
rbx.platform.typedef.key_t = int
|
71
|
+
rbx.platform.typedef.clock_t = long
|
72
|
+
rbx.platform.typedef.time_t = long
|
73
|
+
rbx.platform.typedef.clockid_t = int
|
74
|
+
rbx.platform.typedef.timer_t = pointer
|
75
|
+
rbx.platform.typedef.size_t = ulong
|
76
|
+
rbx.platform.typedef.ulong = ulong
|
77
|
+
rbx.platform.typedef.ushort = ushort
|
78
|
+
rbx.platform.typedef.uint = uint
|
79
|
+
rbx.platform.typedef.int8_t = char
|
80
|
+
rbx.platform.typedef.int16_t = short
|
81
|
+
rbx.platform.typedef.int32_t = int
|
82
|
+
rbx.platform.typedef.int64_t = long_long
|
83
|
+
rbx.platform.typedef.u_int8_t = uchar
|
84
|
+
rbx.platform.typedef.u_int16_t = ushort
|
85
|
+
rbx.platform.typedef.u_int32_t = uint
|
86
|
+
rbx.platform.typedef.u_int64_t = ulong_long
|
87
|
+
rbx.platform.typedef.register_t = long
|
88
|
+
rbx.platform.typedef.__sig_atomic_t = int
|
89
|
+
rbx.platform.typedef.suseconds_t = long
|
90
|
+
rbx.platform.typedef.__fd_mask = long
|
91
|
+
rbx.platform.typedef.fd_mask = long
|
92
|
+
rbx.platform.typedef.blksize_t = long
|
93
|
+
rbx.platform.typedef.blkcnt_t = long
|
94
|
+
rbx.platform.typedef.fsblkcnt_t = ulong
|
95
|
+
rbx.platform.typedef.fsfilcnt_t = ulong
|
96
|
+
rbx.platform.typedef.pthread_t = ulong
|
97
|
+
rbx.platform.typedef.pthread_key_t = uint
|
98
|
+
rbx.platform.typedef.pthread_once_t = int
|
99
|
+
rbx.platform.typedef.socklen_t = uint
|
100
|
+
rbx.platform.typedef.sa_family_t = ushort
|
101
|
+
rbx.platform.typedef.rlim_t = ulong
|
102
|
+
rbx.platform.typedef.__rlimit_resource_t = int
|
103
|
+
rbx.platform.typedef.__rusage_who_t = int
|
104
|
+
rbx.platform.typedef.__priority_which_t = int
|
@@ -19,12 +19,12 @@ rbx.platform.typedef.__darwin_socklen_t = uint
|
|
19
19
|
rbx.platform.typedef.__darwin_ssize_t = long
|
20
20
|
rbx.platform.typedef.__darwin_time_t = long
|
21
21
|
rbx.platform.typedef.int8_t = char
|
22
|
-
rbx.platform.typedef.u_int8_t = uchar
|
23
22
|
rbx.platform.typedef.int16_t = short
|
24
|
-
rbx.platform.typedef.u_int16_t = ushort
|
25
23
|
rbx.platform.typedef.int32_t = int
|
26
|
-
rbx.platform.typedef.u_int32_t = uint
|
27
24
|
rbx.platform.typedef.int64_t = long_long
|
25
|
+
rbx.platform.typedef.u_int8_t = uchar
|
26
|
+
rbx.platform.typedef.u_int16_t = ushort
|
27
|
+
rbx.platform.typedef.u_int32_t = uint
|
28
28
|
rbx.platform.typedef.u_int64_t = ulong_long
|
29
29
|
rbx.platform.typedef.register_t = long_long
|
30
30
|
rbx.platform.typedef.intptr_t = long
|
@@ -35,6 +35,7 @@ rbx.platform.typedef.user_ssize_t = long_long
|
|
35
35
|
rbx.platform.typedef.user_long_t = long_long
|
36
36
|
rbx.platform.typedef.user_ulong_t = ulong_long
|
37
37
|
rbx.platform.typedef.user_time_t = long_long
|
38
|
+
rbx.platform.typedef.user_off_t = long_long
|
38
39
|
rbx.platform.typedef.syscall_arg_t = ulong_long
|
39
40
|
rbx.platform.typedef.__darwin_blkcnt_t = long_long
|
40
41
|
rbx.platform.typedef.__darwin_blksize_t = int
|
@@ -50,12 +51,13 @@ rbx.platform.typedef.__darwin_mach_port_t = uint
|
|
50
51
|
rbx.platform.typedef.__darwin_mode_t = ushort
|
51
52
|
rbx.platform.typedef.__darwin_off_t = long_long
|
52
53
|
rbx.platform.typedef.__darwin_pid_t = int
|
53
|
-
rbx.platform.typedef.__darwin_pthread_key_t = ulong
|
54
54
|
rbx.platform.typedef.__darwin_sigset_t = uint
|
55
55
|
rbx.platform.typedef.__darwin_suseconds_t = int
|
56
56
|
rbx.platform.typedef.__darwin_uid_t = uint
|
57
57
|
rbx.platform.typedef.__darwin_useconds_t = uint
|
58
58
|
rbx.platform.typedef.__darwin_uuid_t[16] = uchar
|
59
|
+
rbx.platform.typedef.__darwin_uuid_string_t[37] = char
|
60
|
+
rbx.platform.typedef.__darwin_pthread_key_t = ulong
|
59
61
|
rbx.platform.typedef.u_char = uchar
|
60
62
|
rbx.platform.typedef.u_short = ushort
|
61
63
|
rbx.platform.typedef.u_int = uint
|
@@ -91,10 +93,34 @@ rbx.platform.typedef.ssize_t = long
|
|
91
93
|
rbx.platform.typedef.time_t = long
|
92
94
|
rbx.platform.typedef.useconds_t = uint
|
93
95
|
rbx.platform.typedef.suseconds_t = int
|
96
|
+
rbx.platform.typedef.rsize_t = ulong
|
97
|
+
rbx.platform.typedef.errno_t = int
|
94
98
|
rbx.platform.typedef.fd_mask = int
|
95
99
|
rbx.platform.typedef.pthread_key_t = ulong
|
96
100
|
rbx.platform.typedef.fsblkcnt_t = uint
|
97
101
|
rbx.platform.typedef.fsfilcnt_t = uint
|
98
102
|
rbx.platform.typedef.sa_family_t = uchar
|
99
103
|
rbx.platform.typedef.socklen_t = uint
|
104
|
+
rbx.platform.typedef.uint8_t = uchar
|
105
|
+
rbx.platform.typedef.uint16_t = ushort
|
106
|
+
rbx.platform.typedef.uint32_t = uint
|
107
|
+
rbx.platform.typedef.uint64_t = ulong_long
|
108
|
+
rbx.platform.typedef.int_least8_t = char
|
109
|
+
rbx.platform.typedef.int_least16_t = short
|
110
|
+
rbx.platform.typedef.int_least32_t = int
|
111
|
+
rbx.platform.typedef.int_least64_t = long_long
|
112
|
+
rbx.platform.typedef.uint_least8_t = uchar
|
113
|
+
rbx.platform.typedef.uint_least16_t = ushort
|
114
|
+
rbx.platform.typedef.uint_least32_t = uint
|
115
|
+
rbx.platform.typedef.uint_least64_t = ulong_long
|
116
|
+
rbx.platform.typedef.int_fast8_t = char
|
117
|
+
rbx.platform.typedef.int_fast16_t = short
|
118
|
+
rbx.platform.typedef.int_fast32_t = int
|
119
|
+
rbx.platform.typedef.int_fast64_t = long_long
|
120
|
+
rbx.platform.typedef.uint_fast8_t = uchar
|
121
|
+
rbx.platform.typedef.uint_fast16_t = ushort
|
122
|
+
rbx.platform.typedef.uint_fast32_t = uint
|
123
|
+
rbx.platform.typedef.uint_fast64_t = ulong_long
|
124
|
+
rbx.platform.typedef.intmax_t = long
|
125
|
+
rbx.platform.typedef.uintmax_t = ulong
|
100
126
|
rbx.platform.typedef.rlim_t = ulong_long
|
data/lib/ffi/struct.rb
CHANGED
@@ -256,6 +256,12 @@ module FFI
|
|
256
256
|
# :field2 => :pointer,
|
257
257
|
# :field3 => :string
|
258
258
|
# end
|
259
|
+
# @example Creating a layout with pointers to functions
|
260
|
+
# class MyFunctionTable < Struct
|
261
|
+
# layout :function1, callback([:int, :int], :int),
|
262
|
+
# :function2, callback([:pointer], :void),
|
263
|
+
# :field3, :string
|
264
|
+
# end
|
259
265
|
# @note Creating a layout from a hash +spec+ is supported only for Ruby 1.9.
|
260
266
|
def layout(*spec)
|
261
267
|
#raise RuntimeError, "struct layout already defined for #{self.inspect}" if defined?(@layout)
|
data/lib/ffi/version.rb
CHANGED
data/libtest/EnumTest.c
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
*
|
4
4
|
* For licensing, see LICENSE.SPECS
|
5
5
|
*/
|
6
|
+
#include <stdint.h>
|
6
7
|
|
7
8
|
int test_untagged_enum(int val) {
|
8
9
|
return val;
|
@@ -12,6 +13,22 @@ int test_untagged_typedef_enum(int val) {
|
|
12
13
|
return val;
|
13
14
|
}
|
14
15
|
|
16
|
+
uint8_t test_untagged_nonint_enum(uint8_t val) {
|
17
|
+
return val;
|
18
|
+
}
|
19
|
+
|
20
|
+
uint16_t test_tagged_nonint_enum1(uint16_t val) {
|
21
|
+
return val;
|
22
|
+
}
|
23
|
+
|
24
|
+
uint32_t test_tagged_nonint_enum2(uint32_t val) {
|
25
|
+
return val;
|
26
|
+
}
|
27
|
+
|
28
|
+
uint64_t test_tagged_nonint_enum3(uint64_t val) {
|
29
|
+
return val;
|
30
|
+
}
|
31
|
+
|
15
32
|
typedef enum {c1, c2, c3, c4} enum_type1;
|
16
33
|
enum_type1 test_tagged_typedef_enum1(enum_type1 val) {
|
17
34
|
return val;
|
data/spec/ffi/enum_spec.rb
CHANGED
@@ -36,6 +36,28 @@ module TestEnum3
|
|
36
36
|
attach_function :test_tagged_typedef_enum4, [:enum_type4], :enum_type4
|
37
37
|
end
|
38
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
|
+
|
39
61
|
describe "A library with no enum defined" do
|
40
62
|
it "returns nil when asked for an enum" do
|
41
63
|
expect(TestEnum0.enum_type(:foo)).to be_nil
|
@@ -60,6 +82,14 @@ describe "An untagged enum" do
|
|
60
82
|
expect(TestEnum1.test_untagged_enum(:c14)).to eq(4242)
|
61
83
|
expect(TestEnum1.test_untagged_enum(:c15)).to eq(424242)
|
62
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)
|
63
93
|
end
|
64
94
|
end
|
65
95
|
|
@@ -69,6 +99,12 @@ describe "A tagged typedef enum" do
|
|
69
99
|
expect(TestEnum3.enum_type(:enum_type2)).not_to be_nil
|
70
100
|
expect(TestEnum3.enum_type(:enum_type3)).not_to be_nil
|
71
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
|
72
108
|
end
|
73
109
|
|
74
110
|
it "contains enum constants" do
|
@@ -76,6 +112,12 @@ describe "A tagged typedef enum" do
|
|
76
112
|
expect(TestEnum3.enum_type(:enum_type2).symbols.length).to eq(4)
|
77
113
|
expect(TestEnum3.enum_type(:enum_type3).symbols.length).to eq(4)
|
78
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)
|
79
121
|
end
|
80
122
|
|
81
123
|
it "constants can be used as function parameters and return value" do
|
@@ -95,6 +137,30 @@ describe "A tagged typedef enum" do
|
|
95
137
|
expect(TestEnum3.test_tagged_typedef_enum4(:c14)).to be :c14
|
96
138
|
expect(TestEnum3.test_tagged_typedef_enum4(:c15)).to be :c15
|
97
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)
|
98
164
|
end
|
99
165
|
|
100
166
|
it "integers can be used instead of constants" do
|
@@ -114,6 +180,18 @@ describe "A tagged typedef enum" do
|
|
114
180
|
expect(TestEnum3.test_tagged_typedef_enum4(4242)).to be :c14
|
115
181
|
expect(TestEnum3.test_tagged_typedef_enum4(424242)).to be :c15
|
116
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)
|
117
195
|
end
|
118
196
|
end
|
119
197
|
|
@@ -128,6 +206,11 @@ describe "All enums" do
|
|
128
206
|
expect(TestEnum3.enum_value(:c2)).to eq(1)
|
129
207
|
expect(TestEnum3.enum_value(:c3)).to eq(2)
|
130
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)
|
131
214
|
end
|
132
215
|
|
133
216
|
it "can have an explicit first constant and autonumbered subsequent constants" do
|
@@ -140,6 +223,16 @@ describe "All enums" do
|
|
140
223
|
expect(TestEnum3.enum_value(:c6)).to eq(43)
|
141
224
|
expect(TestEnum3.enum_value(:c7)).to eq(44)
|
142
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)
|
143
236
|
end
|
144
237
|
|
145
238
|
it "can have a mix of explicit and autonumbered constants" do
|
@@ -152,6 +245,16 @@ describe "All enums" do
|
|
152
245
|
expect(TestEnum3.enum_value(:c10)).to eq(43)
|
153
246
|
expect(TestEnum3.enum_value(:c11)).to eq(4242)
|
154
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)
|
155
258
|
end
|
156
259
|
|
157
260
|
it "can have all its constants explicitely valued" do
|
@@ -164,6 +267,16 @@ describe "All enums" do
|
|
164
267
|
expect(TestEnum3.enum_value(:c14)).to eq(4242)
|
165
268
|
expect(TestEnum3.enum_value(:c15)).to eq(424242)
|
166
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)
|
167
280
|
end
|
168
281
|
|
169
282
|
it "return the constant corresponding to a specific value" do
|
@@ -190,6 +303,42 @@ describe "All enums" do
|
|
190
303
|
expect(enum[4242]).to be :c14
|
191
304
|
expect(enum[424242]).to be :c15
|
192
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)
|
193
342
|
end
|
194
343
|
|
195
344
|
it "return nil for values that don't have a symbol" do
|
@@ -219,9 +368,56 @@ describe "All enums" do
|
|
219
368
|
expect(enum[424243]).to be_nil
|
220
369
|
expect(enum[42424241]).to be_nil
|
221
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
|
222
417
|
end
|
223
418
|
|
224
419
|
it "duplicate enum keys rejected" do
|
225
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
|
226
422
|
end
|
227
423
|
end
|