ffi 1.9.3-x64-mingw32 → 1.9.5-x64-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.

Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +13 -16
  3. data/ext/ffi_c/DynamicLibrary.c +9 -5
  4. data/ext/ffi_c/DynamicLibrary.h +49 -0
  5. data/ext/ffi_c/Function.c +4 -3
  6. data/ext/ffi_c/FunctionInfo.c +2 -2
  7. data/ext/ffi_c/Platform.c +2 -2
  8. data/ext/ffi_c/Struct.c +1 -0
  9. data/ext/ffi_c/Variadic.c +2 -2
  10. data/ffi.gemspec +5 -5
  11. data/lib/2.0/ffi_c.so +0 -0
  12. data/lib/ffi/library.rb +7 -7
  13. data/lib/ffi/platform.rb +4 -1
  14. data/lib/ffi/platform/x86_64-netbsd/types.conf +2 -0
  15. data/lib/ffi/struct.rb +2 -2
  16. data/lib/ffi/version.rb +1 -1
  17. data/libtest/ClosureTest.c +15 -0
  18. data/libtest/FunctionTest.c +12 -0
  19. data/spec/ffi/LICENSE.SPECS +22 -0
  20. data/spec/ffi/async_callback_spec.rb +1 -0
  21. data/spec/ffi/bool_spec.rb +2 -0
  22. data/spec/ffi/buffer_spec.rb +1 -0
  23. data/spec/ffi/callback_spec.rb +31 -4
  24. data/spec/ffi/custom_param_type.rb +1 -0
  25. data/spec/ffi/custom_type_spec.rb +1 -0
  26. data/spec/ffi/dup_spec.rb +1 -1
  27. data/spec/ffi/enum_spec.rb +1 -0
  28. data/spec/ffi/errno_spec.rb +2 -0
  29. data/spec/ffi/ffi_spec.rb +1 -0
  30. data/spec/ffi/fixtures/Benchmark.c +52 -0
  31. data/spec/ffi/fixtures/BoolTest.c +34 -0
  32. data/spec/ffi/fixtures/BufferTest.c +31 -0
  33. data/spec/ffi/fixtures/ClosureTest.c +190 -0
  34. data/spec/ffi/fixtures/EnumTest.c +34 -0
  35. data/spec/ffi/fixtures/FunctionTest.c +58 -0
  36. data/spec/ffi/fixtures/GNUmakefile +149 -0
  37. data/spec/ffi/fixtures/GlobalVariable.c +62 -0
  38. data/spec/ffi/fixtures/LastErrorTest.c +21 -0
  39. data/spec/ffi/fixtures/NumberTest.c +132 -0
  40. data/spec/ffi/fixtures/PointerTest.c +63 -0
  41. data/spec/ffi/fixtures/ReferenceTest.c +23 -0
  42. data/spec/ffi/fixtures/StringTest.c +34 -0
  43. data/spec/ffi/fixtures/StructTest.c +243 -0
  44. data/spec/ffi/fixtures/UnionTest.c +43 -0
  45. data/spec/ffi/fixtures/VariadicTest.c +99 -0
  46. data/spec/ffi/fixtures/classes.rb +438 -0
  47. data/spec/ffi/function_spec.rb +4 -2
  48. data/spec/ffi/io_spec.rb +17 -0
  49. data/spec/ffi/library_spec.rb +25 -0
  50. data/spec/ffi/long_double.rb +1 -0
  51. data/spec/ffi/managed_struct_spec.rb +1 -1
  52. data/spec/ffi/memorypointer_spec.rb +72 -0
  53. data/spec/ffi/number_spec.rb +2 -0
  54. data/spec/ffi/platform_spec.rb +97 -0
  55. data/spec/ffi/pointer_spec.rb +8 -2
  56. data/spec/ffi/rbx/attach_function_spec.rb +6 -0
  57. data/spec/ffi/rbx/memory_pointer_spec.rb +7 -2
  58. data/spec/ffi/rbx/spec_helper.rb +7 -1
  59. data/spec/ffi/rbx/struct_spec.rb +7 -1
  60. data/spec/ffi/spec_helper.rb +68 -9
  61. data/spec/ffi/string_spec.rb +3 -1
  62. data/spec/ffi/strptr_spec.rb +1 -0
  63. data/spec/ffi/struct_by_ref_spec.rb +4 -3
  64. data/spec/ffi/struct_callback_spec.rb +2 -1
  65. data/spec/ffi/struct_initialize_spec.rb +1 -0
  66. data/spec/ffi/struct_packed_spec.rb +1 -0
  67. data/spec/ffi/struct_spec.rb +99 -39
  68. data/spec/ffi/typedef_spec.rb +15 -3
  69. data/spec/ffi/union_spec.rb +1 -0
  70. data/spec/ffi/variadic_spec.rb +18 -0
  71. data/spec/spec.opts +1 -2
  72. metadata +417 -430
  73. data/lib/ffi_c.so +0 -0
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008-2014 Ruby-FFI contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -4,6 +4,7 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+ require 'ffi'
7
8
 
8
9
  describe "async callback" do
9
10
  module LibTest
@@ -4,6 +4,8 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+ require 'ffi'
8
+
7
9
  describe "Function with primitive boolean arguments and return values" do
8
10
  module LibTest
9
11
  extend FFI::Library
@@ -4,6 +4,7 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+ require 'ffi'
7
8
 
8
9
  describe "Buffer#total" do
9
10
  [1,2,3].each do |i|
@@ -4,6 +4,7 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+ require 'ffi'
7
8
 
8
9
  describe "Callback" do
9
10
  # module LibC
@@ -253,6 +254,9 @@ describe "Callback" do
253
254
  s2[:f32] = struct[:f32]
254
255
  s2[:s32] = struct[:s32]
255
256
  end
257
+ expect(s2[:s8]).to eql 0x12
258
+ expect(s2[:s32]).to eql 0x1eefbeef
259
+ expect(s2[:f32]).to be_within(0.0000001).of 1.234567
256
260
  end
257
261
 
258
262
 
@@ -264,7 +268,7 @@ describe "Callback" do
264
268
 
265
269
  describe "When the callback is considered optional by the underlying library" do
266
270
  it "should handle receiving 'nil' in place of the closure" do
267
- LibTest.testOptionalCallbackCrV(nil, 13)
271
+ LibTest.testOptionalCallbackCrV(nil, 13).should be_nil
268
272
  end
269
273
  end
270
274
 
@@ -288,7 +292,7 @@ describe "Callback" do
288
292
  callback :cb_return_type_1, [ :short ], :short
289
293
  callback :cb_lookup_1, [ :short ], :cb_return_type_1
290
294
  attach_function :testReturnsCallback_1, :testReturnsClosure, [ :cb_lookup_1, :short ], :cb_return_type_1
291
- end
295
+ end.should be_an_instance_of FFI::Function
292
296
  end
293
297
 
294
298
  it "should return a callback" do
@@ -345,7 +349,7 @@ describe "Callback" do
345
349
  callback :cb_argument, [ :int ], :int
346
350
  callback :cb_with_cb_argument, [ :cb_argument, :int ], :int
347
351
  attach_function :testCallbackAsArgument_2, :testArgumentClosure, [ :cb_with_cb_argument, :int ], :int
348
- end
352
+ end.should be_an_instance_of FFI::Function
349
353
  end
350
354
  it 'should be able to use the callback argument' do
351
355
  module LibTest
@@ -644,7 +648,7 @@ describe "Callback with " do
644
648
  magic = LibTest::S8F32S32.new
645
649
  LibTest.testCallbackYrV(magic) { |i| v = i }
646
650
  v.class.should == magic.class
647
- v.pointer == magic.pointer
651
+ v.pointer.should == magic.pointer
648
652
  end
649
653
 
650
654
  it "struct by reference argument with nil value" do
@@ -664,4 +668,27 @@ describe "Callback with " do
664
668
  }.should raise_error(ArgumentError)
665
669
  end
666
670
 
671
+ #
672
+ # Test stdcall convention with function and callback.
673
+ # This is Windows 32-bit only.
674
+ #
675
+ if FFI::Platform::OS =~ /windows|cygwin/ && FFI::Platform::ARCH == 'i386'
676
+ module LibTestStdcall
677
+ extend FFI::Library
678
+ ffi_lib TestLibrary::PATH
679
+ ffi_convention :stdcall
680
+
681
+ callback :cbStdcall, [ :pointer, :long ], :void
682
+ attach_function :testCallbackStdcall, 'testClosureStdcall', [ :pointer, :cbStdcall, :long ], :bool
683
+ end
684
+
685
+ it "stdcall convention" do
686
+ v = 0xdeadbeef
687
+ po = FFI::MemoryPointer.new :long
688
+ pr = proc{|a,i| v = a,i; i }
689
+ res = LibTestStdcall.testCallbackStdcall(po, pr, 0x7fffffff)
690
+ v.should == [po, 0x7fffffff]
691
+ res.should be_true
692
+ end
693
+ end
667
694
  end
@@ -4,6 +4,7 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+ require 'ffi'
7
8
 
8
9
  describe "functions with custom parameter types" do
9
10
  before :each do
@@ -4,6 +4,7 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+ require 'ffi'
7
8
 
8
9
  describe "functions with custom types" do
9
10
  class Custom_enum
data/spec/ffi/dup_spec.rb CHANGED
@@ -3,8 +3,8 @@
3
3
  # For licensing, see LICENSE.SPECS
4
4
  #
5
5
 
6
-
7
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+ require 'ffi'
8
8
 
9
9
  describe "Pointer#dup" do
10
10
  it "clone should be independent" do
@@ -4,6 +4,7 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+ require 'ffi'
7
8
 
8
9
  module TestEnum0
9
10
  extend FFI::Library
@@ -4,6 +4,8 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+ require 'ffi'
8
+
7
9
  describe "FFI.errno" do
8
10
  module LibTest
9
11
  extend FFI::Library
data/spec/ffi/ffi_spec.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+ require 'ffi'
7
8
 
8
9
  describe "FFI" do
9
10
 
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * For licensing, see LICENSE.SPECS
5
+ */
6
+ #include <sys/types.h>
7
+ #include <stdint.h>
8
+
9
+ void returnVoid() {
10
+
11
+ }
12
+
13
+ void returnVoidI(int arg) {
14
+
15
+ }
16
+ int returnInt() {
17
+ return 0;
18
+ }
19
+
20
+ int returnIntI(int arg) {
21
+ return arg;
22
+ }
23
+
24
+ typedef int8_t s8;
25
+ typedef uint8_t u8;
26
+ typedef int16_t s16;
27
+ typedef uint16_t u16;
28
+ typedef int32_t s32;
29
+ typedef uint32_t u32;
30
+ typedef int64_t s64;
31
+ typedef uint64_t u64;
32
+ typedef float f32;
33
+ typedef double f64;
34
+ typedef void v;
35
+ typedef char* S;
36
+ typedef void* P;
37
+
38
+ #define B6(R, T1, T2, T3, T4, T5, T6) R bench_##T1##T2##T3##T4##T5##T6##_##R(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) {}
39
+ #define B5(R, T1, T2, T3, T4, T5) R bench_##T1##T2##T3##T4##T5##_##R(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {}
40
+ #define B4(R, T1, T2, T3, T4) R bench_##T1##T2##T3##T4##_##R(T1 a1, T2 a2, T3 a3, T4 a4) {}
41
+ #define B3(R, T1, T2, T3) R bench_##T1##T2##T3##_##R(T1 a1, T2 a2, T3 a3) {}
42
+ #define B2(R, T1, T2) R bench_##T1##T2##_##R(T1 a1, T2 a2) {}
43
+ #define B1(R, T1) R bench_##T1##_##R(T1 a1) {}
44
+ #define BrV(T) B1(v, T); B2(v, T, T); B3(v, T, T, T); B4(v, T, T, T, T); B5(v, T, T, T, T, T); B6(v, T, T, T, T, T, T);
45
+ BrV(u32);
46
+ BrV(s32);
47
+ BrV(s64);
48
+ BrV(u64);
49
+ BrV(f32);
50
+ BrV(f64);
51
+ BrV(S);
52
+ BrV(P);
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner.
3
+ * Copyright (c) 2009 Aman Gupta.
4
+ *
5
+ * All rights reserved.
6
+ *
7
+ * For licensing, see LICENSE.SPECS
8
+ */
9
+
10
+ #include <stdbool.h>
11
+
12
+ bool
13
+ bool_return_true()
14
+ {
15
+ return true;
16
+ }
17
+
18
+ bool
19
+ bool_return_false()
20
+ {
21
+ return false;
22
+ }
23
+
24
+ bool
25
+ bool_return_val(bool value)
26
+ {
27
+ return value;
28
+ }
29
+
30
+ bool
31
+ bool_reverse_val(bool value)
32
+ {
33
+ return value ? false : true;
34
+ }
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * For licensing, see LICENSE.SPECS
5
+ */
6
+
7
+
8
+ #define MEMSET(buf, value, size) do { \
9
+ int i; for (i = 0; i < size; ++i) buf[i] = value; \
10
+ } while(0)
11
+ #define MEMCPY(dst, src, size) do { \
12
+ int i; for (i = 0; i < size; ++i) dst[i] = src[i]; \
13
+ } while(0)
14
+
15
+ #define FILL(JTYPE, CTYPE) \
16
+ void fill##JTYPE##Buffer(CTYPE* buf, CTYPE value, int size) { MEMSET(buf, value, size); }
17
+
18
+ #define COPY(JTYPE, CTYPE) \
19
+ void copy##JTYPE##Buffer(CTYPE* dst, CTYPE* src, int size) { MEMCPY(dst, src, size); }
20
+
21
+ #define FUNC(JTYPE, CTYPE) \
22
+ FILL(JTYPE, CTYPE); \
23
+ COPY(JTYPE, CTYPE)
24
+
25
+ FUNC(Byte, char);
26
+ FUNC(Short, short);
27
+ FUNC(Int, int);
28
+ FUNC(Long, long long);
29
+ FUNC(Float, float);
30
+ FUNC(Double, double);
31
+
@@ -0,0 +1,190 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * For licensing, see LICENSE.SPECS
5
+ */
6
+
7
+ #include <stdlib.h>
8
+ #include <stdbool.h>
9
+ #ifndef _WIN32
10
+ # include <pthread.h>
11
+ #else
12
+ # include <windows.h>
13
+ # include <process.h>
14
+ #endif
15
+
16
+ #define R(T, rtype) rtype testClosureVr##T(rtype (*closure)(void)) { \
17
+ return closure != NULL ? (*closure)() : (rtype) 0; \
18
+ }
19
+
20
+ #define P(T, ptype) void testClosure##T##rV(void (*closure)(ptype), ptype a1) { \
21
+ if (closure != NULL) (*closure)(a1); \
22
+ }
23
+
24
+ void testClosureVrV(void (*closure)(void))
25
+ {
26
+ (*closure)();
27
+ }
28
+
29
+ R(Z, bool);
30
+ R(B, char);
31
+ R(S, short);
32
+ R(I, int);
33
+ R(L, long);
34
+ R(J, long long);
35
+ R(LL, long long);
36
+ R(F, float);
37
+ R(D, double);
38
+ R(P, const void*);
39
+
40
+
41
+ P(Z, bool);
42
+ P(B, char);
43
+ P(S, short);
44
+ P(I, int);
45
+ P(L, long);
46
+ P(J, long long);
47
+ P(LL, long long);
48
+ P(F, float);
49
+ P(D, double);
50
+ P(P, const void*);
51
+ P(UL, unsigned long);
52
+
53
+ void testOptionalClosureBrV(void (*closure)(char), char a1)
54
+ {
55
+ if (closure) {
56
+ (*closure)(a1);
57
+ }
58
+ }
59
+
60
+
61
+ struct ThreadVrV {
62
+ void (*closure)(void);
63
+ int count;
64
+ };
65
+
66
+ static void *
67
+ threadVrV(void *arg)
68
+ {
69
+ struct ThreadVrV* t = (struct ThreadVrV *) arg;
70
+
71
+ int i;
72
+ for (i = 0; i < t->count; i++) {
73
+ (*t->closure)();
74
+ }
75
+
76
+ return NULL;
77
+ }
78
+
79
+ void testThreadedClosureVrV(void (*closure)(void), int n)
80
+ {
81
+ struct ThreadVrV arg = {closure, n};
82
+ #ifndef _WIN32
83
+ pthread_t t;
84
+ pthread_create(&t, NULL, threadVrV, &arg);
85
+ pthread_join(t, NULL);
86
+ #else
87
+ HANDLE hThread = (HANDLE) _beginthread((void (*)(void *))threadVrV, 0, &arg);
88
+ WaitForSingleObject(hThread, INFINITE);
89
+ #endif
90
+ }
91
+
92
+ struct s8f32s32 {
93
+ char s8;
94
+ float f32;
95
+ int s32;
96
+ };
97
+
98
+ // Takes a struct argument
99
+ void testClosureTrV(void (*closure)(struct s8f32s32 s), struct s8f32s32* s)
100
+ {
101
+ (*closure)(*s);
102
+ }
103
+
104
+ // Returns a struct value
105
+ struct s8f32s32 testClosureVrT(struct s8f32s32 (*closure)())
106
+ {
107
+ return (*closure)();
108
+ }
109
+
110
+ typedef int (*returnTypeClosure_t)(int) ;
111
+ typedef returnTypeClosure_t (*lookupClosure_t)();
112
+
113
+ int testReturnsClosure(lookupClosure_t lookup, int val)
114
+ {
115
+ returnTypeClosure_t func = lookup ? (*lookup)() : NULL;
116
+ return func ? (*func)(val) : 0;
117
+ }
118
+
119
+ static int multiplyByTwo(int value)
120
+ {
121
+ return value * 2;
122
+ }
123
+
124
+ returnTypeClosure_t testReturnsFunctionPointer()
125
+ {
126
+ return multiplyByTwo;
127
+ }
128
+
129
+ typedef int (*argumentClosure_t)(int);
130
+ typedef int (*withArgumentClosure_t)(argumentClosure_t, int);
131
+
132
+ int testArgumentClosure(withArgumentClosure_t closure_with, argumentClosure_t closure_arg, int val)
133
+ {
134
+ return (*closure_with)(closure_arg, val);
135
+ }
136
+
137
+
138
+ //
139
+ // These macros produce functions of the form:
140
+ // testClosureBIrV(void (*closure)(char, int), char a1, int a2) {}
141
+ //
142
+ #define C2_(J1, J2, N1, N2) \
143
+ void testClosure##J1##J2##rV(void (*closure)(N1, N2), N1 a1, N2 a2) \
144
+ { \
145
+ if (closure != NULL) (*closure)(a1, a2); \
146
+ }
147
+
148
+ #define C2(J, N) \
149
+ C2_(B, J, char, N) \
150
+ C2_(S, J, short, N) \
151
+ C2_(I, J, int, N) \
152
+ C2_(LL, J, long long, N) \
153
+ C2_(F, J, float, N) \
154
+ C2_(D, J, double, N) \
155
+
156
+
157
+ C2(B, char);
158
+ C2(S, short);
159
+ C2(I, int);
160
+ C2(LL, long long);
161
+ C2(F, float);
162
+ C2(D, double);
163
+
164
+ #define C3_(J1, J2, J3, N1, N2, N3) \
165
+ void testClosure##J1##J2##J3##rV(void (*closure)(N1, N2, N3), N1 a1, N2 a2, N3 a3) \
166
+ { \
167
+ (*closure)(a1, a2, a3); \
168
+ }
169
+
170
+
171
+ #define C3(J, N) \
172
+ C3_(B, J, B, char, N, char) \
173
+ C3_(S, J, S, short, N, short) \
174
+ C3_(I, J, I, int, N, int) \
175
+ C3_(LL, J, LL, long long, N, long long) \
176
+ C3_(F, J, F, float, N, float) \
177
+ C3_(D, J, D, double, N, double) \
178
+
179
+ C3(B, char);
180
+ C3(S, short);
181
+ C3(I, int);
182
+ C3(LL, long long);
183
+ C3(F, float);
184
+ C3(D, double);
185
+ C3_(B, S, I, char, short, int);
186
+ C3_(B, S, LL, char, short, long long);
187
+ C3_(LL, S, B, long long, short, char);
188
+ C3_(LL, B, S, long long, char, short);
189
+
190
+