ffi 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

Files changed (56) hide show
  1. data/Rakefile +4 -4
  2. data/ext/ffi_c/AbstractMemory.c +367 -14
  3. data/ext/ffi_c/AbstractMemory.h +4 -0
  4. data/ext/ffi_c/ArrayType.c +28 -0
  5. data/ext/ffi_c/Buffer.c +101 -25
  6. data/ext/ffi_c/Call.c +8 -5
  7. data/ext/ffi_c/ClosurePool.c +9 -8
  8. data/ext/ffi_c/DataConverter.c +29 -0
  9. data/ext/ffi_c/DynamicLibrary.c +64 -1
  10. data/ext/ffi_c/Function.c +111 -10
  11. data/ext/ffi_c/FunctionInfo.c +13 -1
  12. data/ext/ffi_c/LastError.c +16 -0
  13. data/ext/ffi_c/MappedType.c +22 -0
  14. data/ext/ffi_c/MemoryPointer.c +11 -1
  15. data/ext/ffi_c/MethodHandle.c +18 -11
  16. data/ext/ffi_c/Platform.c +9 -3
  17. data/ext/ffi_c/Pointer.c +98 -0
  18. data/ext/ffi_c/Struct.c +4 -4
  19. data/ext/ffi_c/Struct.h +2 -1
  20. data/ext/ffi_c/StructLayout.c +2 -2
  21. data/ext/ffi_c/Thread.c +124 -1
  22. data/ext/ffi_c/Type.c +108 -17
  23. data/ext/ffi_c/Types.c +9 -2
  24. data/ext/ffi_c/Variadic.c +5 -4
  25. data/ext/ffi_c/compat.h +8 -0
  26. data/ext/ffi_c/endian.h +7 -1
  27. data/ext/ffi_c/extconf.rb +46 -35
  28. data/ext/ffi_c/ffi.c +5 -0
  29. data/ext/ffi_c/libffi.darwin.mk +15 -15
  30. data/ext/ffi_c/libffi.gnu.mk +3 -3
  31. data/ext/ffi_c/libffi.mk +4 -4
  32. data/lib/ffi.rb +13 -9
  33. data/lib/ffi/autopointer.rb +88 -26
  34. data/lib/ffi/enum.rb +42 -0
  35. data/lib/ffi/errno.rb +6 -1
  36. data/lib/ffi/ffi.rb +1 -0
  37. data/lib/ffi/io.rb +13 -2
  38. data/lib/ffi/library.rb +212 -19
  39. data/lib/ffi/memorypointer.rb +1 -33
  40. data/lib/ffi/platform.rb +23 -7
  41. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  42. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  43. data/lib/ffi/platform/x86_64-freebsd/types.conf +126 -0
  44. data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
  45. data/lib/ffi/pointer.rb +44 -0
  46. data/lib/ffi/struct.rb +1 -1
  47. data/lib/ffi/struct_layout_builder.rb +2 -1
  48. data/lib/ffi/tools/const_generator.rb +72 -17
  49. data/lib/ffi/types.rb +21 -1
  50. data/spec/ffi/rbx/memory_pointer_spec.rb +4 -2
  51. data/spec/ffi/struct_spec.rb +10 -0
  52. data/spec/ffi/typedef_spec.rb +11 -0
  53. data/tasks/extension.rake +0 -1
  54. data/tasks/gem.rake +0 -1
  55. data/tasks/yard.rake +11 -0
  56. metadata +15 -8
@@ -51,6 +51,12 @@ type_allocate(VALUE klass)
51
51
  return obj;
52
52
  }
53
53
 
54
+ /*
55
+ * Document-method: initialize
56
+ * call-seq: initialize(value)
57
+ * @param [Fixnum,Type] value
58
+ * @return [self]
59
+ */
54
60
  static VALUE
55
61
  type_initialize(VALUE self, VALUE value)
56
62
  {
@@ -72,6 +78,11 @@ type_initialize(VALUE self, VALUE value)
72
78
  return self;
73
79
  }
74
80
 
81
+ /*
82
+ * call-seq: type.size
83
+ * @return [Fixnum]
84
+ * Return type's size, in bytes.
85
+ */
75
86
  static VALUE
76
87
  type_size(VALUE self)
77
88
  {
@@ -82,6 +93,10 @@ type_size(VALUE self)
82
93
  return INT2FIX(type->ffiType->size);
83
94
  }
84
95
 
96
+ /*
97
+ * call-seq: type.alignment
98
+ * @return [Fixnum]
99
+ */
85
100
  static VALUE
86
101
  type_alignment(VALUE self)
87
102
  {
@@ -92,6 +107,11 @@ type_alignment(VALUE self)
92
107
  return INT2FIX(type->ffiType->alignment);
93
108
  }
94
109
 
110
+ /*
111
+ * call-seq: type.inspect
112
+ * @return [String]
113
+ * Inspect {Type} object.
114
+ */
95
115
  static VALUE
96
116
  type_inspect(VALUE self)
97
117
  {
@@ -128,6 +148,11 @@ builtin_type_free(BuiltinType *type)
128
148
  xfree(type);
129
149
  }
130
150
 
151
+ /*
152
+ * call-seq: type.inspect
153
+ * @return [String]
154
+ * Inspect {Type::Builtin} object.
155
+ */
131
156
  static VALUE
132
157
  builtin_type_inspect(VALUE self)
133
158
  {
@@ -145,21 +170,29 @@ int
145
170
  rbffi_type_size(VALUE type)
146
171
  {
147
172
  int t = TYPE(type);
173
+
148
174
  if (t == T_FIXNUM || t == T_BIGNUM) {
149
175
  return NUM2INT(type);
176
+
150
177
  } else if (t == T_SYMBOL) {
151
178
  /*
152
179
  * Try looking up directly in the type and size maps
153
180
  */
154
181
  VALUE nType;
155
- if ((nType = rb_hash_aref(typeMap, type)) != Qnil) {
156
- VALUE nSize = rb_hash_aref(sizeMap, nType);
157
- if (TYPE(nSize) == T_FIXNUM) {
158
- return FIX2INT(nSize);
182
+ if ((nType = rb_hash_lookup(typeMap, type)) != Qnil) {
183
+ if (rb_obj_is_kind_of(nType, rbffi_TypeClass)) {
184
+ Type* type;
185
+ Data_Get_Struct(nType, Type, type);
186
+ return (int) type->ffiType->size;
187
+
188
+ } else if (rb_respond_to(nType, id_size)) {
189
+ return NUM2INT(rb_funcall2(nType, id_size, 0, NULL));
159
190
  }
160
191
  }
192
+
161
193
  // Not found - call up to the ruby version to resolve
162
194
  return NUM2INT(rb_funcall2(rbffi_FFIModule, id_type_size, 1, &type));
195
+
163
196
  } else {
164
197
  return NUM2INT(rb_funcall2(type, id_size, 0, NULL));
165
198
  }
@@ -174,7 +207,7 @@ rbffi_Type_Lookup(VALUE name)
174
207
  * Try looking up directly in the type Map
175
208
  */
176
209
  VALUE nType;
177
- if ((nType = rb_hash_aref(typeMap, name)) != Qnil && rb_obj_is_kind_of(nType, rbffi_TypeClass)) {
210
+ if ((nType = rb_hash_lookup(typeMap, name)) != Qnil && rb_obj_is_kind_of(nType, rbffi_TypeClass)) {
178
211
  return nType;
179
212
  }
180
213
  } else if (rb_obj_is_kind_of(name, rbffi_TypeClass)) {
@@ -196,7 +229,9 @@ rbffi_Type_Find(VALUE name)
196
229
  VALUE rbType = rbffi_Type_Lookup(name);
197
230
 
198
231
  if (!RTEST(rbType)) {
199
- rb_raise(rb_eTypeError, "invalid type, %s", RSTRING_PTR(rb_inspect(name)));
232
+ VALUE s = rb_inspect(name);
233
+ rb_raise(rb_eTypeError, "invalid type, %s", RSTRING_PTR(s));
234
+ RB_GC_GUARD(s);
200
235
  }
201
236
 
202
237
  return rbType;
@@ -206,8 +241,18 @@ void
206
241
  rbffi_Type_Init(VALUE moduleFFI)
207
242
  {
208
243
  VALUE moduleNativeType;
209
- VALUE classType = rbffi_TypeClass = rb_define_class_under(moduleFFI, "Type", rb_cObject);
210
-
244
+ /*
245
+ * Document-class: FFI::Type
246
+ * This class manages C types.
247
+ *
248
+ * It embbed {FFI::Type::Builtin} objects as constants (for names,
249
+ * see {FFI::NativeType}).
250
+ */
251
+ rbffi_TypeClass = rb_define_class_under(moduleFFI, "Type", rb_cObject);
252
+
253
+ /*
254
+ * Document-constant: FFI::TypeDefs
255
+ */
211
256
  rb_define_const(moduleFFI, "TypeDefs", typeMap = rb_hash_new());
212
257
  rb_define_const(moduleFFI, "SizeTypes", sizeMap = rb_hash_new());
213
258
  rb_global_variable(&typeMap);
@@ -216,19 +261,62 @@ rbffi_Type_Init(VALUE moduleFFI)
216
261
  id_type_size = rb_intern("type_size");
217
262
  id_size = rb_intern("size");
218
263
 
219
-
264
+ /*
265
+ * Document-class: FFI::Type::Builtin
266
+ * Class for Built-in types.
267
+ */
220
268
  classBuiltinType = rb_define_class_under(rbffi_TypeClass, "Builtin", rbffi_TypeClass);
269
+ /*
270
+ * Document-module: FFI::NativeType
271
+ * This module defines constants for native (C) types.
272
+ *
273
+ * ==Native type constants
274
+ * Native types are defined by constants :
275
+ * * INT8, SCHAR, CHAR
276
+ * * UINT8, UCHAR
277
+ * * INT16, SHORT, SSHORT
278
+ * * UINT16, USHORT
279
+ * * INT32,, INT, SINT
280
+ * * UINT32, UINT
281
+ * * INT64, LONG_LONG, SLONG_LONG
282
+ * * UINT64, ULONG_LONG
283
+ * * LONG, SLONG
284
+ * * ULONG
285
+ * * FLOAT32, FLOAT
286
+ * * FLOAT64, DOUBLE
287
+ * * POINTER
288
+ * * CALLBACK
289
+ * * FUNCTION
290
+ * * CHAR_ARRAY
291
+ * * BOOL
292
+ * * STRING (immutable string, nul terminated)
293
+ * * STRUCT (struct-b-value param or result)
294
+ * * ARRAY (array type definition)
295
+ * * MAPPED (custom native type)
296
+ * For function return type only :
297
+ * * VOID
298
+ * For function argument type only :
299
+ * * BUFFER_IN
300
+ * * BUFFER_OUT
301
+ * * VARARGS (function takes a variable number of arguments)
302
+ *
303
+ * All these constants are exported to {FFI} module prefixed with "TYPE_".
304
+ * They are objets from {FFI::Type::Builtin} class.
305
+ */
221
306
  moduleNativeType = rb_define_module_under(moduleFFI, "NativeType");
222
307
 
308
+ /*
309
+ * Document-global: FFI::Type
310
+ */
223
311
  rb_global_variable(&rbffi_TypeClass);
224
312
  rb_global_variable(&classBuiltinType);
225
313
  rb_global_variable(&moduleNativeType);
226
314
 
227
- rb_define_alloc_func(classType, type_allocate);
228
- rb_define_method(classType, "initialize", type_initialize, 1);
229
- rb_define_method(classType, "size", type_size, 0);
230
- rb_define_method(classType, "alignment", type_alignment, 0);
231
- rb_define_method(classType, "inspect", type_inspect, 0);
315
+ rb_define_alloc_func(rbffi_TypeClass, type_allocate);
316
+ rb_define_method(rbffi_TypeClass, "initialize", type_initialize, 1);
317
+ rb_define_method(rbffi_TypeClass, "size", type_size, 0);
318
+ rb_define_method(rbffi_TypeClass, "alignment", type_alignment, 0);
319
+ rb_define_method(rbffi_TypeClass, "inspect", type_inspect, 0);
232
320
 
233
321
  // Make Type::Builtin non-allocatable
234
322
  rb_undef_method(CLASS_OF(classBuiltinType), "new");
@@ -240,16 +328,19 @@ rbffi_Type_Init(VALUE moduleFFI)
240
328
  // Define all the builtin types
241
329
  #define T(x, ffiType) do { \
242
330
  VALUE t = Qnil; \
243
- rb_define_const(classType, #x, t = builtin_type_new(classBuiltinType, NATIVE_##x, ffiType, #x)); \
331
+ rb_define_const(rbffi_TypeClass, #x, t = builtin_type_new(classBuiltinType, NATIVE_##x, ffiType, #x)); \
244
332
  rb_define_const(moduleNativeType, #x, t); \
245
333
  rb_define_const(moduleFFI, "TYPE_" #x, t); \
246
334
  } while(0)
247
335
 
248
336
  #define A(old_type, new_type) do { \
249
- VALUE t = rb_const_get(classType, rb_intern(#old_type)); \
250
- rb_const_set(classType, rb_intern(#new_type), t); \
337
+ VALUE t = rb_const_get(rbffi_TypeClass, rb_intern(#old_type)); \
338
+ rb_const_set(rbffi_TypeClass, rb_intern(#new_type), t); \
251
339
  } while(0)
252
340
 
341
+ /*
342
+ * Document-constant: FFI::Type::Builtin::VOID
343
+ */
253
344
  T(VOID, &ffi_type_void);
254
345
  T(INT8, &ffi_type_sint8);
255
346
  A(INT8, SCHAR);
@@ -86,6 +86,8 @@ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr)
86
86
 
87
87
  Data_Get_Struct(rbMemory, AbstractMemory, mem);
88
88
  memcpy(mem->address, ptr, sbv->base.ffiType->size);
89
+ RB_GC_GUARD(rbMemory);
90
+ RB_GC_GUARD(rbType);
89
91
 
90
92
  return rb_class_new_instance(1, &rbMemory, sbv->rbStructClass);
91
93
  }
@@ -94,12 +96,17 @@ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr)
94
96
  // For mapped types, first convert to the real native type, then upcall to
95
97
  // ruby to convert to the expected return type
96
98
  MappedType* m = (MappedType *) type;
97
- VALUE values[2];
99
+ VALUE values[2], rbReturnValue;
98
100
 
99
101
  values[0] = rbffi_NativeValue_ToRuby(m->type, m->rbType, ptr);
100
102
  values[1] = Qnil;
103
+
101
104
 
102
- return rb_funcall2(m->rbConverter, id_from_native, 2, values);
105
+ rbReturnValue = rb_funcall2(m->rbConverter, id_from_native, 2, values);
106
+ RB_GC_GUARD(values[0]);
107
+ RB_GC_GUARD(rbType);
108
+
109
+ return rbReturnValue;
103
110
  }
104
111
 
105
112
  default:
@@ -86,7 +86,8 @@ variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE
86
86
  VALUE retval = Qnil;
87
87
  VALUE convention = Qnil;
88
88
  VALUE fixed = Qnil;
89
- int i;
89
+ VALUE rbConventionStr;
90
+ int i;
90
91
 
91
92
  Check_Type(options, T_HASH);
92
93
  convention = rb_hash_aref(options, ID2SYM(rb_intern("convention")));
@@ -97,7 +98,7 @@ variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE
97
98
  invoker->function = rbffi_AbstractMemory_Cast(rbFunction, rbffi_PointerClass)->address;
98
99
 
99
100
  #if defined(_WIN32) || defined(__WIN32__)
100
- VALUE rbConventionStr = rb_funcall2(convention, rb_intern("to_s"), 0, NULL);
101
+ rbConventionStr = rb_funcall2(convention, rb_intern("to_s"), 0, NULL);
101
102
  invoker->abi = (RTEST(convention) && strcmp(StringValueCStr(rbConventionStr), "stdcall") == 0)
102
103
  ? FFI_STDCALL : FFI_DEFAULT_ABI;
103
104
  #else
@@ -159,7 +160,7 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
159
160
  Check_Type(parameterValues, T_ARRAY);
160
161
 
161
162
  Data_Get_Struct(self, VariadicInvoker, invoker);
162
- paramCount = RARRAY_LEN(parameterTypes);
163
+ paramCount = (int) RARRAY_LEN(parameterTypes);
163
164
  paramTypes = ALLOCA_N(Type *, paramCount);
164
165
  ffiParamTypes = ALLOCA_N(ffi_type *, paramCount);
165
166
  params = ALLOCA_N(FFIStorage, paramCount);
@@ -201,7 +202,7 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
201
202
 
202
203
  ffiParamTypes[i] = paramTypes[i]->ffiType;
203
204
  if (ffiParamTypes[i] == NULL) {
204
- rb_raise(rb_eArgError, "Invalid parameter type #%x", paramTypes[i]);
205
+ rb_raise(rb_eArgError, "Invalid parameter type #%x", paramTypes[i]->nativeType);
205
206
  }
206
207
  argv[i] = rb_ary_entry(parameterValues, i);
207
208
  }
@@ -62,5 +62,13 @@
62
62
  # define MIN(a, b) ((a) < (b) ? (a) : (b))
63
63
  #endif
64
64
 
65
+ #ifndef RB_GC_GUARD(x)
66
+ # define RB_GC_GUARD(x) (x)
67
+ #endif
68
+
69
+ #ifndef RB_GC_GUARD_PTR(x)
70
+ # define RB_GC_GUARD_PTR(x) (x)
71
+ #endif
72
+
65
73
  #endif /* RBFFI_COMPAT_H */
66
74
 
@@ -4,7 +4,7 @@
4
4
  #include <sys/param.h>
5
5
  #include <sys/types.h>
6
6
 
7
- #if defined(__linux__) || defined(__CYGWIN__)
7
+ #if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) || defined(__GLIBC__)
8
8
  # include_next <endian.h>
9
9
  #endif
10
10
 
@@ -33,6 +33,12 @@
33
33
  # endif
34
34
  #endif
35
35
 
36
+ #if defined(_WIN32)
37
+ # define LITTLE_ENDIAN 1234
38
+ # define BIG_ENDIAN 4321
39
+ # define BYTE_ORDER LITTLE_ENDIAN
40
+ #endif
41
+
36
42
  #if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN)
37
43
  # error "Cannot determine the endian-ness of this platform"
38
44
  #endif
@@ -1,46 +1,57 @@
1
1
  #!/usr/bin/env ruby
2
- require 'mkmf'
3
- require 'rbconfig'
4
- dir_config("ffi_c")
5
2
 
6
- unless RbConfig::CONFIG['host_os'] =~ /mswin32|mingw32/
7
- if pkg_config("libffi") || find_header("ffi.h", "/usr/local/include")
3
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
4
+ require 'mkmf'
5
+ require 'rbconfig'
6
+ dir_config("ffi_c")
7
+
8
+ if pkg_config("libffi") ||
9
+ have_header("ffi.h") ||
10
+ find_header("ffi.h", "/usr/local/include")
8
11
 
9
12
  # We need at least ffi_call and ffi_prep_closure
10
- libffi_ok = have_library("ffi", "ffi_call", [ "ffi.h" ]) && have_func("ffi_prep_closure")
11
-
13
+ libffi_ok = have_library("ffi", "ffi_call", [ "ffi.h" ]) ||
14
+ have_library("libffi", "ffi_call", [ "ffi.h" ])
15
+ libffi_ok &&= have_func("ffi_prep_closure")
16
+
12
17
  # Check if the raw api is available.
13
18
  $defs << "-DHAVE_RAW_API" if have_func("ffi_raw_call") && have_func("ffi_prep_raw_closure")
14
19
  end
15
- end
16
-
17
- have_func('rb_thread_blocking_region')
18
- have_func('ruby_thread_has_gvl_p')
19
- have_func('ruby_native_thread_p')
20
- have_func('rb_thread_call_with_gvl')
21
-
22
- $defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works
23
- $defs << "-DUSE_INTERNAL_LIBFFI" unless libffi_ok
24
- $defs << "-DRUBY_1_9" if RUBY_VERSION >= "1.9.0"
25
-
26
- create_header
20
+
21
+ have_func('rb_thread_blocking_region')
22
+ have_func('ruby_thread_has_gvl_p') unless RUBY_VERSION >= "1.9.3"
23
+ have_func('ruby_native_thread_p')
24
+ have_func('rb_thread_call_with_gvl')
25
+
26
+ $defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works
27
+ $defs << "-DUSE_INTERNAL_LIBFFI" unless libffi_ok
28
+ $defs << "-DRUBY_1_9" if RUBY_VERSION >= "1.9.0"
27
29
 
28
- $CFLAGS << " -mwin32 " if RbConfig::CONFIG['host_os'] =~ /cygwin/
29
- #$CFLAGS << " -Werror -Wunused -Wformat -Wimplicit -Wreturn-type "
30
- if (ENV['CC'] || RbConfig::MAKEFILE_CONFIG['CC']) =~ /gcc/
31
- $CFLAGS << " -Wno-declaration-after-statement "
32
- end
33
-
34
- create_makefile("ffi_c")
35
- unless libffi_ok
36
- File.open("Makefile", "a") do |mf|
37
- mf.puts "LIBFFI_HOST=--host=#{RbConfig::CONFIG['host_alias']}" if RbConfig::CONFIG.has_key?("host_alias")
38
- if RbConfig::CONFIG['host_os'].downcase =~ /darwin/
39
- mf.puts "include ${srcdir}/libffi.darwin.mk"
40
- elsif RbConfig::CONFIG['host_os'].downcase =~ /bsd/
41
- mf.puts '.include "${srcdir}/libffi.bsd.mk"'
42
- else
43
- mf.puts "include ${srcdir}/libffi.mk"
30
+ create_header
31
+
32
+ $CFLAGS << " -mwin32 " if RbConfig::CONFIG['host_os'] =~ /cygwin/
33
+ #$CFLAGS << " -Werror -Wunused -Wformat -Wimplicit -Wreturn-type "
34
+ if (ENV['CC'] || RbConfig::MAKEFILE_CONFIG['CC']) =~ /gcc/
35
+ $CFLAGS << " -Wno-declaration-after-statement "
36
+ end
37
+
38
+ create_makefile("ffi_c")
39
+ unless libffi_ok
40
+ File.open("Makefile", "a") do |mf|
41
+ mf.puts "LIBFFI_HOST=--host=#{RbConfig::CONFIG['host_alias']}" if RbConfig::CONFIG.has_key?("host_alias")
42
+ if RbConfig::CONFIG['host_os'].downcase =~ /darwin/
43
+ mf.puts "include ${srcdir}/libffi.darwin.mk"
44
+ elsif RbConfig::CONFIG['host_os'].downcase =~ /bsd/
45
+ mf.puts '.include "${srcdir}/libffi.bsd.mk"'
46
+ elsif RbConfig::CONFIG['host_os'] !~ /mswin32|mingw32/
47
+ mf.puts "include ${srcdir}/libffi.mk"
48
+ end
44
49
  end
45
50
  end
51
+
52
+ else
53
+ File.open("Makefile", "w") do |mf|
54
+ mf.puts "# Dummy makefile for non-mri rubies"
55
+ mf.puts "all install::\n"
56
+ end
46
57
  end
@@ -50,6 +50,11 @@ static VALUE moduleFFI = Qnil;
50
50
 
51
51
  void
52
52
  Init_ffi_c(void) {
53
+ /*
54
+ * Document-module: FFI
55
+ *
56
+ * This module embbed type constants from {FFI::NativeType}.
57
+ */
53
58
  rbffi_FFIModule = moduleFFI = rb_define_module("FFI");
54
59
  rb_global_variable(&moduleFFI);
55
60
 
@@ -5,7 +5,7 @@ include ${srcdir}/libffi.gnu.mk
5
5
  CCACHE := $(shell type -p ccache)
6
6
  BUILD_DIR := $(shell pwd)
7
7
 
8
- INCFLAGS += -I${BUILD_DIR}
8
+ INCFLAGS += -I"$(BUILD_DIR)"
9
9
 
10
10
  # Work out which arches we need to compile the lib for
11
11
  ARCHES :=
@@ -24,35 +24,35 @@ endif
24
24
  ifeq ($(strip $(ARCHES)),)
25
25
  # Just build the one (default) architecture
26
26
  $(LIBFFI):
27
- @mkdir -p $(LIBFFI_BUILD_DIR)
28
- @if [ ! -f $(LIBFFI_BUILD_DIR)/Makefile ]; then \
27
+ @mkdir -p "$(LIBFFI_BUILD_DIR)"
28
+ @if [ ! -f "$(LIBFFI_BUILD_DIR)"/Makefile ]; then \
29
29
  echo "Configuring libffi"; \
30
- cd $(LIBFFI_BUILD_DIR) && \
30
+ cd "$(LIBFFI_BUILD_DIR)" && \
31
31
  /usr/bin/env CC="$(CC)" LD="$(LD)" CFLAGS="$(LIBFFI_CFLAGS)" \
32
32
  /bin/sh $(LIBFFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \
33
33
  fi
34
- cd $(LIBFFI_BUILD_DIR) && $(MAKE)
34
+ cd "$(LIBFFI_BUILD_DIR)" && $(MAKE)
35
35
 
36
36
  else
37
37
  # Build a fat binary and assemble
38
38
  build_ffi = \
39
- mkdir -p $(BUILD_DIR)/libffi-$(1); \
40
- (if [ ! -f $(BUILD_DIR)/libffi-$(1)/Makefile ]; then \
39
+ mkdir -p "$(BUILD_DIR)"/libffi-$(1); \
40
+ (if [ ! -f "$(BUILD_DIR)"/libffi-$(1)/Makefile ]; then \
41
41
  echo "Configuring libffi for $(1)"; \
42
- cd $(BUILD_DIR)/libffi-$(1) && \
42
+ cd "$(BUILD_DIR)"/libffi-$(1) && \
43
43
  env CC="$(CCACHE) $(CC)" CFLAGS="-arch $(1) $(LIBFFI_CFLAGS)" LDFLAGS="-arch $(1)" \
44
44
  $(LIBFFI_CONFIGURE) --host=$(1)-apple-darwin > /dev/null; \
45
45
  fi); \
46
- env MACOSX_DEPLOYMENT_TARGET=10.4 $(MAKE) -C $(BUILD_DIR)/libffi-$(1)
46
+ env MACOSX_DEPLOYMENT_TARGET=10.4 $(MAKE) -C "$(BUILD_DIR)"/libffi-$(1)
47
47
 
48
48
  $(LIBFFI):
49
49
  @for arch in $(ARCHES); do $(call build_ffi,$$arch);done
50
50
  # Assemble into a FAT (x86_64, i386, ppc) library
51
- @mkdir -p $(BUILD_DIR)/libffi/.libs
51
+ @mkdir -p "$(BUILD_DIR)"/libffi/.libs
52
52
  /usr/bin/libtool -static -o $@ \
53
- $(foreach arch, $(ARCHES),$(BUILD_DIR)/libffi-$(arch)/.libs/libffi_convenience.a)
54
- @mkdir -p $(LIBFFI_BUILD_DIR)/include
55
- $(RM) $(LIBFFI_BUILD_DIR)/include/ffi.h
53
+ $(foreach arch, $(ARCHES),"$(BUILD_DIR)"/libffi-$(arch)/.libs/libffi_convenience.a)
54
+ @mkdir -p "$(LIBFFI_BUILD_DIR)"/include
55
+ $(RM) "$(LIBFFI_BUILD_DIR)"/include/ffi.h
56
56
  @( \
57
57
  printf "#if defined(__i386__)\n"; \
58
58
  printf "#include \"libffi-i386/include/ffi.h\"\n"; \
@@ -61,7 +61,7 @@ $(LIBFFI):
61
61
  printf "#elif defined(__ppc__)\n"; \
62
62
  printf "#include \"libffi-ppc/include/ffi.h\"\n";\
63
63
  printf "#endif\n";\
64
- ) > $(LIBFFI_BUILD_DIR)/include/ffi.h
64
+ ) > "$(LIBFFI_BUILD_DIR)"/include/ffi.h
65
65
  @( \
66
66
  printf "#if defined(__i386__)\n"; \
67
67
  printf "#include \"libffi-i386/include/ffitarget.h\"\n"; \
@@ -70,6 +70,6 @@ $(LIBFFI):
70
70
  printf "#elif defined(__ppc__)\n"; \
71
71
  printf "#include \"libffi-ppc/include/ffitarget.h\"\n";\
72
72
  printf "#endif\n";\
73
- ) > $(LIBFFI_BUILD_DIR)/include/ffitarget.h
73
+ ) > "$(LIBFFI_BUILD_DIR)"/include/ffitarget.h
74
74
 
75
75
  endif