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.

Files changed (50) hide show
  1. data/COPYING +674 -0
  2. data/COPYING.LESSER +165 -0
  3. data/README.md +104 -0
  4. data/Rakefile +36 -43
  5. data/ext/ffi_c/LongDouble.c +4 -0
  6. data/ext/ffi_c/LongDouble.c.orig +65 -0
  7. data/ext/ffi_c/MethodHandle.c +1 -1
  8. data/ext/ffi_c/Types.h +1 -0
  9. data/ext/ffi_c/Variadic.c +4 -0
  10. data/ext/ffi_c/extconf.rb +1 -0
  11. data/ext/ffi_c/libffi.bsd.mk +1 -1
  12. data/ext/ffi_c/libffi.darwin.mk +6 -4
  13. data/ext/ffi_c/libffi.mk +1 -1
  14. data/lib/1.8/ffi_c.so +0 -0
  15. data/lib/1.9/ffi_c.so +0 -0
  16. data/lib/ffi/autopointer.rb +9 -8
  17. data/lib/ffi/enum.rb +2 -1
  18. data/libtest/Benchmark.c +66 -0
  19. data/libtest/BoolTest.c +45 -0
  20. data/libtest/BufferTest.c +45 -0
  21. data/libtest/ClosureTest.c +204 -0
  22. data/libtest/EnumTest.c +48 -0
  23. data/libtest/FunctionTest.c +72 -0
  24. data/libtest/GNUmakefile +149 -0
  25. data/libtest/GlobalVariable.c +76 -0
  26. data/libtest/LastErrorTest.c +35 -0
  27. data/libtest/NumberTest.c +146 -0
  28. data/libtest/PointerTest.c +77 -0
  29. data/libtest/ReferenceTest.c +37 -0
  30. data/libtest/StringTest.c +48 -0
  31. data/libtest/StructTest.c +254 -0
  32. data/libtest/UnionTest.c +57 -0
  33. data/libtest/VariadicTest.c +76 -0
  34. data/spec/ffi/enum_spec.rb +4 -0
  35. data/spec/ffi/pointer_spec.rb +17 -0
  36. metadata +85 -40
  37. data/README.rdoc +0 -102
  38. data/tasks/ann.rake +0 -80
  39. data/tasks/extension.rake +0 -32
  40. data/tasks/gem.rake +0 -199
  41. data/tasks/git.rake +0 -41
  42. data/tasks/notes.rake +0 -27
  43. data/tasks/post_load.rake +0 -34
  44. data/tasks/rdoc.rake +0 -50
  45. data/tasks/rubyforge.rake +0 -55
  46. data/tasks/setup.rb +0 -301
  47. data/tasks/spec.rake +0 -54
  48. data/tasks/svn.rake +0 -47
  49. data/tasks/test.rake +0 -40
  50. data/tasks/yard.rake +0 -11
@@ -77,7 +77,7 @@ typedef int bool;
77
77
  static bool prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize);
78
78
  static long trampoline_size(void);
79
79
 
80
- #if defined(__x86_64__) && defined(__GNUC__)
80
+ #if defined(__x86_64__) && defined(__GNUC__) && !defined(__sun)
81
81
  # define CUSTOM_TRAMPOLINE 1
82
82
  #endif
83
83
 
@@ -66,6 +66,7 @@ typedef enum {
66
66
  NATIVE_MAPPED,
67
67
  } NativeType;
68
68
 
69
+ #include <ffi.h>
69
70
  #include "Type.h"
70
71
 
71
72
  VALUE rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr);
@@ -221,7 +221,11 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
221
221
  if (ffiReturnType == NULL) {
222
222
  rb_raise(rb_eArgError, "Invalid return type");
223
223
  }
224
+ #ifdef HAVE_FFI_PREP_CIF_VAR
225
+ ffiStatus = ffi_prep_cif_var(&cif, invoker->abi, paramCount, paramCount, ffiReturnType, ffiParamTypes);
226
+ #else
224
227
  ffiStatus = ffi_prep_cif(&cif, invoker->abi, paramCount, ffiReturnType, ffiParamTypes);
228
+ #endif
225
229
  switch (ffiStatus) {
226
230
  case FFI_BAD_ABI:
227
231
  rb_raise(rb_eArgError, "Invalid ABI specified");
@@ -26,6 +26,7 @@ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
26
26
  have_func('rb_thread_blocking_region')
27
27
  have_func('ruby_native_thread_p')
28
28
  have_func('rb_thread_call_with_gvl')
29
+ have_func('ffi_prep_cif_var')
29
30
 
30
31
  $defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works
31
32
  $defs << "-DUSE_INTERNAL_LIBFFI" unless libffi_ok
@@ -27,7 +27,7 @@ $(LIBFFI):
27
27
  @if [ ! -f ${LIBFFI_BUILD_DIR}/Makefile ]; then \
28
28
  echo "Configuring libffi"; \
29
29
  cd ${LIBFFI_BUILD_DIR} && \
30
- /usr/bin/env CC="${CC}" LD="${LD}" CFLAGS="${LIBFFI_CFLAGS}" \
30
+ /usr/bin/env CC="${CC}" LD="${LD}" CFLAGS="${LIBFFI_CFLAGS}" GREP_OPTIONS="" \
31
31
  /bin/sh ${LIBFFI_CONFIGURE} ${LIBFFI_HOST} > /dev/null; \
32
32
  fi
33
33
  @cd ${LIBFFI_BUILD_DIR} && ${MAKE}
@@ -9,15 +9,17 @@ INCFLAGS += -I"$(BUILD_DIR)"
9
9
 
10
10
  # Work out which arches we need to compile the lib for
11
11
  ARCHES :=
12
- ifneq ($(findstring -arch ppc,$(CFLAGS)),)
12
+ ARCHFLAGS ?= $(filter -arch %, $(CFLAGS))
13
+
14
+ ifneq ($(findstring -arch ppc,$(ARCHFLAGS)),)
13
15
  ARCHES += ppc
14
16
  endif
15
17
 
16
- ifneq ($(findstring -arch i386,$(CFLAGS)),)
18
+ ifneq ($(findstring -arch i386,$(ARCHFLAGS)),)
17
19
  ARCHES += i386
18
20
  endif
19
21
 
20
- ifneq ($(findstring -arch x86_64,$(CFLAGS)),)
22
+ ifneq ($(findstring -arch x86_64,$(ARCHFLAGS)),)
21
23
  ARCHES += x86_64
22
24
  endif
23
25
 
@@ -29,7 +31,7 @@ $(LIBFFI):
29
31
  @if [ ! -f "$(LIBFFI_BUILD_DIR)"/Makefile ]; then \
30
32
  echo "Configuring libffi"; \
31
33
  cd "$(LIBFFI_BUILD_DIR)" && \
32
- /usr/bin/env CC="$(CC)" LD="$(LD)" CFLAGS="$(LIBFFI_CFLAGS)" \
34
+ /usr/bin/env CC="$(CC)" LD="$(LD)" CFLAGS="$(LIBFFI_CFLAGS)" GREP_OPTIONS="" \
33
35
  /bin/sh $(LIBFFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \
34
36
  fi
35
37
  cd "$(LIBFFI_BUILD_DIR)" && $(MAKE)
@@ -7,7 +7,7 @@ $(LIBFFI):
7
7
  @if [ ! -f "$(LIBFFI_BUILD_DIR)"/Makefile ]; then \
8
8
  echo "Configuring libffi"; \
9
9
  cd "$(LIBFFI_BUILD_DIR)" && \
10
- /usr/bin/env CFLAGS="$(LIBFFI_CFLAGS)" \
10
+ /usr/bin/env CFLAGS="$(LIBFFI_CFLAGS)" GREP_OPTIONS="" \
11
11
  /bin/sh $(LIBFFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \
12
12
  fi
13
13
  $(MAKE) -C "$(LIBFFI_BUILD_DIR)"
Binary file
Binary file
@@ -94,11 +94,19 @@ module FFI
94
94
  @releaser.autorelease=(autorelease)
95
95
  end
96
96
 
97
+ # @return [Boolean] +autorelease+
98
+ # Get +autorelease+ property. See {Pointer Autorelease section at Pointer}.
99
+ def autorelease?
100
+ @releaser.autorelease
101
+ end
102
+
97
103
  # @abstract Base class for {AutoPointer}'s releasers.
98
104
  #
99
105
  # All subclasses of Releaser should define a +#release(ptr)+ method.
100
106
  # A releaser is an object in charge of release an {AutoPointer}.
101
107
  class Releaser
108
+ attr_accessor :autorelease
109
+
102
110
  # @param [Pointer] ptr
103
111
  # @param [#call] proc
104
112
  # @return [nil]
@@ -119,14 +127,7 @@ module FFI
119
127
  @proc = nil
120
128
  end
121
129
  end
122
-
123
- # @param [Boolean] autorelease
124
- # @return [Boolean] autorelease
125
- # Set +autorelease+ attribute for pointer managed by Releaser.
126
- def autorelease=(autorelease)
127
- @autorelease = autorelease if @ptr
128
- end
129
-
130
+
130
131
  # @param args
131
132
  # Release pointer if +autorelease+ is set.
132
133
  def call(*args)
@@ -86,6 +86,7 @@ module FFI
86
86
  info.each do |i|
87
87
  case i
88
88
  when Symbol
89
+ raise ArgumentError, "duplicate enum key" if @kv_map.has_key?(i)
89
90
  @kv_map[i] = value
90
91
  last_cst = i
91
92
  value += 1
@@ -95,7 +96,7 @@ module FFI
95
96
  end
96
97
  end
97
98
  end
98
- @vk_map = Hash[@kv_map.map{|k,v| [v,k]}]
99
+ @vk_map = @kv_map.invert
99
100
  end
100
101
 
101
102
  # @return [Array] enum symbol names
@@ -0,0 +1,66 @@
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
+ #include <sys/types.h>
21
+ #include <stdint.h>
22
+
23
+ void returnVoid() {
24
+
25
+ }
26
+
27
+ void returnVoidI(int arg) {
28
+
29
+ }
30
+ int returnInt() {
31
+ return 0;
32
+ }
33
+
34
+ int returnIntI(int arg) {
35
+ return arg;
36
+ }
37
+
38
+ typedef int8_t s8;
39
+ typedef uint8_t u8;
40
+ typedef int16_t s16;
41
+ typedef uint16_t u16;
42
+ typedef int32_t s32;
43
+ typedef uint32_t u32;
44
+ typedef int64_t s64;
45
+ typedef uint64_t u64;
46
+ typedef float f32;
47
+ typedef double f64;
48
+ typedef void v;
49
+ typedef char* S;
50
+ typedef void* P;
51
+
52
+ #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) {}
53
+ #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) {}
54
+ #define B4(R, T1, T2, T3, T4) R bench_##T1##T2##T3##T4##_##R(T1 a1, T2 a2, T3 a3, T4 a4) {}
55
+ #define B3(R, T1, T2, T3) R bench_##T1##T2##T3##_##R(T1 a1, T2 a2, T3 a3) {}
56
+ #define B2(R, T1, T2) R bench_##T1##T2##_##R(T1 a1, T2 a2) {}
57
+ #define B1(R, T1) R bench_##T1##_##R(T1 a1) {}
58
+ #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);
59
+ BrV(u32);
60
+ BrV(s32);
61
+ BrV(s64);
62
+ BrV(u64);
63
+ BrV(f32);
64
+ BrV(f64);
65
+ BrV(S);
66
+ BrV(P);
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright (c) 2009 Aman Gupta. 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 <stdbool.h>
22
+
23
+ bool
24
+ bool_return_true()
25
+ {
26
+ return true;
27
+ }
28
+
29
+ bool
30
+ bool_return_false()
31
+ {
32
+ return false;
33
+ }
34
+
35
+ bool
36
+ bool_return_val(bool value)
37
+ {
38
+ return value;
39
+ }
40
+
41
+ bool
42
+ bool_reverse_val(bool value)
43
+ {
44
+ return value ? false : true;
45
+ }
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright (C) 2007 Wayne Meissner
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
+
22
+ #define MEMSET(buf, value, size) do { \
23
+ int i; for (i = 0; i < size; ++i) buf[i] = value; \
24
+ } while(0)
25
+ #define MEMCPY(dst, src, size) do { \
26
+ int i; for (i = 0; i < size; ++i) dst[i] = src[i]; \
27
+ } while(0)
28
+
29
+ #define FILL(JTYPE, CTYPE) \
30
+ void fill##JTYPE##Buffer(CTYPE* buf, CTYPE value, int size) { MEMSET(buf, value, size); }
31
+
32
+ #define COPY(JTYPE, CTYPE) \
33
+ void copy##JTYPE##Buffer(CTYPE* dst, CTYPE* src, int size) { MEMCPY(dst, src, size); }
34
+
35
+ #define FUNC(JTYPE, CTYPE) \
36
+ FILL(JTYPE, CTYPE); \
37
+ COPY(JTYPE, CTYPE)
38
+
39
+ FUNC(Byte, char);
40
+ FUNC(Short, short);
41
+ FUNC(Int, int);
42
+ FUNC(Long, long long);
43
+ FUNC(Float, float);
44
+ FUNC(Double, double);
45
+
@@ -0,0 +1,204 @@
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 <stdlib.h>
22
+ #include <stdbool.h>
23
+ #ifndef _WIN32
24
+ # include <pthread.h>
25
+ #else
26
+ # include <windows.h>
27
+ # include <process.h>
28
+ #endif
29
+
30
+ #define R(T, rtype) rtype testClosureVr##T(rtype (*closure)(void)) { \
31
+ return closure != NULL ? (*closure)() : (rtype) 0; \
32
+ }
33
+
34
+ #define P(T, ptype) void testClosure##T##rV(void (*closure)(ptype), ptype a1) { \
35
+ if (closure != NULL) (*closure)(a1); \
36
+ }
37
+
38
+ void testClosureVrV(void (*closure)(void))
39
+ {
40
+ (*closure)();
41
+ }
42
+
43
+ R(Z, bool);
44
+ R(B, char);
45
+ R(S, short);
46
+ R(I, int);
47
+ R(L, long);
48
+ R(J, long long);
49
+ R(LL, long long);
50
+ R(F, float);
51
+ R(D, double);
52
+ R(P, const void*);
53
+
54
+
55
+ P(Z, bool);
56
+ P(B, char);
57
+ P(S, short);
58
+ P(I, int);
59
+ P(L, long);
60
+ P(J, long long);
61
+ P(LL, long long);
62
+ P(F, float);
63
+ P(D, double);
64
+ P(P, const void*);
65
+ P(UL, unsigned long);
66
+
67
+ void testOptionalClosureBrV(void (*closure)(char), char a1)
68
+ {
69
+ if (closure) {
70
+ (*closure)(a1);
71
+ }
72
+ }
73
+
74
+
75
+ struct ThreadVrV {
76
+ void (*closure)(void);
77
+ int count;
78
+ };
79
+
80
+ static void *
81
+ threadVrV(void *arg)
82
+ {
83
+ struct ThreadVrV* t = (struct ThreadVrV *) arg;
84
+
85
+ int i;
86
+ for (i = 0; i < t->count; i++) {
87
+ (*t->closure)();
88
+ }
89
+
90
+ return NULL;
91
+ }
92
+
93
+ void testThreadedClosureVrV(void (*closure)(void), int n)
94
+ {
95
+ struct ThreadVrV arg = {closure, n};
96
+ #ifndef _WIN32
97
+ pthread_t t;
98
+ pthread_create(&t, NULL, threadVrV, &arg);
99
+ pthread_join(t, NULL);
100
+ #else
101
+ HANDLE hThread = (HANDLE) _beginthread((void (*)(void *))threadVrV, 0, &arg);
102
+ WaitForSingleObject(hThread, INFINITE);
103
+ #endif
104
+ }
105
+
106
+ struct s8f32s32 {
107
+ char s8;
108
+ float f32;
109
+ int s32;
110
+ };
111
+
112
+ // Takes a struct argument
113
+ void testClosureTrV(void (*closure)(struct s8f32s32 s), struct s8f32s32* s)
114
+ {
115
+ (*closure)(*s);
116
+ }
117
+
118
+ // Returns a struct value
119
+ struct s8f32s32 testClosureVrT(struct s8f32s32 (*closure)())
120
+ {
121
+ return (*closure)();
122
+ }
123
+
124
+ typedef int (*returnTypeClosure_t)(int) ;
125
+ typedef returnTypeClosure_t (*lookupClosure_t)();
126
+
127
+ int testReturnsClosure(lookupClosure_t lookup, int val)
128
+ {
129
+ returnTypeClosure_t func = lookup ? (*lookup)() : NULL;
130
+ return func ? (*func)(val) : 0;
131
+ }
132
+
133
+ static int multiplyByTwo(int value)
134
+ {
135
+ return value * 2;
136
+ }
137
+
138
+ returnTypeClosure_t testReturnsFunctionPointer()
139
+ {
140
+ return multiplyByTwo;
141
+ }
142
+
143
+ typedef int (*argumentClosure_t)(int);
144
+ typedef int (*withArgumentClosure_t)(argumentClosure_t, int);
145
+
146
+ int testArgumentClosure(withArgumentClosure_t closure_with, argumentClosure_t closure_arg, int val)
147
+ {
148
+ return (*closure_with)(closure_arg, val);
149
+ }
150
+
151
+
152
+ //
153
+ // These macros produce functions of the form:
154
+ // testClosureBIrV(void (*closure)(char, int), char a1, int a2) {}
155
+ //
156
+ #define C2_(J1, J2, N1, N2) \
157
+ void testClosure##J1##J2##rV(void (*closure)(N1, N2), N1 a1, N2 a2) \
158
+ { \
159
+ if (closure != NULL) (*closure)(a1, a2); \
160
+ }
161
+
162
+ #define C2(J, N) \
163
+ C2_(B, J, char, N) \
164
+ C2_(S, J, short, N) \
165
+ C2_(I, J, int, N) \
166
+ C2_(LL, J, long long, N) \
167
+ C2_(F, J, float, N) \
168
+ C2_(D, J, double, N) \
169
+
170
+
171
+ C2(B, char);
172
+ C2(S, short);
173
+ C2(I, int);
174
+ C2(LL, long long);
175
+ C2(F, float);
176
+ C2(D, double);
177
+
178
+ #define C3_(J1, J2, J3, N1, N2, N3) \
179
+ void testClosure##J1##J2##J3##rV(void (*closure)(N1, N2, N3), N1 a1, N2 a2, N3 a3) \
180
+ { \
181
+ (*closure)(a1, a2, a3); \
182
+ }
183
+
184
+
185
+ #define C3(J, N) \
186
+ C3_(B, J, B, char, N, char) \
187
+ C3_(S, J, S, short, N, short) \
188
+ C3_(I, J, I, int, N, int) \
189
+ C3_(LL, J, LL, long long, N, long long) \
190
+ C3_(F, J, F, float, N, float) \
191
+ C3_(D, J, D, double, N, double) \
192
+
193
+ C3(B, char);
194
+ C3(S, short);
195
+ C3(I, int);
196
+ C3(LL, long long);
197
+ C3(F, float);
198
+ C3(D, double);
199
+ C3_(B, S, I, char, short, int);
200
+ C3_(B, S, LL, char, short, long long);
201
+ C3_(LL, S, B, long long, short, char);
202
+ C3_(LL, B, S, long long, char, short);
203
+
204
+