ffi 1.1.6.pre2-x86-mingw32 → 1.2.0.pre2-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.
- data/COPYING +674 -0
- data/COPYING.LESSER +165 -0
- data/README.md +104 -0
- data/Rakefile +36 -43
- data/ext/ffi_c/LongDouble.c +4 -0
- data/ext/ffi_c/LongDouble.c.orig +65 -0
- data/ext/ffi_c/MethodHandle.c +1 -1
- data/ext/ffi_c/Types.h +1 -0
- data/ext/ffi_c/Variadic.c +4 -0
- data/ext/ffi_c/extconf.rb +1 -0
- data/ext/ffi_c/libffi.bsd.mk +1 -1
- data/ext/ffi_c/libffi.darwin.mk +6 -4
- data/ext/ffi_c/libffi.mk +1 -1
- data/lib/1.8/ffi_c.so +0 -0
- data/lib/1.9/ffi_c.so +0 -0
- data/lib/ffi/autopointer.rb +9 -8
- data/lib/ffi/enum.rb +2 -1
- data/libtest/Benchmark.c +66 -0
- data/libtest/BoolTest.c +45 -0
- data/libtest/BufferTest.c +45 -0
- data/libtest/ClosureTest.c +204 -0
- data/libtest/EnumTest.c +48 -0
- data/libtest/FunctionTest.c +72 -0
- data/libtest/GNUmakefile +149 -0
- data/libtest/GlobalVariable.c +76 -0
- data/libtest/LastErrorTest.c +35 -0
- data/libtest/NumberTest.c +146 -0
- data/libtest/PointerTest.c +77 -0
- data/libtest/ReferenceTest.c +37 -0
- data/libtest/StringTest.c +48 -0
- data/libtest/StructTest.c +254 -0
- data/libtest/UnionTest.c +57 -0
- data/libtest/VariadicTest.c +76 -0
- data/spec/ffi/enum_spec.rb +4 -0
- data/spec/ffi/pointer_spec.rb +17 -0
- metadata +85 -40
- data/README.rdoc +0 -102
- data/tasks/ann.rake +0 -80
- data/tasks/extension.rake +0 -32
- data/tasks/gem.rake +0 -199
- data/tasks/git.rake +0 -41
- data/tasks/notes.rake +0 -27
- data/tasks/post_load.rake +0 -34
- data/tasks/rdoc.rake +0 -50
- data/tasks/rubyforge.rake +0 -55
- data/tasks/setup.rb +0 -301
- data/tasks/spec.rake +0 -54
- data/tasks/svn.rake +0 -47
- data/tasks/test.rake +0 -40
- data/tasks/yard.rake +0 -11
@@ -0,0 +1,77 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* This file is part of ruby-ffi.
|
7
|
+
*
|
8
|
+
* This code is free software: you can redistribute it and/or modify it under
|
9
|
+
* the terms of the GNU Lesser General Public License version 3 only, as
|
10
|
+
* published by the Free Software Foundation.
|
11
|
+
*
|
12
|
+
* This code is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
15
|
+
* version 3 for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
18
|
+
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include <sys/types.h>
|
22
|
+
#include <sys/param.h>
|
23
|
+
#include <stdint.h>
|
24
|
+
#include <stdio.h>
|
25
|
+
#include <stdlib.h>
|
26
|
+
#include <string.h>
|
27
|
+
typedef void* ptr;
|
28
|
+
typedef void* pointer;
|
29
|
+
#ifdef _WIN32
|
30
|
+
typedef char* caddr_t;
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#define RET(T) T ptr_ret_##T(void* arg1, int offset) { \
|
34
|
+
T tmp; memcpy(&tmp, (caddr_t) arg1 + offset, sizeof(tmp)); return tmp; \
|
35
|
+
}
|
36
|
+
#define SET(T) void ptr_set_##T(void* arg1, int offset, T value) { \
|
37
|
+
memcpy((caddr_t) arg1 + offset, &value, sizeof(value)); \
|
38
|
+
}
|
39
|
+
#define TEST(T) SET(T) RET(T)
|
40
|
+
|
41
|
+
TEST(int8_t);
|
42
|
+
TEST(int16_t);
|
43
|
+
TEST(int32_t);
|
44
|
+
TEST(int64_t);
|
45
|
+
TEST(float);
|
46
|
+
TEST(double);
|
47
|
+
TEST(pointer);
|
48
|
+
|
49
|
+
void*
|
50
|
+
ptr_return_array_element(void **ptrArray, int arrayIndex)
|
51
|
+
{
|
52
|
+
return ptrArray[arrayIndex];
|
53
|
+
}
|
54
|
+
|
55
|
+
void
|
56
|
+
ptr_set_array_element(void **ptrArray, int arrayIndex, void *value)
|
57
|
+
{
|
58
|
+
ptrArray[arrayIndex] = value;
|
59
|
+
}
|
60
|
+
|
61
|
+
void*
|
62
|
+
ptr_malloc(int size)
|
63
|
+
{
|
64
|
+
return calloc(1, size);
|
65
|
+
}
|
66
|
+
void
|
67
|
+
ptr_free(void* ptr)
|
68
|
+
{
|
69
|
+
free(ptr);
|
70
|
+
}
|
71
|
+
|
72
|
+
void*
|
73
|
+
ptr_from_address(uintptr_t addr)
|
74
|
+
{
|
75
|
+
return (void *) addr;
|
76
|
+
}
|
77
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* This file is part of ruby-ffi.
|
7
|
+
*
|
8
|
+
* This code is free software: you can redistribute it and/or modify it under
|
9
|
+
* the terms of the GNU Lesser General Public License version 3 only, as
|
10
|
+
* published by the Free Software Foundation.
|
11
|
+
*
|
12
|
+
* This code is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
15
|
+
* version 3 for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
18
|
+
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include <stdint.h>
|
22
|
+
|
23
|
+
#define REF(T) void ref_##T(T arg, T* result) { *result = arg; }
|
24
|
+
#define ADD(T) void ref_add_##T(T arg1, T arg2, T* result) { *result = arg1 + arg2; }
|
25
|
+
#define SUB(T) void ref_sub_##T(T arg1, T arg2, T* result) { *result = arg1 - arg2; }
|
26
|
+
#define MUL(T) void ref_mul_##T(T arg1, T arg2, T* result) { *result = arg1 * arg2; }
|
27
|
+
#define DIV(T) void ref_div_##T(T arg1, T arg2, T* result) { *result = arg1 / arg2; }
|
28
|
+
#define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) REF(T)
|
29
|
+
|
30
|
+
TEST(int8_t);
|
31
|
+
TEST(int16_t);
|
32
|
+
TEST(int32_t);
|
33
|
+
TEST(int64_t);
|
34
|
+
TEST(float);
|
35
|
+
TEST(double);
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* This file is part of ruby-ffi.
|
7
|
+
*
|
8
|
+
* This code is free software: you can redistribute it and/or modify it under
|
9
|
+
* the terms of the GNU Lesser General Public License version 3 only, as
|
10
|
+
* published by the Free Software Foundation.
|
11
|
+
*
|
12
|
+
* This code is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
15
|
+
* version 3 for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
18
|
+
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include <string.h>
|
22
|
+
|
23
|
+
int
|
24
|
+
string_equals(const char* s1, const char* s2)
|
25
|
+
{
|
26
|
+
return strcmp(s1, s2) == 0;
|
27
|
+
}
|
28
|
+
|
29
|
+
void
|
30
|
+
string_set(char* s1, const char* s2)
|
31
|
+
{
|
32
|
+
strcpy(s1, s2);
|
33
|
+
}
|
34
|
+
void
|
35
|
+
string_concat(char* dst, const char* src)
|
36
|
+
{
|
37
|
+
strcat(dst, src);
|
38
|
+
}
|
39
|
+
void
|
40
|
+
string_dummy(char* dummy)
|
41
|
+
{
|
42
|
+
}
|
43
|
+
const char*
|
44
|
+
string_null(void)
|
45
|
+
{
|
46
|
+
return NULL;
|
47
|
+
}
|
48
|
+
|
@@ -0,0 +1,254 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* This file is part of ruby-ffi.
|
7
|
+
*
|
8
|
+
* This code is free software: you can redistribute it and/or modify it under
|
9
|
+
* the terms of the GNU Lesser General Public License version 3 only, as
|
10
|
+
* published by the Free Software Foundation.
|
11
|
+
*
|
12
|
+
* This code is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
15
|
+
* version 3 for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
18
|
+
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include <stdio.h>
|
22
|
+
#include <stdlib.h>
|
23
|
+
#include <stdbool.h>
|
24
|
+
#include <stdint.h>
|
25
|
+
#include <string.h>
|
26
|
+
#include <stdarg.h>
|
27
|
+
|
28
|
+
typedef char s8;
|
29
|
+
typedef short s16;
|
30
|
+
typedef int s32;
|
31
|
+
typedef long long s64;
|
32
|
+
typedef float f32;
|
33
|
+
typedef double f64;
|
34
|
+
|
35
|
+
typedef struct bugged_struct {
|
36
|
+
unsigned char visible;
|
37
|
+
unsigned int x;
|
38
|
+
unsigned int y;
|
39
|
+
short rx;
|
40
|
+
short ry;
|
41
|
+
unsigned char order;
|
42
|
+
unsigned char size;
|
43
|
+
} bugged_struct_t;
|
44
|
+
|
45
|
+
unsigned int
|
46
|
+
bugged_struct_size() {
|
47
|
+
return sizeof(bugged_struct_t);
|
48
|
+
}
|
49
|
+
|
50
|
+
struct test1 {
|
51
|
+
char b;
|
52
|
+
short s;
|
53
|
+
int i;
|
54
|
+
long long j;
|
55
|
+
long l;
|
56
|
+
float f;
|
57
|
+
double d;
|
58
|
+
char string[32];
|
59
|
+
};
|
60
|
+
|
61
|
+
struct struct_with_array {
|
62
|
+
char c;
|
63
|
+
int a[5];
|
64
|
+
};
|
65
|
+
|
66
|
+
struct nested {
|
67
|
+
int i;
|
68
|
+
};
|
69
|
+
|
70
|
+
struct container {
|
71
|
+
char first;
|
72
|
+
struct nested s;
|
73
|
+
};
|
74
|
+
|
75
|
+
int
|
76
|
+
struct_align_nested_struct(struct container* a) { return a->s.i; }
|
77
|
+
|
78
|
+
void*
|
79
|
+
struct_field_array(struct struct_with_array* s) { return &s->a; }
|
80
|
+
|
81
|
+
struct container*
|
82
|
+
struct_make_container_struct(int i)
|
83
|
+
{
|
84
|
+
static struct container cs;
|
85
|
+
memset(&cs, 0, sizeof(cs));
|
86
|
+
cs.first = 1;
|
87
|
+
cs.s.i = i;
|
88
|
+
return &cs;
|
89
|
+
}
|
90
|
+
|
91
|
+
#define T(x, type) \
|
92
|
+
type struct_field_##type(struct test1* t) { return t->x; } \
|
93
|
+
struct type##_align { char first; type value; }; \
|
94
|
+
type struct_align_##type(struct type##_align* a) { return a->value; }
|
95
|
+
|
96
|
+
T(b, s8);
|
97
|
+
T(s, s16);
|
98
|
+
T(i, s32);
|
99
|
+
T(j, s64);
|
100
|
+
T(f, f32);
|
101
|
+
T(d, f64);
|
102
|
+
T(l, long);
|
103
|
+
|
104
|
+
void
|
105
|
+
struct_set_string(struct test1* t, char* s)
|
106
|
+
{
|
107
|
+
strcpy(t->string, s);
|
108
|
+
}
|
109
|
+
|
110
|
+
struct test1*
|
111
|
+
struct_make_struct(char b, short s, int i, long long ll, float f, double d)
|
112
|
+
{
|
113
|
+
static struct test1 t;
|
114
|
+
memset(&t, 0, sizeof(t));
|
115
|
+
t.b = b;
|
116
|
+
t.s = s;
|
117
|
+
t.i = i;
|
118
|
+
t.j = ll;
|
119
|
+
t.f = f;
|
120
|
+
t.d = d;
|
121
|
+
return &t;
|
122
|
+
}
|
123
|
+
|
124
|
+
typedef int (*add_cb)(int a1, int a2);
|
125
|
+
typedef int (*sub_cb)(int a1, int a2);
|
126
|
+
struct test2 {
|
127
|
+
add_cb add_callback;
|
128
|
+
sub_cb sub_callback;
|
129
|
+
};
|
130
|
+
|
131
|
+
int
|
132
|
+
struct_call_add_cb(struct test2* t, int a1, int a2)
|
133
|
+
{
|
134
|
+
return t->add_callback(a1, a2);
|
135
|
+
}
|
136
|
+
|
137
|
+
int
|
138
|
+
struct_call_sub_cb(struct test2* t, int a1, int a2)
|
139
|
+
{
|
140
|
+
return t->sub_callback(a1, a2);
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
struct struct_with_array*
|
145
|
+
struct_make_struct_with_array(int a_0, int a_1, int a_2, int a_3, int a_4)
|
146
|
+
{
|
147
|
+
static struct struct_with_array s;
|
148
|
+
|
149
|
+
memset(&s, 0, sizeof(s));
|
150
|
+
|
151
|
+
s.a[0] = a_0;
|
152
|
+
s.a[1] = a_1;
|
153
|
+
s.a[2] = a_2;
|
154
|
+
s.a[3] = a_3;
|
155
|
+
s.a[4] = a_4;
|
156
|
+
|
157
|
+
return &s;
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
struct s8s32 {
|
162
|
+
char s8;
|
163
|
+
int s32;
|
164
|
+
};
|
165
|
+
|
166
|
+
struct s8s32
|
167
|
+
struct_return_s8s32()
|
168
|
+
{
|
169
|
+
struct s8s32 s;
|
170
|
+
s.s8 = 0x7f;
|
171
|
+
s.s32 = 0x12345678;
|
172
|
+
|
173
|
+
return s;
|
174
|
+
}
|
175
|
+
|
176
|
+
struct s8s32
|
177
|
+
struct_s8s32_set(char s8, int s32)
|
178
|
+
{
|
179
|
+
struct s8s32 s;
|
180
|
+
|
181
|
+
s.s8 = s8;
|
182
|
+
s.s32 = s32;
|
183
|
+
|
184
|
+
return s;
|
185
|
+
}
|
186
|
+
|
187
|
+
int
|
188
|
+
struct_s8s32_get_s8(struct s8s32 s)
|
189
|
+
{
|
190
|
+
return s.s8;
|
191
|
+
}
|
192
|
+
|
193
|
+
int
|
194
|
+
struct_s8s32_get_s32(struct s8s32 s)
|
195
|
+
{
|
196
|
+
return s.s32;
|
197
|
+
}
|
198
|
+
|
199
|
+
struct s8s32
|
200
|
+
struct_s8s32_ret_s8s32(struct s8s32 s)
|
201
|
+
{
|
202
|
+
return s;
|
203
|
+
}
|
204
|
+
|
205
|
+
// Pass a struct and an int arg, ensure the int arg is passed correctly
|
206
|
+
int
|
207
|
+
struct_s8s32_s32_ret_s32(struct s8s32 s, int s32)
|
208
|
+
{
|
209
|
+
return s32;
|
210
|
+
}
|
211
|
+
|
212
|
+
// Pass a struct and a long long arg, ensure the long long arg is passed correctly
|
213
|
+
long long
|
214
|
+
struct_s8s32_s64_ret_s64(struct s8s32 s, long long s64)
|
215
|
+
{
|
216
|
+
return s64;
|
217
|
+
}
|
218
|
+
|
219
|
+
// Pass a struct and a long long arg, ensure the long long arg is passed correctly
|
220
|
+
int
|
221
|
+
struct_s32_ptr_s32_s8s32_ret_s32(int s32a, void *ptr, int s32b, struct s8s32 s)
|
222
|
+
{
|
223
|
+
if (ptr != NULL) *(struct s8s32 *) ptr = s;
|
224
|
+
return s.s32;
|
225
|
+
}
|
226
|
+
|
227
|
+
// Pass a char *, copy into buffer length struct
|
228
|
+
struct struct_string {
|
229
|
+
char *bytes;
|
230
|
+
int len;
|
231
|
+
};
|
232
|
+
|
233
|
+
struct struct_string
|
234
|
+
struct_varargs_ret_struct_string(int len, ...)
|
235
|
+
{
|
236
|
+
struct struct_string ss;
|
237
|
+
va_list vl;
|
238
|
+
char* cp = NULL;
|
239
|
+
|
240
|
+
va_start(vl, len);
|
241
|
+
|
242
|
+
ss.len = len;
|
243
|
+
ss.bytes = va_arg(vl, char *);
|
244
|
+
if (ss.bytes != NULL) {
|
245
|
+
cp = malloc(strlen(ss.bytes) + 1);
|
246
|
+
strcpy(cp, ss.bytes);
|
247
|
+
ss.bytes = cp;
|
248
|
+
}
|
249
|
+
|
250
|
+
va_end(vl);
|
251
|
+
|
252
|
+
return ss;
|
253
|
+
}
|
254
|
+
|
data/libtest/UnionTest.c
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* This file is part of ruby-ffi.
|
7
|
+
*
|
8
|
+
* This code is free software: you can redistribute it and/or modify it under
|
9
|
+
* the terms of the GNU Lesser General Public License version 3 only, as
|
10
|
+
* published by the Free Software Foundation.
|
11
|
+
*
|
12
|
+
* This code is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
15
|
+
* version 3 for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
18
|
+
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include <stdio.h>
|
22
|
+
#include <stdbool.h>
|
23
|
+
#include <stdint.h>
|
24
|
+
#include <string.h>
|
25
|
+
#include <stdlib.h>
|
26
|
+
|
27
|
+
typedef char s8;
|
28
|
+
typedef short s16;
|
29
|
+
typedef int s32;
|
30
|
+
typedef long long s64;
|
31
|
+
typedef float f32;
|
32
|
+
typedef double f64;
|
33
|
+
|
34
|
+
typedef union union_test {
|
35
|
+
char b;
|
36
|
+
short s;
|
37
|
+
int i;
|
38
|
+
long long j;
|
39
|
+
long l;
|
40
|
+
float f;
|
41
|
+
double d;
|
42
|
+
s8 a[10];
|
43
|
+
} union_test_t;
|
44
|
+
|
45
|
+
#define T(x, type) \
|
46
|
+
type union_align_##type(union_test_t* u) { return u->x; } \
|
47
|
+
union_test_t* union_make_union_with_##type(type value) { static union_test_t u; u.x = value; return &u; }
|
48
|
+
|
49
|
+
T(b, s8);
|
50
|
+
T(s, s16);
|
51
|
+
T(i, s32);
|
52
|
+
T(j, s64);
|
53
|
+
T(f, f32);
|
54
|
+
T(d, f64);
|
55
|
+
T(l, long);
|
56
|
+
|
57
|
+
unsigned int union_size() { return sizeof(union_test_t); }
|