ffi 1.9.6-x86-mingw32 → 1.9.8-x86-mingw32
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 +8 -8
- 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/1.8/ffi_c.so +0 -0
- data/lib/1.9/ffi_c.so +0 -0
- data/lib/2.0/ffi_c.so +0 -0
- data/lib/2.1/ffi_c.so +0 -0
- data/lib/2.2/ffi_c.so +0 -0
- 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 +19 -11
- data/spec/ffi/ffi.log +0 -5833
- data/spec/ffi/struct_by_ref_spec.rb.orig +0 -43
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTRiYmE0MDg4OTgxNDE0YTUwNTRiMWJjNzM4M2M2YWU5YTUzYTI4MA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmQ2NTBiYzk0ZDViODUwYWNiMThkYTE3MTZjNWIzNTY5YmE3NjgwZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGM4MjBjMTVhYWQyNjk0MDZhMTg3NDgxZTFjZGExNmNmZmZhNTc1ZTllOTIy
|
10
|
+
YjMwZGI4MjJmOTVmZDlmOGVhMjEyYzI4NDdmN2IzZmMwNTJhN2RjMDFmZGU0
|
11
|
+
ZDZjNDkzZWY3YTI3NTkxOTU1ZTNlNmEwMjQzMWFiYWM1OGY2Zjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjA1YjZlOWI5NDBiODY3YTc3NzZjYjJmZDgzOGQ3Mjg0NzAwZTZlMDZiMTU0
|
14
|
+
MjEwZWVmMWVjOWRlYjMzYjZlMDJkZTk3MjJiM2JhZDMxN2JiYjEyN2U1NmVj
|
15
|
+
YzkzMzZlNzU4NTFmMWQzNDUxZDRmMTI4ZTIwN2VmMzI1ZDEwZjk=
|
data/README.md
CHANGED
@@ -63,7 +63,7 @@ as Rubyspec, see the LICENSE.SPECS file.
|
|
63
63
|
|
64
64
|
## Credits
|
65
65
|
|
66
|
-
The following people have submitted code, bug reports, or
|
66
|
+
The following people have submitted code, bug reports, or otherwise contributed to the success of this project:
|
67
67
|
|
68
68
|
* Alban Peignier <alban.peignier@free.fr>
|
69
69
|
* Aman Gupta <aman@tmm1.net>
|
data/Rakefile
CHANGED
@@ -82,8 +82,8 @@ end
|
|
82
82
|
TEST_DEPS = [ LIBTEST ]
|
83
83
|
if RUBY_PLATFORM == "java"
|
84
84
|
desc "Run all specs"
|
85
|
-
task :specs => TEST_DEPS do
|
86
|
-
sh %{#{Gem.ruby} -w -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
|
85
|
+
task :specs, [:options] => TEST_DEPS do |t, args|
|
86
|
+
sh %{#{Gem.ruby} -w -S rspec #{args.options || Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
|
87
87
|
end
|
88
88
|
desc "Run rubinius specs"
|
89
89
|
task :rbxspecs => TEST_DEPS do
|
@@ -92,9 +92,9 @@ if RUBY_PLATFORM == "java"
|
|
92
92
|
else
|
93
93
|
TEST_DEPS.unshift :compile
|
94
94
|
desc "Run all specs"
|
95
|
-
task :specs => TEST_DEPS do
|
95
|
+
task :specs, [:options] => TEST_DEPS do |t, args|
|
96
96
|
ENV["MRI_FFI"] = "1"
|
97
|
-
sh %{#{Gem.ruby} -w -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
|
97
|
+
sh %{#{Gem.ruby} -w -Ilib -I#{BUILD_EXT_DIR} -S rspec #{args.options || Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
|
98
98
|
end
|
99
99
|
desc "Run rubinius specs"
|
100
100
|
task :rbxspecs => TEST_DEPS do
|
@@ -187,21 +187,21 @@ if USE_RAKE_COMPILER
|
|
187
187
|
|
188
188
|
task 'gem:win32' => ['gem:win32-x64', 'gem:win32-i386']
|
189
189
|
|
190
|
-
task 'gem:win32-
|
191
|
-
sh("rake cross native:i386-mingw32 gem RUBY_CC_VERSION='1.8.7:1.9.3:2.0.0:2.1.
|
190
|
+
task 'gem:win32-i386' do
|
191
|
+
sh("rake cross native:i386-mingw32 gem RUBY_CC_VERSION='1.8.7:1.9.3:2.0.0:2.1.5:2.2.1'") || raise("win32-i386 build failed!")
|
192
192
|
end
|
193
193
|
|
194
194
|
task 'gem:win32-x64' do
|
195
|
-
sh("rake cross native:x64-mingw32 gem RUBY_CC_VERSION='2.0.0:2.1.
|
195
|
+
sh("rake cross native:x64-mingw32 gem RUBY_CC_VERSION='2.0.0:2.1.5:2.2.1'") || raise("win32-x64 build failed!")
|
196
196
|
end
|
197
197
|
|
198
|
-
(ENV['RUBY_CC_VERSION'] || '1.8.7:1.9.3:2.0.0:2.1.
|
198
|
+
(ENV['RUBY_CC_VERSION'] || '1.8.7:1.9.3:2.0.0:2.1.5:2.2.1' ).to_s.split(':').each do |ruby_version|
|
199
199
|
task "copy:ffi_c:i386-mingw32:#{ruby_version}" do |t|
|
200
200
|
sh "i686-w64-mingw32-strip -S #{BUILD_DIR}/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
-
(ENV['RUBY_CC_VERSION'] || '2.0.0:2.1.
|
204
|
+
(ENV['RUBY_CC_VERSION'] || '2.0.0:2.1.5:2.2.1' ).to_s.split(':').each do |ruby_version|
|
205
205
|
task "copy:ffi_c:x64-mingw32:#{ruby_version}" do |t|
|
206
206
|
sh "x86_64-w64-mingw32-strip -S #{BUILD_DIR}/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
|
207
207
|
end
|
data/ext/ffi_c/Call.c
CHANGED
@@ -126,19 +126,30 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
126
126
|
switch (paramType->nativeType) {
|
127
127
|
|
128
128
|
case NATIVE_INT8:
|
129
|
-
|
129
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
130
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
131
|
+
param->s8 = NUM2INT(value);
|
132
|
+
} else {
|
133
|
+
param->s8 = NUM2INT(argv[argidx]);
|
134
|
+
}
|
135
|
+
|
130
136
|
++argidx;
|
131
137
|
ADJ(param, INT8);
|
132
138
|
break;
|
133
139
|
|
134
|
-
|
135
140
|
case NATIVE_INT16:
|
136
|
-
|
141
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
142
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
143
|
+
param->s16 = NUM2INT(value);
|
144
|
+
|
145
|
+
} else {
|
146
|
+
param->s16 = NUM2INT(argv[argidx]);
|
147
|
+
}
|
148
|
+
|
137
149
|
++argidx;
|
138
150
|
ADJ(param, INT16);
|
139
151
|
break;
|
140
152
|
|
141
|
-
|
142
153
|
case NATIVE_INT32:
|
143
154
|
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
144
155
|
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
@@ -152,7 +163,6 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
152
163
|
ADJ(param, INT32);
|
153
164
|
break;
|
154
165
|
|
155
|
-
|
156
166
|
case NATIVE_BOOL:
|
157
167
|
if (type != T_TRUE && type != T_FALSE) {
|
158
168
|
rb_raise(rb_eTypeError, "wrong argument type (expected a boolean parameter)");
|
@@ -161,67 +171,122 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
161
171
|
ADJ(param, INT8);
|
162
172
|
break;
|
163
173
|
|
164
|
-
|
165
174
|
case NATIVE_UINT8:
|
166
|
-
|
175
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
176
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
177
|
+
param->u8 = NUM2UINT(value);
|
178
|
+
} else {
|
179
|
+
param->u8 = NUM2UINT(argv[argidx]);
|
180
|
+
}
|
181
|
+
|
167
182
|
ADJ(param, INT8);
|
168
183
|
++argidx;
|
169
184
|
break;
|
170
185
|
|
171
|
-
|
172
186
|
case NATIVE_UINT16:
|
173
|
-
|
187
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
188
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
189
|
+
param->u16 = NUM2UINT(value);
|
190
|
+
} else {
|
191
|
+
param->u16 = NUM2UINT(argv[argidx]);
|
192
|
+
}
|
193
|
+
|
174
194
|
ADJ(param, INT16);
|
175
195
|
++argidx;
|
176
196
|
break;
|
177
197
|
|
178
|
-
|
179
198
|
case NATIVE_UINT32:
|
180
|
-
|
199
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
200
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
201
|
+
param->u32 = NUM2UINT(value);
|
202
|
+
} else {
|
203
|
+
param->u32 = NUM2UINT(argv[argidx]);
|
204
|
+
}
|
205
|
+
|
181
206
|
ADJ(param, INT32);
|
182
207
|
++argidx;
|
183
208
|
break;
|
184
209
|
|
185
|
-
|
186
210
|
case NATIVE_INT64:
|
187
|
-
|
211
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
212
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
213
|
+
param->i64 = NUM2LL(value);
|
214
|
+
} else {
|
215
|
+
param->i64 = NUM2LL(argv[argidx]);
|
216
|
+
}
|
217
|
+
|
188
218
|
ADJ(param, INT64);
|
189
219
|
++argidx;
|
190
220
|
break;
|
191
221
|
|
192
|
-
|
193
222
|
case NATIVE_UINT64:
|
194
|
-
|
223
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
224
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
225
|
+
param->u64 = NUM2ULL(value);
|
226
|
+
} else {
|
227
|
+
param->u64 = NUM2ULL(argv[argidx]);
|
228
|
+
}
|
229
|
+
|
195
230
|
ADJ(param, INT64);
|
196
231
|
++argidx;
|
197
232
|
break;
|
198
233
|
|
199
234
|
case NATIVE_LONG:
|
200
|
-
|
235
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
236
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
237
|
+
*(ffi_sarg *) param = NUM2LONG(value);
|
238
|
+
} else {
|
239
|
+
*(ffi_sarg *) param = NUM2LONG(argv[argidx]);
|
240
|
+
}
|
241
|
+
|
201
242
|
ADJ(param, LONG);
|
202
243
|
++argidx;
|
203
244
|
break;
|
204
245
|
|
205
246
|
case NATIVE_ULONG:
|
206
|
-
|
247
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
248
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
249
|
+
*(ffi_arg *) param = NUM2ULONG(value);
|
250
|
+
} else {
|
251
|
+
*(ffi_arg *) param = NUM2ULONG(argv[argidx]);
|
252
|
+
}
|
253
|
+
|
207
254
|
ADJ(param, LONG);
|
208
255
|
++argidx;
|
209
256
|
break;
|
210
257
|
|
211
258
|
case NATIVE_FLOAT32:
|
212
|
-
|
259
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
260
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
261
|
+
param->f32 = (float) NUM2DBL(value);
|
262
|
+
} else {
|
263
|
+
param->f32 = (float) NUM2DBL(argv[argidx]);
|
264
|
+
}
|
265
|
+
|
213
266
|
ADJ(param, FLOAT32);
|
214
267
|
++argidx;
|
215
268
|
break;
|
216
269
|
|
217
270
|
case NATIVE_FLOAT64:
|
218
|
-
|
271
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
272
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
273
|
+
param->f64 = NUM2DBL(value);
|
274
|
+
} else {
|
275
|
+
param->f64 = NUM2DBL(argv[argidx]);
|
276
|
+
}
|
277
|
+
|
219
278
|
ADJ(param, FLOAT64);
|
220
279
|
++argidx;
|
221
280
|
break;
|
222
281
|
|
223
282
|
case NATIVE_LONGDOUBLE:
|
224
|
-
|
283
|
+
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
|
284
|
+
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
|
285
|
+
param->ld = rbffi_num2longdouble(value);
|
286
|
+
} else {
|
287
|
+
param->ld = rbffi_num2longdouble(argv[argidx]);
|
288
|
+
}
|
289
|
+
|
225
290
|
ADJ(param, LONGDOUBLE);
|
226
291
|
++argidx;
|
227
292
|
break;
|
data/ext/ffi_c/Variadic.c
CHANGED
@@ -170,7 +170,7 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
|
|
170
170
|
ffi_type* ffiReturnType;
|
171
171
|
Type** paramTypes;
|
172
172
|
VALUE* argv;
|
173
|
-
int paramCount = 0, i;
|
173
|
+
int paramCount = 0, fixedCount = 0, i;
|
174
174
|
ffi_status ffiStatus;
|
175
175
|
rbffi_frame_t frame = { 0 };
|
176
176
|
|
@@ -229,8 +229,12 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
|
|
229
229
|
if (ffiReturnType == NULL) {
|
230
230
|
rb_raise(rb_eArgError, "Invalid return type");
|
231
231
|
}
|
232
|
+
|
233
|
+
/*Get the number of fixed args from @fixed array*/
|
234
|
+
fixedCount = RARRAY_LEN(rb_iv_get(self, "@fixed"));
|
235
|
+
|
232
236
|
#ifdef HAVE_FFI_PREP_CIF_VAR
|
233
|
-
ffiStatus = ffi_prep_cif_var(&cif, invoker->abi,
|
237
|
+
ffiStatus = ffi_prep_cif_var(&cif, invoker->abi, fixedCount, paramCount, ffiReturnType, ffiParamTypes);
|
234
238
|
#else
|
235
239
|
ffiStatus = ffi_prep_cif(&cif, invoker->abi, paramCount, ffiReturnType, ffiParamTypes);
|
236
240
|
#endif
|
@@ -156,7 +156,7 @@ ca_epilogue:
|
|
156
156
|
ret
|
157
157
|
ffi_call_win32 ENDP
|
158
158
|
|
159
|
-
ffi_closure_SYSV PROC NEAR FORCEFRAME
|
159
|
+
ffi_closure_SYSV PROC NEAR <FORCEFRAME>
|
160
160
|
;; the ffi_closure ctx is passed in eax by the trampoline.
|
161
161
|
|
162
162
|
sub esp, 40
|
@@ -314,7 +314,7 @@ ffi_closure_raw_SYSV ENDP
|
|
314
314
|
|
315
315
|
#endif /* !FFI_NO_RAW_API */
|
316
316
|
|
317
|
-
ffi_closure_STDCALL PROC NEAR FORCEFRAME
|
317
|
+
ffi_closure_STDCALL PROC NEAR <FORCEFRAME>
|
318
318
|
;; the ffi_closure ctx is passed in eax by the trampoline.
|
319
319
|
|
320
320
|
sub esp, 40
|
data/ffi.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.homepage = 'http://wiki.github.com/ffi/ffi'
|
9
9
|
s.summary = 'Ruby FFI'
|
10
10
|
s.description = 'Ruby FFI library'
|
11
|
-
s.files = %w(ffi.gemspec LICENSE COPYING README.md Rakefile) + Dir.glob("{ext,gen,lib,spec,libtest}/**/*").reject { |f| f =~ /(lib\/[12]\.[089]|\.
|
11
|
+
s.files = %w(ffi.gemspec LICENSE COPYING README.md Rakefile) + Dir.glob("{ext,gen,lib,spec,libtest}/**/*").reject { |f| f =~ /(lib\/[12]\.[089]|\.s?[ao]$|\.bundle|\.dylib$)/ }
|
12
12
|
s.extensions << 'ext/ffi_c/extconf.rb'
|
13
13
|
s.has_rdoc = false
|
14
14
|
s.rdoc_options = %w[--exclude=ext/ffi_c/.*\.o$ --exclude=ffi_c\.(bundle|so)$]
|
data/lib/1.8/ffi_c.so
CHANGED
Binary file
|
data/lib/1.9/ffi_c.so
CHANGED
Binary file
|
data/lib/2.0/ffi_c.so
CHANGED
Binary file
|
data/lib/2.1/ffi_c.so
CHANGED
Binary file
|
data/lib/2.2/ffi_c.so
ADDED
Binary file
|
data/lib/ffi.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
|
2
2
|
Object.send(:remove_const, :FFI) if defined?(::FFI)
|
3
3
|
begin
|
4
|
-
if RUBY_VERSION =~ /1
|
4
|
+
if RUBY_VERSION =~ /1\.8/
|
5
5
|
require '1.8/ffi_c'
|
6
|
-
elsif RUBY_VERSION =~ /1
|
6
|
+
elsif RUBY_VERSION =~ /1\.9/
|
7
7
|
require '1.9/ffi_c'
|
8
|
-
elsif RUBY_VERSION =~ /2
|
8
|
+
elsif RUBY_VERSION =~ /2\.0/
|
9
9
|
require '2.0/ffi_c'
|
10
|
-
elsif RUBY_VERSION =~ /2
|
10
|
+
elsif RUBY_VERSION =~ /2\.1/
|
11
11
|
require '2.1/ffi_c'
|
12
|
+
elsif RUBY_VERSION =~ /2\.2/
|
13
|
+
require '2.2/ffi_c'
|
12
14
|
else
|
13
15
|
require 'ffi_c'
|
14
16
|
end
|
data/lib/ffi/enum.rb
CHANGED
@@ -86,10 +86,16 @@ module FFI
|
|
86
86
|
|
87
87
|
attr_reader :tag
|
88
88
|
|
89
|
-
# @
|
90
|
-
#
|
91
|
-
|
92
|
-
|
89
|
+
# @overload initialize(info, tag=nil)
|
90
|
+
# @param [nil, Enumerable] info
|
91
|
+
# @param [nil, Symbol] tag enum tag
|
92
|
+
# @overload initialize(native_type, info, tag=nil)
|
93
|
+
# @param [FFI::Type] native_type Native type for new Enum
|
94
|
+
# @param [nil, Enumerable] info symbols and values for new Enum
|
95
|
+
# @param [nil, Symbol] tag name of new Enum
|
96
|
+
def initialize(*args)
|
97
|
+
@native_type = args.shift if args.first.kind_of?(FFI::Type)
|
98
|
+
info, @tag = *args
|
93
99
|
@kv_map = Hash.new
|
94
100
|
unless info.nil?
|
95
101
|
last_cst = nil
|
@@ -144,9 +150,9 @@ module FFI
|
|
144
150
|
alias to_hash symbol_map
|
145
151
|
|
146
152
|
# Get native type of Enum
|
147
|
-
# @return [Type
|
153
|
+
# @return [Type]
|
148
154
|
def native_type
|
149
|
-
Type::INT
|
155
|
+
@native_type || Type::INT
|
150
156
|
end
|
151
157
|
|
152
158
|
# @param [Symbol, Integer, #to_int] val
|
data/lib/ffi/library.rb
CHANGED
@@ -444,9 +444,29 @@ module FFI
|
|
444
444
|
# @example
|
445
445
|
# enum [:zero, :one, :two] # unnamed enum, equivalent to above example
|
446
446
|
# @param [Array] values values for enum
|
447
|
+
# @overload enum(native_type, name, values)
|
448
|
+
# Create a named enum and specify the native type.
|
449
|
+
# @example
|
450
|
+
# enum FFI::Type::UINT64, :foo, [:zero, :one, :two] # named enum
|
451
|
+
# @param [FFI::Type] native_type native type for new enum
|
452
|
+
# @param [Symbol] name name for new enum
|
453
|
+
# @param [Array] values values for enum
|
454
|
+
# @overload enum(native_type, *args)
|
455
|
+
# Create an unnamed enum and specify the native type.
|
456
|
+
# @example
|
457
|
+
# enum FFI::Type::UINT64, :zero, :one, :two # unnamed enum
|
458
|
+
# @param [FFI::Type] native_type native type for new enum
|
459
|
+
# @param args values for enum
|
460
|
+
# @overload enum(native_type, values)
|
461
|
+
# Create an unnamed enum and specify the native type.
|
462
|
+
# @example
|
463
|
+
# enum Type::UINT64, [:zero, :one, :two] # unnamed enum, equivalent to above example
|
464
|
+
# @param [FFI::Type] native_type native type for new enum
|
465
|
+
# @param [Array] values values for enum
|
447
466
|
# @return [FFI::Enum]
|
448
467
|
# Create a new {FFI::Enum}.
|
449
468
|
def enum(*args)
|
469
|
+
native_type = args.first.kind_of?(FFI::Type) ? args.shift : nil
|
450
470
|
name, values = if args[0].kind_of?(Symbol) && args[1].kind_of?(Array)
|
451
471
|
[ args[0], args[1] ]
|
452
472
|
elsif args[0].kind_of?(Array)
|
@@ -455,7 +475,7 @@ module FFI
|
|
455
475
|
[ nil, args ]
|
456
476
|
end
|
457
477
|
@ffi_enums = FFI::Enums.new unless defined?(@ffi_enums)
|
458
|
-
@ffi_enums << (e = FFI::Enum.new(values, name))
|
478
|
+
@ffi_enums << (e = native_type ? FFI::Enum.new(native_type, values, name) : FFI::Enum.new(values, name))
|
459
479
|
|
460
480
|
# If called as enum :foo, [ :zero, :one, :two ], add a typedef alias
|
461
481
|
typedef(e, name) if name
|
data/lib/ffi/platform.rb
CHANGED
@@ -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 = uint
|
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 = int
|
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 = uint
|
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 = int
|
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
|