ffi 1.12.2 → 1.15.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +132 -0
  3. data/Gemfile +1 -2
  4. data/README.md +14 -2
  5. data/Rakefile +46 -65
  6. data/ext/ffi_c/AbstractMemory.c +24 -25
  7. data/ext/ffi_c/Buffer.c +4 -9
  8. data/ext/ffi_c/Call.c +3 -15
  9. data/ext/ffi_c/ClosurePool.c +75 -25
  10. data/ext/ffi_c/ClosurePool.h +3 -1
  11. data/ext/ffi_c/DynamicLibrary.c +1 -6
  12. data/ext/ffi_c/Function.c +38 -38
  13. data/ext/ffi_c/Function.h +0 -4
  14. data/ext/ffi_c/FunctionInfo.c +3 -8
  15. data/ext/ffi_c/LastError.c +2 -6
  16. data/ext/ffi_c/LongDouble.c +5 -3
  17. data/ext/ffi_c/LongDouble.h +0 -4
  18. data/ext/ffi_c/MemoryPointer.c +3 -8
  19. data/ext/ffi_c/MemoryPointer.h +0 -4
  20. data/ext/ffi_c/MethodHandle.c +21 -31
  21. data/ext/ffi_c/MethodHandle.h +3 -2
  22. data/ext/ffi_c/Platform.c +3 -7
  23. data/ext/ffi_c/Pointer.c +25 -26
  24. data/ext/ffi_c/Pointer.h +0 -4
  25. data/ext/ffi_c/Struct.c +3 -6
  26. data/ext/ffi_c/StructByValue.c +2 -7
  27. data/ext/ffi_c/StructLayout.c +9 -8
  28. data/ext/ffi_c/Thread.c +0 -8
  29. data/ext/ffi_c/Thread.h +1 -9
  30. data/ext/ffi_c/Type.c +1 -1
  31. data/ext/ffi_c/Types.c +6 -7
  32. data/ext/ffi_c/Types.h +3 -4
  33. data/ext/ffi_c/Variadic.c +14 -9
  34. data/ext/ffi_c/compat.h +4 -0
  35. data/ext/ffi_c/extconf.rb +36 -23
  36. data/ext/ffi_c/libffi/.travis.yml +4 -0
  37. data/ext/ffi_c/libffi/.travis/bfin-sim.exp +1 -1
  38. data/ext/ffi_c/libffi/.travis/build.sh +4 -0
  39. data/ext/ffi_c/libffi/.travis/m32r-sim.exp +1 -1
  40. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +1 -1
  41. data/ext/ffi_c/libffi/.travis/or1k-sim.exp +1 -1
  42. data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +1 -1
  43. data/ext/ffi_c/libffi/.travis/wine-sim.exp +1 -1
  44. data/ext/ffi_c/libffi/Makefile.am +49 -58
  45. data/ext/ffi_c/libffi/Makefile.in +93 -58
  46. data/ext/ffi_c/libffi/README.md +11 -1
  47. data/ext/ffi_c/libffi/config.guess +552 -331
  48. data/ext/ffi_c/libffi/config.sub +1321 -1306
  49. data/ext/ffi_c/libffi/configure +120 -24
  50. data/ext/ffi_c/libffi/configure.ac +31 -10
  51. data/ext/ffi_c/libffi/configure.host +32 -20
  52. data/ext/ffi_c/libffi/fficonfig.h.in +9 -0
  53. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +1 -1
  54. data/ext/ffi_c/libffi/include/ffi.h.in +8 -0
  55. data/ext/ffi_c/libffi/libffi.map.in +8 -12
  56. data/ext/ffi_c/libffi/libtool-version +1 -1
  57. data/ext/ffi_c/libffi/ltmain.sh +6 -4
  58. data/ext/ffi_c/libffi/msvcc.sh +11 -11
  59. data/ext/ffi_c/libffi/src/aarch64/ffi.c +51 -35
  60. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +10 -5
  61. data/ext/ffi_c/libffi/src/aarch64/internal.h +1 -0
  62. data/ext/ffi_c/libffi/src/aarch64/sysv.S +14 -3
  63. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +1 -1
  64. data/ext/ffi_c/libffi/src/arm/ffi.c +22 -0
  65. data/ext/ffi_c/libffi/src/arm/sysv.S +4 -4
  66. data/ext/ffi_c/libffi/src/closures.c +33 -10
  67. data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
  68. data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
  69. data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
  70. data/ext/ffi_c/libffi/src/dlmalloc.c +1 -1
  71. data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
  72. data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
  73. data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
  74. data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
  75. data/ext/ffi_c/libffi/src/mips/ffi.c +5 -1
  76. data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
  77. data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
  78. data/ext/ffi_c/libffi/src/pa/ffitarget.h +1 -6
  79. data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
  80. data/ext/ffi_c/libffi/src/pa/linux.S +4 -2
  81. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +13 -1
  82. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +1 -1
  83. data/ext/ffi_c/libffi/src/powerpc/linux64.S +8 -0
  84. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +13 -1
  85. data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
  86. data/ext/ffi_c/libffi/src/prep_cif.c +1 -1
  87. data/ext/ffi_c/libffi/src/x86/ffi.c +15 -6
  88. data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
  89. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
  90. data/ext/ffi_c/libffi/src/x86/ffiw64.c +15 -8
  91. data/ext/ffi_c/libffi/src/x86/sysv.S +15 -6
  92. data/ext/ffi_c/libffi/src/x86/unix64.S +59 -4
  93. data/ext/ffi_c/libffi/src/x86/win64.S +7 -3
  94. data/ext/ffi_c/libffi/src/x86/win64_intel.S +3 -2
  95. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +22 -2
  96. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +4 -4
  97. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2 -2
  98. data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +2 -0
  99. data/ffi.gemspec +2 -2
  100. data/lib/ffi.rb +10 -3
  101. data/lib/ffi/abstract_memory.rb +44 -0
  102. data/lib/ffi/autopointer.rb +1 -1
  103. data/lib/ffi/ffi.rb +1 -0
  104. data/lib/ffi/io.rb +3 -3
  105. data/lib/ffi/library.rb +7 -3
  106. data/lib/ffi/managedstruct.rb +2 -2
  107. data/lib/ffi/platform.rb +18 -8
  108. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  109. data/lib/ffi/platform/aarch64-freebsd/types.conf +2 -2
  110. data/lib/ffi/platform/aarch64-freebsd12/types.conf +113 -60
  111. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  112. data/lib/ffi/platform/arm-linux/types.conf +32 -4
  113. data/lib/ffi/platform/i386-windows/types.conf +26 -79
  114. data/lib/ffi/platform/powerpc-linux/types.conf +32 -2
  115. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  116. data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
  117. data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
  118. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  119. data/lib/ffi/platform/x86_64-darwin/types.conf +4 -0
  120. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +4 -22
  121. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  122. data/lib/ffi/platform/x86_64-linux/types.conf +21 -0
  123. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  124. data/lib/ffi/platform/x86_64-windows/types.conf +10 -78
  125. data/lib/ffi/pointer.rb +21 -14
  126. data/lib/ffi/struct.rb +8 -2
  127. data/lib/ffi/tools/const_generator.rb +2 -1
  128. data/lib/ffi/tools/struct_generator.rb +2 -1
  129. data/lib/ffi/tools/types_generator.rb +2 -0
  130. data/lib/ffi/variadic.rb +1 -10
  131. data/lib/ffi/version.rb +1 -1
  132. data/rakelib/ffi_gem_helper.rb +65 -0
  133. data/samples/getlogin.rb +1 -1
  134. data/samples/getpid.rb +1 -1
  135. data/samples/gettimeofday.rb +8 -8
  136. data/samples/hello.rb +2 -1
  137. data/samples/inotify.rb +1 -1
  138. data/samples/pty.rb +1 -2
  139. data/samples/qsort.rb +0 -1
  140. metadata +21 -12
  141. data/.appveyor.yml +0 -27
  142. data/.gitignore +0 -25
  143. data/.gitmodules +0 -4
  144. data/.travis.yml +0 -44
  145. data/.yardopts +0 -5
  146. data/ext/ffi_c/win32/stdbool.h +0 -8
  147. data/ext/ffi_c/win32/stdint.h +0 -201
  148. data/samples/sample_helper.rb +0 -6
data/ext/ffi_c/Pointer.h CHANGED
@@ -30,11 +30,7 @@
30
30
  #ifndef RBFFI_POINTER_H
31
31
  #define RBFFI_POINTER_H
32
32
 
33
- #ifndef _MSC_VER
34
33
  # include <stdbool.h>
35
- #else
36
- # include "win32/stdbool.h"
37
- #endif
38
34
 
39
35
  #ifdef __cplusplus
40
36
  extern "C" {
data/ext/ffi_c/Struct.c CHANGED
@@ -31,12 +31,9 @@
31
31
  #include <sys/types.h>
32
32
  #ifndef _MSC_VER
33
33
  # include <sys/param.h>
34
- # include <stdint.h>
35
- # include <stdbool.h>
36
- #else
37
- # include "win32/stdbool.h"
38
- # include "win32/stdint.h"
39
34
  #endif
35
+ #include <stdint.h>
36
+ #include <stdbool.h>
40
37
  #include <ruby.h>
41
38
  #include "rbffi.h"
42
39
  #include "compat.h"
@@ -290,7 +287,7 @@ struct_field(Struct* s, VALUE fieldName)
290
287
  VALUE rbField = rb_hash_aref(layout->rbFieldMap, fieldName);
291
288
  if (unlikely(NIL_P(rbField))) {
292
289
  VALUE str = rb_funcall2(fieldName, id_to_s, 0, NULL);
293
- rb_raise(rb_eArgError, "No such field '%s'", StringValuePtr(str));
290
+ rb_raise(rb_eArgError, "No such field '%s'", StringValueCStr(str));
294
291
  }
295
292
  /* Write the retrieved coder to the cache */
296
293
  p_ce->fieldName = fieldName;
@@ -32,13 +32,8 @@
32
32
  #endif
33
33
  #include <sys/types.h>
34
34
  #include <stdio.h>
35
- #ifndef _MSC_VER
36
- # include <stdint.h>
37
- # include <stdbool.h>
38
- #else
39
- # include "win32/stdbool.h"
40
- # include "win32/stdint.h"
41
- #endif
35
+ #include <stdint.h>
36
+ #include <stdbool.h>
42
37
  #include <errno.h>
43
38
  #include <ruby.h>
44
39
 
@@ -32,12 +32,9 @@
32
32
 
33
33
  #ifndef _MSC_VER
34
34
  # include <sys/param.h>
35
- # include <stdint.h>
36
- # include <stdbool.h>
37
- #else
38
- # include "win32/stdbool.h"
39
- # include "win32/stdint.h"
40
35
  #endif
36
+ #include <stdint.h>
37
+ #include <stdbool.h>
41
38
  #include <ruby.h>
42
39
  #include "rbffi.h"
43
40
  #include "compat.h"
@@ -126,7 +123,6 @@ struct_field_initialize(int argc, VALUE* argv, VALUE self)
126
123
 
127
124
  switch (field->type->nativeType == NATIVE_MAPPED ? ((MappedType *) field->type)->type->nativeType : field->type->nativeType) {
128
125
  case NATIVE_FUNCTION:
129
- case NATIVE_CALLBACK:
130
126
  case NATIVE_POINTER:
131
127
  field->referenceRequired = true;
132
128
  break;
@@ -350,8 +346,13 @@ array_field_put(VALUE self, VALUE pointer, VALUE value)
350
346
  argv[0] = INT2FIX(f->offset);
351
347
  argv[1] = value;
352
348
 
353
- rb_funcall2(pointer, rb_intern("put_string"), 2, argv);
354
-
349
+ if (RSTRING_LEN(value) < array->length) {
350
+ rb_funcall2(pointer, rb_intern("put_string"), 2, argv);
351
+ } else if (RSTRING_LEN(value) == array->length) {
352
+ rb_funcall2(pointer, rb_intern("put_bytes"), 2, argv);
353
+ } else {
354
+ rb_raise(rb_eIndexError, "String is longer (%ld bytes) than the char array (%d bytes)", RSTRING_LEN(value), array->length);
355
+ }
355
356
  } else {
356
357
  #ifdef notyet
357
358
  MemoryOp* op;
data/ext/ffi_c/Thread.c CHANGED
@@ -28,12 +28,7 @@
28
28
  */
29
29
 
30
30
  #include <stddef.h>
31
- #ifndef _MSC_VER
32
31
  #include <stdbool.h>
33
- #else
34
- # include "win32/stdbool.h"
35
- # include "win32/stdint.h"
36
- #endif
37
32
 
38
33
  #if defined(__CYGWIN__) || !defined(_WIN32)
39
34
  # include <pthread.h>
@@ -74,9 +69,6 @@ void
74
69
  rbffi_frame_push(rbffi_frame_t* frame)
75
70
  {
76
71
  memset(frame, 0, sizeof(*frame));
77
- #ifndef HAVE_RUBY_THREAD_HAS_GVL_P
78
- frame->has_gvl = true;
79
- #endif
80
72
  frame->exc = Qnil;
81
73
 
82
74
  #ifdef _WIN32
data/ext/ffi_c/Thread.h CHANGED
@@ -30,12 +30,7 @@
30
30
  #ifndef RBFFI_THREAD_H
31
31
  #define RBFFI_THREAD_H
32
32
 
33
- #ifndef _MSC_VER
34
- # include <stdbool.h>
35
- #else
36
- # include "win32/stdbool.h"
37
- # include "win32/stdint.h"
38
- #endif
33
+ #include <stdbool.h>
39
34
  #include <ruby.h>
40
35
  #include "extconf.h"
41
36
 
@@ -66,9 +61,6 @@ typedef struct rbffi_frame {
66
61
  struct thread_data* td;
67
62
  #endif
68
63
  struct rbffi_frame* prev;
69
- #ifndef HAVE_RUBY_THREAD_HAS_GVL_P
70
- bool has_gvl;
71
- #endif
72
64
  VALUE exc;
73
65
  } rbffi_frame_t;
74
66
 
data/ext/ffi_c/Type.c CHANGED
@@ -28,7 +28,7 @@
28
28
  */
29
29
 
30
30
  #ifndef _MSC_VER
31
- #include <sys/param.h>
31
+ # include <sys/param.h>
32
32
  #endif
33
33
 
34
34
  #include <sys/types.h>
data/ext/ffi_c/Types.c CHANGED
@@ -85,10 +85,9 @@ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr)
85
85
  return rbffi_Pointer_NewInstance(*(void **) ptr);
86
86
  case NATIVE_BOOL:
87
87
  return ((unsigned char) *(ffi_arg *) ptr) ? Qtrue : Qfalse;
88
-
89
- case NATIVE_FUNCTION:
90
- case NATIVE_CALLBACK: {
91
- return *(void **) ptr != NULL
88
+
89
+ case NATIVE_FUNCTION: {
90
+ return *(void **) ptr != NULL
92
91
  ? rbffi_Function_NewInstance(rbType, rbffi_Pointer_NewInstance(*(void **) ptr))
93
92
  : Qnil;
94
93
  }
@@ -116,15 +115,15 @@ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr)
116
115
 
117
116
  values[0] = rbffi_NativeValue_ToRuby(m->type, m->rbType, ptr);
118
117
  values[1] = Qnil;
119
-
118
+
120
119
 
121
120
  rbReturnValue = rb_funcall2(m->rbConverter, id_from_native, 2, values);
122
121
  RB_GC_GUARD(values[0]);
123
122
  RB_GC_GUARD(rbType);
124
-
123
+
125
124
  return rbReturnValue;
126
125
  }
127
-
126
+
128
127
  default:
129
128
  rb_raise(rb_eRuntimeError, "Unknown type: %d", type->nativeType);
130
129
  return Qnil;
data/ext/ffi_c/Types.h CHANGED
@@ -51,20 +51,19 @@ typedef enum {
51
51
  NATIVE_FLOAT64,
52
52
  NATIVE_LONGDOUBLE,
53
53
  NATIVE_POINTER,
54
- NATIVE_CALLBACK,
55
54
  NATIVE_FUNCTION,
56
55
  NATIVE_BUFFER_IN,
57
56
  NATIVE_BUFFER_OUT,
58
57
  NATIVE_BUFFER_INOUT,
59
58
  NATIVE_CHAR_ARRAY,
60
59
  NATIVE_BOOL,
61
-
60
+
62
61
  /** An immutable string. Nul terminated, but only copies in to the native function */
63
62
  NATIVE_STRING,
64
-
63
+
65
64
  /** The function takes a variable number of arguments */
66
65
  NATIVE_VARARGS,
67
-
66
+
68
67
  /** Struct-by-value param or result */
69
68
  NATIVE_STRUCT,
70
69
 
data/ext/ffi_c/Variadic.c CHANGED
@@ -33,13 +33,8 @@
33
33
  #include <sys/types.h>
34
34
 
35
35
  #include <stdio.h>
36
- #ifndef _MSC_VER
37
- # include <stdint.h>
38
- # include <stdbool.h>
39
- #else
40
- # include "win32/stdbool.h"
41
- # include "win32/stdint.h"
42
- #endif
36
+ #include <stdint.h>
37
+ #include <stdbool.h>
43
38
  #include <ruby.h>
44
39
 
45
40
  #include <ffi.h>
@@ -173,7 +168,8 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
173
168
  ffi_type* ffiReturnType;
174
169
  Type** paramTypes;
175
170
  VALUE* argv;
176
- int paramCount = 0, fixedCount = 0, i;
171
+ VALUE* callbackParameters;
172
+ int paramCount = 0, fixedCount = 0, callbackCount = 0, i;
177
173
  ffi_status ffiStatus;
178
174
  rbffi_frame_t frame = { 0 };
179
175
 
@@ -187,6 +183,7 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
187
183
  params = ALLOCA_N(FFIStorage, paramCount);
188
184
  ffiValues = ALLOCA_N(void*, paramCount);
189
185
  argv = ALLOCA_N(VALUE, paramCount);
186
+ callbackParameters = ALLOCA_N(VALUE, paramCount);
190
187
  retval = alloca(MAX(invoker->returnType->ffiType->size, FFI_SIZEOF_ARG));
191
188
 
192
189
  for (i = 0; i < paramCount; ++i) {
@@ -216,6 +213,14 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
216
213
  Data_Get_Struct(rbType, Type, paramTypes[i]);
217
214
  break;
218
215
 
216
+ case NATIVE_FUNCTION:
217
+ if (!rb_obj_is_kind_of(rbType, rbffi_FunctionTypeClass)) {
218
+ VALUE typeName = rb_funcall2(rbType, rb_intern("inspect"), 0, NULL);
219
+ rb_raise(rb_eTypeError, "Incorrect parameter type (%s)", RSTRING_PTR(typeName));
220
+ }
221
+ callbackParameters[callbackCount++] = rbType;
222
+ break;
223
+
219
224
  default:
220
225
  break;
221
226
  }
@@ -253,7 +258,7 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
253
258
  }
254
259
 
255
260
  rbffi_SetupCallParams(paramCount, argv, -1, paramTypes, params,
256
- ffiValues, NULL, 0, invoker->rbEnums);
261
+ ffiValues, callbackParameters, callbackCount, invoker->rbEnums);
257
262
 
258
263
  rbffi_frame_push(&frame);
259
264
 
data/ext/ffi_c/compat.h CHANGED
@@ -64,6 +64,10 @@
64
64
  # define unlikely(x) (x)
65
65
  #endif
66
66
 
67
+ #ifdef _MSC_VER
68
+ #define ffi_type_longdouble ffi_type_double
69
+ #endif
70
+
67
71
  #ifndef MAX
68
72
  # define MAX(a, b) ((a) < (b) ? (b) : (a))
69
73
  #endif
data/ext/ffi_c/extconf.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
3
+ if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
4
4
  require 'mkmf'
5
5
  require 'rbconfig'
6
6
 
@@ -8,14 +8,22 @@ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
8
8
  # We need pkg_config or ffi.h
9
9
  libffi_ok = pkg_config("libffi") ||
10
10
  have_header("ffi.h") ||
11
- find_header("ffi.h", "/usr/local/include", "/usr/include/ffi")
11
+ find_header("ffi.h", "/usr/local/include", "/usr/include/ffi",
12
+ "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi",
13
+ "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ffi") ||
14
+ (find_header("ffi.h", `xcrun --sdk macosx --show-sdk-path`.strip + "/usr/include/ffi") rescue false)
12
15
 
13
- # Ensure we can link to ffi_call
14
- libffi_ok &&= have_library("ffi", "ffi_call", [ "ffi.h" ]) ||
15
- have_library("libffi", "ffi_call", [ "ffi.h" ])
16
+ # Ensure we can link to ffi_prep_closure_loc
17
+ libffi_ok &&= have_library("ffi", "ffi_prep_closure_loc", [ "ffi.h" ]) ||
18
+ have_library("libffi", "ffi_prep_closure_loc", [ "ffi.h" ]) ||
19
+ have_library("libffi-8", "ffi_prep_closure_loc", [ "ffi.h" ])
16
20
 
17
- # And we need a libffi version recent enough to provide ffi_closure_alloc
18
- libffi_ok &&= have_func("ffi_closure_alloc")
21
+ if RbConfig::CONFIG['host_os'] =~ /mswin/
22
+ have_library('libffi_convenience')
23
+ have_library('shlwapi')
24
+ end
25
+
26
+ libffi_ok
19
27
  end
20
28
 
21
29
  dir_config("ffi_c")
@@ -36,40 +44,45 @@ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
36
44
  abort "system libffi is not usable" unless system_libffi_usable?
37
45
  end
38
46
 
39
- have_header('shlwapi.h')
40
- have_func('rb_thread_call_without_gvl') || abort("Ruby C-API function `rb_thread_call_without_gvl` is missing")
41
- have_func('ruby_native_thread_p')
42
- if RUBY_VERSION >= "2.3.0"
43
- # On OSX and Linux ruby_thread_has_gvl_p() is detected but fails at runtime for ruby < 2.3.0
44
- have_func('ruby_thread_has_gvl_p')
45
- end
46
-
47
47
  if system_libffi
48
48
  have_func('ffi_prep_cif_var')
49
49
  $defs << "-DHAVE_RAW_API" if have_func("ffi_raw_call") && have_func("ffi_prep_raw_closure")
50
50
  else
51
51
  $defs << "-DHAVE_FFI_PREP_CIF_VAR"
52
52
  $defs << "-DUSE_INTERNAL_LIBFFI"
53
+
54
+ # Ensure libffi symbols aren't exported when using static libffi.
55
+ # This is to avoid interference with other gems like fiddle.
56
+ # See https://github.com/ffi/ffi/issues/835
57
+ append_ldflags "-Wl,--exclude-libs,ALL"
53
58
  end
54
59
 
55
- $defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works
56
- $defs << "-DFFI_BUILDING" if RbConfig::CONFIG['host_os'] =~ /mswin/ # for compatibility with newer libffi
60
+ # Some linux archs need explicit linking to pthread, see https://github.com/ffi/ffi/issues/893
61
+ append_ldflags "-pthread"
57
62
 
58
- create_header
63
+ ffi_alloc_default = RbConfig::CONFIG['host_os'] =~ /darwin/i && RbConfig::CONFIG['host'] =~ /arm|aarch64/i
64
+ if enable_config('libffi-alloc', ffi_alloc_default)
65
+ $defs << "-DUSE_FFI_ALLOC"
66
+ end
59
67
 
60
- $LOCAL_LIBS << " ./libffi/.libs/libffi_convenience.lib" if !system_libffi && RbConfig::CONFIG['host_os'] =~ /mswin/
68
+ $defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works
61
69
 
70
+ create_header
62
71
  create_makefile("ffi_c")
72
+
63
73
  unless system_libffi
64
74
  File.open("Makefile", "a") do |mf|
65
75
  mf.puts "LIBFFI_HOST=--host=#{RbConfig::CONFIG['host_alias']}" if RbConfig::CONFIG.has_key?("host_alias")
66
- if RbConfig::CONFIG['host_os'].downcase =~ /darwin/
76
+ if RbConfig::CONFIG['host_os'] =~ /darwin/i
77
+ if RbConfig::CONFIG['host'] =~ /arm|aarch64/i
78
+ mf.puts "LIBFFI_HOST=--host=aarch64-apple-#{RbConfig::CONFIG['host_os']}"
79
+ end
67
80
  mf.puts "include ${srcdir}/libffi.darwin.mk"
68
- elsif RbConfig::CONFIG['host_os'].downcase =~ /bsd/
81
+ elsif RbConfig::CONFIG['host_os'] =~ /bsd/i
69
82
  mf.puts '.include "${srcdir}/libffi.bsd.mk"'
70
- elsif RbConfig::CONFIG['host_os'].downcase =~ /mswin64/
83
+ elsif RbConfig::CONFIG['host_os'] =~ /mswin64/i
71
84
  mf.puts '!include $(srcdir)/libffi.vc64.mk'
72
- elsif RbConfig::CONFIG['host_os'].downcase =~ /mswin32/
85
+ elsif RbConfig::CONFIG['host_os'] =~ /mswin32/i
73
86
  mf.puts '!include $(srcdir)/libffi.vc.mk'
74
87
  else
75
88
  mf.puts "include ${srcdir}/libffi.mk"
@@ -39,6 +39,10 @@ matrix:
39
39
  - os: linux
40
40
  arch: arm64
41
41
  env: HOST=aarch64-linux-gnu
42
+ - os: linux
43
+ arch: arm64
44
+ env: HOST=aarch64-linux-gnu
45
+ compiler: clang
42
46
  - os: linux
43
47
  env: HOST=arm32v7-linux-gnu LIBFFI_TEST_OPTIMIZATION="-O0"
44
48
  - os: linux
@@ -14,7 +14,7 @@
14
14
  #
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with DejaGnu; if not, write to the Free Software Foundation,
17
- # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
+ # Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA.
18
18
 
19
19
  # This is a list of toolchains that are supported on this board.
20
20
  set_board_info target_install {bfin-elf}
@@ -2,6 +2,10 @@
2
2
 
3
3
  set -x
4
4
 
5
+ # This is a policy bound API key. It can only be used with
6
+ # https://github.com/libffi/rlgl-policy.git.
7
+ RLGL_KEY=0LIBFFI-0LIBFFI-0LIBFFI-0LIBFFI
8
+
5
9
  if [ -z ${QEMU_CPU+x} ]; then
6
10
  export SET_QEMU_CPU=
7
11
  else
@@ -14,7 +14,7 @@
14
14
  #
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with DejaGnu; if not, write to the Free Software Foundation,
17
- # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
+ # Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA.
18
18
 
19
19
  # This is a list of toolchains that are supported on this board.
20
20
  set_board_info target_install {m32r-elf}
@@ -14,7 +14,7 @@
14
14
  #
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with DejaGnu; if not, write to the Free Software Foundation,
17
- # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
+ # Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA.
18
18
 
19
19
  # This is a list of toolchains that are supported on this board.
20
20
  set_board_info target_install {moxie-elf}
@@ -14,7 +14,7 @@
14
14
  #
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with DejaGnu; if not, write to the Free Software Foundation,
17
- # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
+ # Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA.
18
18
 
19
19
  # This is a list of toolchains that are supported on this board.
20
20
  set_board_info target_install {or1k-elf}
@@ -14,7 +14,7 @@
14
14
  #
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with DejaGnu; if not, write to the Free Software Foundation,
17
- # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
+ # Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA.
18
18
 
19
19
  # This is a list of toolchains that are supported on this board.
20
20
  set_board_info target_install {powerpc-eabisim}