ffi 0.6.4 → 1.0.0

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 (92) hide show
  1. data/History.txt +7 -0
  2. data/LICENSE +10 -21
  3. data/README.rdoc +70 -0
  4. data/Rakefile +56 -84
  5. data/ext/ffi_c/AbstractMemory.c +56 -38
  6. data/ext/ffi_c/AbstractMemory.h +15 -22
  7. data/ext/ffi_c/Buffer.c +61 -22
  8. data/ext/ffi_c/Call.c +52 -540
  9. data/ext/ffi_c/Call.h +1 -1
  10. data/ext/ffi_c/DataConverter.c +62 -0
  11. data/ext/ffi_c/DynamicLibrary.c +21 -1
  12. data/ext/ffi_c/Function.c +252 -30
  13. data/ext/ffi_c/MappedType.c +146 -0
  14. data/{libtest/FunctionTest.c → ext/ffi_c/MappedType.h} +32 -25
  15. data/ext/ffi_c/MemoryPointer.c +12 -33
  16. data/ext/ffi_c/Platform.c +2 -0
  17. data/ext/ffi_c/Pointer.c +66 -28
  18. data/ext/ffi_c/Struct.c +19 -306
  19. data/ext/ffi_c/Struct.h +6 -0
  20. data/ext/ffi_c/StructByReference.c +150 -0
  21. data/{libtest/LastErrorTest.c → ext/ffi_c/StructByReference.h} +30 -21
  22. data/ext/ffi_c/StructLayout.c +26 -16
  23. data/ext/ffi_c/Type.c +39 -68
  24. data/ext/ffi_c/Type.h +12 -22
  25. data/ext/ffi_c/Types.c +20 -5
  26. data/ext/ffi_c/Types.h +7 -7
  27. data/ext/ffi_c/Variadic.c +21 -17
  28. data/ext/ffi_c/extconf.rb +4 -0
  29. data/ext/ffi_c/ffi.c +8 -2
  30. data/ext/ffi_c/rbffi.h +1 -0
  31. data/lib/ffi/autopointer.rb +23 -22
  32. data/lib/ffi/enum.rb +36 -21
  33. data/lib/ffi/errno.rb +20 -0
  34. data/lib/ffi/ffi.rb +13 -80
  35. data/lib/ffi/io.rb +12 -20
  36. data/lib/ffi/library.rb +109 -92
  37. data/lib/ffi/managedstruct.rb +1 -1
  38. data/lib/ffi/memorypointer.rb +15 -21
  39. data/lib/ffi/platform.rb +27 -33
  40. data/lib/ffi/pointer.rb +14 -21
  41. data/lib/ffi/struct.rb +98 -49
  42. data/lib/ffi/struct_layout_builder.rb +158 -0
  43. data/lib/ffi/types.rb +99 -128
  44. data/lib/ffi/union.rb +20 -0
  45. data/lib/ffi/variadic.rb +33 -22
  46. data/spec/ffi/async_callback_spec.rb +23 -0
  47. data/spec/ffi/callback_spec.rb +62 -0
  48. data/spec/ffi/custom_param_type.rb +31 -0
  49. data/spec/ffi/custom_type_spec.rb +73 -0
  50. data/spec/ffi/enum_spec.rb +19 -0
  51. data/spec/ffi/ffi_spec.rb +24 -0
  52. data/spec/ffi/pointer_spec.rb +15 -0
  53. data/spec/ffi/rbx/memory_pointer_spec.rb +7 -1
  54. data/spec/ffi/strptr_spec.rb +36 -0
  55. data/spec/ffi/struct_packed_spec.rb +46 -0
  56. data/spec/ffi/struct_spec.rb +19 -5
  57. data/spec/ffi/typedef_spec.rb +14 -0
  58. data/tasks/ann.rake +80 -0
  59. data/tasks/extension.rake +25 -0
  60. data/tasks/gem.rake +200 -0
  61. data/tasks/git.rake +41 -0
  62. data/tasks/notes.rake +27 -0
  63. data/tasks/post_load.rake +34 -0
  64. data/tasks/rdoc.rake +50 -0
  65. data/tasks/rubyforge.rake +55 -0
  66. data/tasks/setup.rb +301 -0
  67. data/tasks/spec.rake +54 -0
  68. data/tasks/svn.rake +47 -0
  69. data/tasks/test.rake +40 -0
  70. metadata +139 -131
  71. data/README.md +0 -109
  72. data/ext/ffi_c/AutoPointer.c +0 -60
  73. data/ext/ffi_c/AutoPointer.h +0 -18
  74. data/ext/ffi_c/Ffi_c.iml +0 -12
  75. data/ffi.gemspec +0 -18
  76. data/gen/log +0 -1
  77. data/lib/Lib.iml +0 -21
  78. data/libtest/Benchmark.c +0 -73
  79. data/libtest/BoolTest.c +0 -52
  80. data/libtest/BufferTest.c +0 -52
  81. data/libtest/ClosureTest.c +0 -173
  82. data/libtest/EnumTest.c +0 -55
  83. data/libtest/GNUmakefile +0 -141
  84. data/libtest/GlobalVariable.c +0 -56
  85. data/libtest/NumberTest.c +0 -145
  86. data/libtest/PointerTest.c +0 -84
  87. data/libtest/ReferenceTest.c +0 -44
  88. data/libtest/StringTest.c +0 -55
  89. data/libtest/StructTest.c +0 -247
  90. data/libtest/UnionTest.c +0 -64
  91. data/libtest/VariadicTest.c +0 -57
  92. data/spec/ffi/Ffi.iml +0 -12
@@ -1,44 +0,0 @@
1
- /*
2
- * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
- *
4
- * Redistribution and use in source and binary forms, with or without
5
- * modification, are permitted provided that the following conditions are met:
6
- *
7
- * Redistributions of source code must retain the above copyright notice, this
8
- * list of conditions and the following disclaimer.
9
- * Redistributions in binary form must reproduce the above copyright notice
10
- * this list of conditions and the following disclaimer in the documentation
11
- * and/or other materials provided with the distribution.
12
- * Neither the name of the project nor the names of its contributors
13
- * may be used to endorse or promote products derived from this software
14
- * without specific prior written permission.
15
- *
16
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- */
27
-
28
- #include <stdint.h>
29
-
30
- #define REF(T) void ref_##T(T arg, T* result) { *result = arg; }
31
- #define ADD(T) void ref_add_##T(T arg1, T arg2, T* result) { *result = arg1 + arg2; }
32
- #define SUB(T) void ref_sub_##T(T arg1, T arg2, T* result) { *result = arg1 - arg2; }
33
- #define MUL(T) void ref_mul_##T(T arg1, T arg2, T* result) { *result = arg1 * arg2; }
34
- #define DIV(T) void ref_div_##T(T arg1, T arg2, T* result) { *result = arg1 / arg2; }
35
- #define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) REF(T)
36
-
37
- TEST(int8_t);
38
- TEST(int16_t);
39
- TEST(int32_t);
40
- TEST(int64_t);
41
- TEST(float);
42
- TEST(double);
43
-
44
-
data/libtest/StringTest.c DELETED
@@ -1,55 +0,0 @@
1
- /*
2
- * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
- *
4
- * Redistribution and use in source and binary forms, with or without
5
- * modification, are permitted provided that the following conditions are met:
6
- *
7
- * Redistributions of source code must retain the above copyright notice, this
8
- * list of conditions and the following disclaimer.
9
- * Redistributions in binary form must reproduce the above copyright notice
10
- * this list of conditions and the following disclaimer in the documentation
11
- * and/or other materials provided with the distribution.
12
- * Neither the name of the project nor the names of its contributors
13
- * may be used to endorse or promote products derived from this software
14
- * without specific prior written permission.
15
- *
16
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- */
27
-
28
- #include <string.h>
29
-
30
- int
31
- string_equals(const char* s1, const char* s2)
32
- {
33
- return strcmp(s1, s2) == 0;
34
- }
35
-
36
- void
37
- string_set(char* s1, const char* s2)
38
- {
39
- strcpy(s1, s2);
40
- }
41
- void
42
- string_concat(char* dst, const char* src)
43
- {
44
- strcat(dst, src);
45
- }
46
- void
47
- string_dummy(char* dummy)
48
- {
49
- }
50
- const char*
51
- string_null(void)
52
- {
53
- return NULL;
54
- }
55
-
data/libtest/StructTest.c DELETED
@@ -1,247 +0,0 @@
1
- /*
2
- * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
- *
4
- * Redistribution and use in source and binary forms, with or without
5
- * modification, are permitted provided that the following conditions are met:
6
- *
7
- * Redistributions of source code must retain the above copyright notice, this
8
- * list of conditions and the following disclaimer.
9
- * Redistributions in binary form must reproduce the above copyright notice
10
- * this list of conditions and the following disclaimer in the documentation
11
- * and/or other materials provided with the distribution.
12
- * Neither the name of the project nor the names of its contributors
13
- * may be used to endorse or promote products derived from this software
14
- * without specific prior written permission.
15
- *
16
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- */
27
-
28
- #include <stdio.h>
29
- #include <stdlib.h>
30
- #include <stdbool.h>
31
- #include <stdint.h>
32
- #include <string.h>
33
- #include <stdarg.h>
34
-
35
- typedef char s8;
36
- typedef short s16;
37
- typedef int s32;
38
- typedef long long s64;
39
- typedef float f32;
40
- typedef double f64;
41
-
42
- typedef struct bugged_struct {
43
- unsigned char visible;
44
- unsigned int x;
45
- unsigned int y;
46
- short rx;
47
- short ry;
48
- unsigned char order;
49
- unsigned char size;
50
- } bugged_struct_t;
51
-
52
- unsigned int
53
- bugged_struct_size() {
54
- return sizeof(bugged_struct_t);
55
- }
56
-
57
- struct test1 {
58
- char b;
59
- short s;
60
- int i;
61
- long long j;
62
- long l;
63
- float f;
64
- double d;
65
- char string[32];
66
- };
67
-
68
- struct struct_with_array {
69
- char c;
70
- int a[5];
71
- };
72
-
73
- struct nested {
74
- int i;
75
- };
76
-
77
- struct container {
78
- char first;
79
- struct nested s;
80
- };
81
-
82
- int
83
- struct_align_nested_struct(struct container* a) { return a->s.i; }
84
-
85
- void*
86
- struct_field_array(struct struct_with_array* s) { return &s->a; }
87
-
88
- struct container*
89
- struct_make_container_struct(int i)
90
- {
91
- static struct container cs;
92
- memset(&cs, 0, sizeof(cs));
93
- cs.first = 1;
94
- cs.s.i = i;
95
- return &cs;
96
- }
97
-
98
- #define T(x, type) \
99
- type struct_field_##type(struct test1* t) { return t->x; } \
100
- struct type##_align { char first; type value; }; \
101
- type struct_align_##type(struct type##_align* a) { return a->value; }
102
-
103
- T(b, s8);
104
- T(s, s16);
105
- T(i, s32);
106
- T(j, s64);
107
- T(f, f32);
108
- T(d, f64);
109
- T(l, long);
110
-
111
- void
112
- struct_set_string(struct test1* t, char* s)
113
- {
114
- strcpy(t->string, s);
115
- }
116
-
117
- struct test1*
118
- struct_make_struct(char b, short s, int i, long long ll, float f, double d)
119
- {
120
- static struct test1 t;
121
- memset(&t, 0, sizeof(t));
122
- t.b = b;
123
- t.s = s;
124
- t.i = i;
125
- t.j = ll;
126
- t.f = f;
127
- t.d = d;
128
- return &t;
129
- }
130
-
131
- typedef int (*add_cb)(int a1, int a2);
132
- typedef int (*sub_cb)(int a1, int a2);
133
- struct test2 {
134
- add_cb add_callback;
135
- sub_cb sub_callback;
136
- };
137
-
138
- int
139
- struct_call_add_cb(struct test2* t, int a1, int a2)
140
- {
141
- return t->add_callback(a1, a2);
142
- }
143
-
144
- int
145
- struct_call_sub_cb(struct test2* t, int a1, int a2)
146
- {
147
- return t->sub_callback(a1, a2);
148
- }
149
-
150
-
151
- struct struct_with_array*
152
- struct_make_struct_with_array(int a_0, int a_1, int a_2, int a_3, int a_4)
153
- {
154
- static struct struct_with_array s;
155
-
156
- memset(&s, 0, sizeof(s));
157
-
158
- s.a[0] = a_0;
159
- s.a[1] = a_1;
160
- s.a[2] = a_2;
161
- s.a[3] = a_3;
162
- s.a[4] = a_4;
163
-
164
- return &s;
165
-
166
- }
167
-
168
- struct s8s32 {
169
- char s8;
170
- int s32;
171
- };
172
-
173
- struct s8s32
174
- struct_return_s8s32()
175
- {
176
- struct s8s32 s;
177
- s.s8 = 0x7f;
178
- s.s32 = 0x12345678;
179
-
180
- return s;
181
- }
182
-
183
- struct s8s32
184
- struct_s8s32_set(char s8, int s32)
185
- {
186
- struct s8s32 s;
187
-
188
- s.s8 = s8;
189
- s.s32 = s32;
190
-
191
- return s;
192
- }
193
-
194
- int
195
- struct_s8s32_get_s8(struct s8s32 s)
196
- {
197
- return s.s8;
198
- }
199
-
200
- int
201
- struct_s8s32_get_s32(struct s8s32 s)
202
- {
203
- return s.s32;
204
- }
205
-
206
- // Pass a struct and an int arg, ensure the int arg is passed correctly
207
- int
208
- struct_s8s32_s32_ret_s32(struct s8s32 s, int s32)
209
- {
210
- return s32;
211
- }
212
-
213
- // Pass a struct and a long long arg, ensure the long long arg is passed correctly
214
- long long
215
- struct_s8s32_s64_ret_s64(struct s8s32 s, long long s64)
216
- {
217
- return s64;
218
- }
219
-
220
- // Pass a char *, copy into buffer length struct
221
- struct struct_string {
222
- char *bytes;
223
- int len;
224
- };
225
-
226
- struct struct_string
227
- struct_varargs_ret_struct_string(int len, ...)
228
- {
229
- struct struct_string ss;
230
- va_list vl;
231
- char* cp = NULL;
232
-
233
- va_start(vl, len);
234
-
235
- ss.len = len;
236
- ss.bytes = va_arg(vl, char *);
237
- if (ss.bytes != NULL) {
238
- cp = malloc(strlen(ss.bytes) + 1);
239
- strcpy(cp, ss.bytes);
240
- ss.bytes = cp;
241
- }
242
-
243
- va_end(vl);
244
-
245
- return ss;
246
- }
247
-
data/libtest/UnionTest.c DELETED
@@ -1,64 +0,0 @@
1
- /*
2
- * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
- *
4
- * Redistribution and use in source and binary forms, with or without
5
- * modification, are permitted provided that the following conditions are met:
6
- *
7
- * Redistributions of source code must retain the above copyright notice, this
8
- * list of conditions and the following disclaimer.
9
- * Redistributions in binary form must reproduce the above copyright notice
10
- * this list of conditions and the following disclaimer in the documentation
11
- * and/or other materials provided with the distribution.
12
- * Neither the name of the project nor the names of its contributors
13
- * may be used to endorse or promote products derived from this software
14
- * without specific prior written permission.
15
- *
16
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- */
27
-
28
- #include <stdio.h>
29
- #include <stdbool.h>
30
- #include <stdint.h>
31
- #include <string.h>
32
- #include <stdlib.h>
33
-
34
- typedef char s8;
35
- typedef short s16;
36
- typedef int s32;
37
- typedef long long s64;
38
- typedef float f32;
39
- typedef double f64;
40
-
41
- typedef union union_test {
42
- char b;
43
- short s;
44
- int i;
45
- long long j;
46
- long l;
47
- float f;
48
- double d;
49
- s8 a[10];
50
- } union_test_t;
51
-
52
- #define T(x, type) \
53
- type union_align_##type(union_test_t* u) { return u->x; } \
54
- union_test_t* union_make_union_with_##type(type value) { static union_test_t u; u.x = value; return &u; }
55
-
56
- T(b, s8);
57
- T(s, s16);
58
- T(i, s32);
59
- T(j, s64);
60
- T(f, f32);
61
- T(d, f64);
62
- T(l, long);
63
-
64
- unsigned int union_size() { return sizeof(union_test_t); }
@@ -1,57 +0,0 @@
1
-
2
- #include <sys/types.h>
3
- #include <stdio.h>
4
- #include <stdint.h>
5
- #include <string.h>
6
- #include <stdarg.h>
7
-
8
- typedef int8_t s8;
9
- typedef uint8_t u8;
10
- typedef int16_t s16;
11
- typedef uint16_t u16;
12
- typedef int32_t s32;
13
- typedef uint32_t u32;
14
- typedef int64_t s64;
15
- typedef uint64_t u64;
16
- typedef signed long sL;
17
- typedef unsigned long uL;
18
- typedef float F;
19
- typedef double D;
20
-
21
- void pack_varargs(s64* buf, const char* fmt, ...)
22
- {
23
- va_list ap;
24
- int c;
25
- double d;
26
- va_start(ap, fmt);
27
- while ((c = *fmt++)) {
28
- switch (c) {
29
- case 'c':
30
- case 's':
31
- case 'i':
32
- *buf++ = va_arg(ap, s32);
33
- break;
34
- case 'l':
35
- *buf++ = va_arg(ap, long);
36
- break;
37
- case 'j':
38
- *buf++ = va_arg(ap, s64);
39
- break;
40
- case 'f':
41
- case 'd':
42
- d = va_arg(ap, double);
43
- memcpy(buf++, &d, sizeof(d));
44
- break;
45
- case 'C':
46
- case 'S':
47
- case 'I':
48
- *buf++ = va_arg(ap, u32);
49
- break;
50
- case 'L':
51
- *buf++ = va_arg(ap, unsigned long);
52
- break;
53
- }
54
- }
55
- va_end(ap);
56
- }
57
-