ffi 0.5.4-x86-mingw32 → 0.6.3-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 (222) hide show
  1. data/History.txt +102 -0
  2. data/LICENSE +1 -27
  3. data/Rakefile +4 -12
  4. data/ext/ffi_c/AbstractMemory.c +6 -8
  5. data/ext/ffi_c/AbstractMemory.h +23 -21
  6. data/ext/ffi_c/AutoPointer.c +0 -1
  7. data/ext/ffi_c/Buffer.c +23 -8
  8. data/ext/ffi_c/Call.c +31 -3
  9. data/ext/ffi_c/Call.h +5 -1
  10. data/ext/ffi_c/DynamicLibrary.c +0 -1
  11. data/ext/ffi_c/Function.c +22 -4
  12. data/ext/ffi_c/MemoryPointer.c +2 -3
  13. data/ext/ffi_c/Pointer.c +23 -9
  14. data/ext/ffi_c/Struct.c +227 -79
  15. data/ext/ffi_c/Struct.h +16 -7
  16. data/ext/ffi_c/StructLayout.c +92 -55
  17. data/ext/ffi_c/Type.c +5 -22
  18. data/ext/ffi_c/Type.h +1 -1
  19. data/ext/ffi_c/Types.c +9 -3
  20. data/ext/ffi_c/Types.h +2 -0
  21. data/ext/ffi_c/extconf.rb +11 -7
  22. data/ext/ffi_c/libffi.gnu.mk +1 -1
  23. data/ext/ffi_c/libffi.mk +1 -1
  24. data/ext/ffi_c/libffi/ChangeLog +900 -84
  25. data/ext/ffi_c/libffi/ChangeLog.libffi +311 -0
  26. data/ext/ffi_c/libffi/LICENSE +1 -1
  27. data/ext/ffi_c/libffi/Makefile.am +14 -4
  28. data/ext/ffi_c/libffi/Makefile.in +362 -211
  29. data/ext/ffi_c/libffi/README +70 -92
  30. data/ext/ffi_c/libffi/aclocal.m4 +6068 -4586
  31. data/ext/ffi_c/libffi/config.guess +125 -143
  32. data/ext/ffi_c/libffi/config.sub +103 -27
  33. data/ext/ffi_c/libffi/configure +11340 -18473
  34. data/ext/ffi_c/libffi/configure.ac +43 -4
  35. data/ext/ffi_c/libffi/doc/libffi.info +15 -15
  36. data/ext/ffi_c/libffi/doc/libffi.texi +1 -1
  37. data/ext/ffi_c/libffi/doc/stamp-vti +4 -4
  38. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  39. data/ext/ffi_c/libffi/fficonfig.h.in +24 -3
  40. data/ext/ffi_c/libffi/include/Makefile.am +1 -1
  41. data/ext/ffi_c/libffi/include/Makefile.in +97 -50
  42. data/ext/ffi_c/libffi/include/ffi.h.in +8 -2
  43. data/ext/ffi_c/libffi/include/ffi_common.h +24 -0
  44. data/ext/ffi_c/libffi/libtool-version +1 -1
  45. data/ext/ffi_c/libffi/ltmain.sh +7346 -5870
  46. data/ext/ffi_c/libffi/m4/libtool.m4 +7360 -0
  47. data/ext/ffi_c/libffi/m4/ltoptions.m4 +368 -0
  48. data/ext/ffi_c/libffi/m4/ltsugar.m4 +123 -0
  49. data/ext/ffi_c/libffi/m4/ltversion.m4 +23 -0
  50. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +92 -0
  51. data/ext/ffi_c/libffi/man/Makefile.in +115 -62
  52. data/ext/ffi_c/libffi/man/ffi_call.3 +3 -3
  53. data/ext/ffi_c/libffi/missing +15 -8
  54. data/ext/ffi_c/libffi/src/arm/sysv.S +15 -8
  55. data/ext/ffi_c/libffi/src/avr32/ffi.c +421 -0
  56. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +50 -0
  57. data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
  58. data/ext/ffi_c/libffi/src/closures.c +47 -10
  59. data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
  60. data/ext/ffi_c/libffi/src/java_raw_api.c +0 -3
  61. data/ext/ffi_c/libffi/src/mips/ffi.c +135 -32
  62. data/ext/ffi_c/libffi/src/mips/ffitarget.h +37 -4
  63. data/ext/ffi_c/libffi/src/mips/n32.S +67 -10
  64. data/ext/ffi_c/libffi/src/mips/o32.S +8 -8
  65. data/ext/ffi_c/libffi/src/pa/ffi.c +7 -0
  66. data/ext/ffi_c/libffi/src/powerpc/aix.S +163 -64
  67. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +308 -112
  68. data/ext/ffi_c/libffi/src/powerpc/ffi.c +20 -7
  69. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +208 -80
  70. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +11 -3
  71. data/ext/ffi_c/libffi/src/powerpc/sysv.S +12 -23
  72. data/ext/ffi_c/libffi/src/s390/sysv.S +1 -1
  73. data/ext/ffi_c/libffi/src/sh/sysv.S +9 -9
  74. data/ext/ffi_c/libffi/src/sh64/ffi.c +37 -22
  75. data/ext/ffi_c/libffi/src/sh64/sysv.S +23 -14
  76. data/ext/ffi_c/libffi/src/sparc/ffi.c +21 -6
  77. data/ext/ffi_c/libffi/src/sparc/v8.S +55 -14
  78. data/ext/ffi_c/libffi/src/x86/darwin.S +10 -9
  79. data/ext/ffi_c/libffi/src/x86/ffi.c +293 -86
  80. data/ext/ffi_c/libffi/src/x86/ffi64.c +73 -19
  81. data/ext/ffi_c/libffi/src/x86/ffitarget.h +30 -0
  82. data/ext/ffi_c/libffi/src/x86/sysv.S +21 -4
  83. data/ext/ffi_c/libffi/src/x86/unix64.S +8 -4
  84. data/ext/ffi_c/libffi/src/x86/win32.S +633 -147
  85. data/ext/ffi_c/libffi/src/x86/win64.S +460 -0
  86. data/ext/ffi_c/libffi/testsuite/Makefile.am +63 -54
  87. data/ext/ffi_c/libffi/testsuite/Makefile.in +112 -77
  88. data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +12 -1
  89. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +4 -4
  90. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +7 -15
  91. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +7 -15
  92. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +7 -15
  93. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +7 -15
  94. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +7 -15
  95. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +7 -14
  96. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +7 -15
  97. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
  98. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_stdcall.c +6 -14
  99. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +4 -12
  100. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +4 -12
  101. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +4 -12
  102. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +4 -12
  103. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +4 -12
  104. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +4 -12
  105. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +4 -12
  106. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +4 -12
  107. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +4 -12
  108. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +4 -12
  109. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +4 -12
  110. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +4 -12
  111. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +4 -12
  112. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +4 -12
  113. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +4 -12
  114. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +4 -12
  115. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +4 -12
  116. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +4 -12
  117. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +4 -12
  118. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +4 -12
  119. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +4 -12
  120. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +4 -12
  121. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +4 -12
  122. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +4 -12
  123. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +4 -12
  124. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +4 -12
  125. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +4 -12
  126. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +134 -0
  127. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +117 -0
  128. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +11 -17
  129. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +4 -12
  130. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +4 -12
  131. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +7 -15
  132. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +4 -12
  133. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +4 -12
  134. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +7 -15
  135. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
  136. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +4 -12
  137. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +57 -0
  138. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +4 -13
  139. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
  140. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +57 -0
  141. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +4 -12
  142. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +4 -12
  143. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +4 -12
  144. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +4 -12
  145. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +4 -12
  146. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +4 -12
  147. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
  148. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +140 -0
  149. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +4 -12
  150. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +4 -12
  151. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +4 -12
  152. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +4 -12
  153. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +4 -12
  154. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +8 -16
  155. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +4 -12
  156. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +37 -0
  157. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +25 -0
  158. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +31 -0
  159. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +2 -1
  160. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +342 -0
  161. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +4 -12
  162. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +4 -12
  163. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +4 -12
  164. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +4 -12
  165. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +4 -12
  166. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +4 -12
  167. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +4 -12
  168. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +4 -12
  169. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +4 -12
  170. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +4 -12
  171. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +4 -12
  172. data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +4 -12
  173. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +1 -1
  174. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +1 -1
  175. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
  176. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
  177. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
  178. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +124 -0
  179. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
  180. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +10 -0
  181. data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +4 -5
  182. data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +17 -16
  183. data/ext/ffi_c/libffi/texinfo.tex +155 -427
  184. data/gen/Rakefile +4 -2
  185. data/lib/1.8/ffi_c.so +0 -0
  186. data/lib/1.9/ffi_c.so +0 -0
  187. data/lib/ffi/autopointer.rb +79 -20
  188. data/lib/ffi/callback.rb +4 -10
  189. data/lib/ffi/enum.rb +28 -0
  190. data/lib/ffi/ffi.rb +1 -0
  191. data/lib/ffi/io.rb +28 -0
  192. data/lib/ffi/library.rb +237 -182
  193. data/lib/ffi/memorypointer.rb +28 -62
  194. data/lib/ffi/platform.rb +27 -0
  195. data/lib/ffi/pointer.rb +28 -0
  196. data/lib/ffi/struct.rb +55 -1
  197. data/lib/ffi/types.rb +29 -0
  198. data/lib/ffi/variadic.rb +29 -0
  199. data/spec/ffi/library_spec.rb +31 -5
  200. data/spec/ffi/rbx/attach_function_spec.rb +2 -1
  201. data/spec/ffi/rbx/memory_pointer_spec.rb +2 -1
  202. data/spec/ffi/spec_helper.rb +5 -1
  203. data/spec/ffi/struct_spec.rb +82 -0
  204. data/tasks/ann.rake +80 -0
  205. data/tasks/extension.rake +25 -0
  206. data/tasks/gem.rake +200 -0
  207. data/tasks/git.rake +41 -0
  208. data/tasks/notes.rake +27 -0
  209. data/tasks/post_load.rake +34 -0
  210. data/tasks/rdoc.rake +50 -0
  211. data/tasks/rubyforge.rake +55 -0
  212. data/tasks/setup.rb +300 -0
  213. data/tasks/spec.rake +54 -0
  214. data/tasks/svn.rake +47 -0
  215. data/tasks/test.rake +40 -0
  216. metadata +312 -279
  217. data/ext/ffi_c/libffi/TODO +0 -1
  218. data/ext/ffi_c/libffi/ltcf-c.sh +0 -861
  219. data/ext/ffi_c/libffi/ltcf-cxx.sh +0 -1069
  220. data/ext/ffi_c/libffi/ltcf-gcj.sh +0 -700
  221. data/ext/ffi_c/libffi/ltconfig +0 -2862
  222. data/ext/ffi_c/libffi/mkinstalldirs +0 -158
@@ -39,16 +39,24 @@ extern "C" {
39
39
 
40
40
  extern void rbffi_Struct_Init(VALUE ffiModule);
41
41
  extern void rbffi_StructLayout_Init(VALUE ffiModule);
42
+ typedef struct StructField_ StructField;
43
+ typedef struct StructLayout_ StructLayout;
44
+ typedef struct Struct_ Struct;
42
45
 
43
- typedef struct StructField_ {
46
+ struct StructField_ {
44
47
  Type* type;
45
48
  unsigned int offset;
46
49
 
47
50
  VALUE rbType;
48
51
  VALUE rbName;
49
- } StructField;
50
52
 
51
- typedef struct StructLayout_ {
53
+ VALUE (*get)(StructField* field, Struct* s);
54
+ void (*put)(StructField* field, Struct* s, VALUE value);
55
+
56
+ MemoryOp* memoryOp;
57
+ };
58
+
59
+ struct StructLayout_ {
52
60
  Type base;
53
61
  StructField** fields;
54
62
  unsigned int fieldCount;
@@ -58,19 +66,20 @@ extern "C" {
58
66
  VALUE rbFieldNames;
59
67
  VALUE rbFieldMap;
60
68
  VALUE rbFields;
61
- } StructLayout;
69
+ };
62
70
 
63
- typedef struct Struct {
71
+ struct Struct_ {
64
72
  StructLayout* layout;
65
73
  AbstractMemory* pointer;
66
74
  VALUE rbLayout;
67
75
  VALUE rbPointer;
68
- } Struct;
76
+ };
69
77
 
70
78
  extern VALUE rbffi_StructClass, rbffi_StructLayoutClass;
71
79
  extern VALUE rbffi_StructLayoutFieldClass, rbffi_StructLayoutFunctionFieldClass;
72
- extern VALUE rbffi_StructLayoutArrayFieldClass, rbffi_StructLayoutStructFieldClass;
80
+ extern VALUE rbffi_StructLayoutArrayFieldClass;
73
81
  extern VALUE rbffi_StructInlineArrayClass;
82
+ extern VALUE rbffi_StructLayoutCharArrayClass;
74
83
 
75
84
  #ifdef __cplusplus
76
85
  }
@@ -53,7 +53,6 @@ static void struct_field_mark(StructField* );
53
53
 
54
54
  VALUE rbffi_StructLayoutFieldClass = Qnil;
55
55
  VALUE rbffi_StructLayoutFunctionFieldClass = Qnil, rbffi_StructLayoutArrayFieldClass = Qnil;
56
- VALUE rbffi_StructLayoutStructFieldClass = Qnil;
57
56
 
58
57
  VALUE rbffi_StructLayoutClass = Qnil;
59
58
 
@@ -105,6 +104,7 @@ struct_field_initialize(int argc, VALUE* argv, VALUE self)
105
104
  field->rbName = (TYPE(rbName) == T_SYMBOL) ? rbName : rb_str_intern(rbName);
106
105
  field->rbType = rbType;
107
106
  Data_Get_Struct(field->rbType, Type, field->type);
107
+ field->memoryOp = get_memory_op(field->type);
108
108
 
109
109
  return self;
110
110
  }
@@ -134,10 +134,11 @@ struct_field_alignment(VALUE self)
134
134
  }
135
135
 
136
136
  static VALUE
137
- struct_field_ffi_type(VALUE self)
137
+ struct_field_type(VALUE self)
138
138
  {
139
139
  StructField* field;
140
140
  Data_Get_Struct(self, StructField, field);
141
+
141
142
  return field->rbType;
142
143
  }
143
144
 
@@ -153,34 +154,28 @@ static VALUE
153
154
  struct_field_get(VALUE self, VALUE pointer)
154
155
  {
155
156
  StructField* f;
156
- MemoryOp* op;
157
- AbstractMemory* memory = MEMORY(pointer);
158
157
 
159
158
  Data_Get_Struct(self, StructField, f);
160
- op = memory_get_op(memory, f->type);
161
- if (op == NULL) {
162
- rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(self));
159
+ if (f->memoryOp == NULL) {
160
+ rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(f->rbType));
163
161
  return Qnil;
164
162
  }
165
163
 
166
- return (*op->get)(memory, f->offset);
164
+ return (*f->memoryOp->get)(MEMORY(pointer), f->offset);
167
165
  }
168
166
 
169
167
  static VALUE
170
168
  struct_field_put(VALUE self, VALUE pointer, VALUE value)
171
169
  {
172
170
  StructField* f;
173
- MemoryOp* op;
174
- AbstractMemory* memory = MEMORY(pointer);
175
-
171
+
176
172
  Data_Get_Struct(self, StructField, f);
177
- op = memory_get_op(memory, f->type);
178
- if (op == NULL) {
179
- rb_raise(rb_eArgError, "put not supported for %s", rb_obj_classname(self));
173
+ if (f->memoryOp == NULL) {
174
+ rb_raise(rb_eArgError, "put not supported for %s", rb_obj_classname(f->rbType));
180
175
  return self;
181
176
  }
182
177
 
183
- (*op->put)(memory, f->offset, value);
178
+ (*f->memoryOp->put)(MEMORY(pointer), f->offset, value);
184
179
 
185
180
  return self;
186
181
  }
@@ -189,33 +184,19 @@ static VALUE
189
184
  function_field_get(VALUE self, VALUE pointer)
190
185
  {
191
186
  StructField* f;
192
- MemoryOp* op;
193
- AbstractMemory* memory = MEMORY(pointer);
194
-
187
+
195
188
  Data_Get_Struct(self, StructField, f);
196
- op = memory->ops->pointer;
197
- if (op == NULL) {
198
- rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(self));
199
- return Qnil;
200
- }
201
189
 
202
- return rbffi_Function_NewInstance(f->rbType, (*op->get)(memory, f->offset));
190
+ return rbffi_Function_NewInstance(f->rbType, (*rbffi_AbstractMemoryOps.pointer->get)(MEMORY(pointer), f->offset));
203
191
  }
204
192
 
205
193
  static VALUE
206
194
  function_field_put(VALUE self, VALUE pointer, VALUE proc)
207
195
  {
208
196
  StructField* f;
209
- MemoryOp* op;
210
- AbstractMemory* memory = MEMORY(pointer);
211
197
  VALUE value = Qnil;
212
198
 
213
199
  Data_Get_Struct(self, StructField, f);
214
- op = memory->ops->pointer;
215
- if (op == NULL) {
216
- rb_raise(rb_eArgError, "put not supported for %s", rb_obj_classname(self));
217
- return self;
218
- }
219
200
 
220
201
  if (NIL_P(proc) || rb_obj_is_kind_of(proc, rbffi_FunctionClass)) {
221
202
  value = proc;
@@ -225,51 +206,110 @@ function_field_put(VALUE self, VALUE pointer, VALUE proc)
225
206
  rb_raise(rb_eTypeError, "wrong type (expected Proc or Function)");
226
207
  }
227
208
 
228
- (*op->put)(memory, f->offset, value);
209
+ (*rbffi_AbstractMemoryOps.pointer->put)(MEMORY(pointer), f->offset, value);
229
210
 
230
211
  return self;
231
212
  }
232
213
 
214
+ static inline bool
215
+ isCharArray(ArrayType* arrayType)
216
+ {
217
+ return arrayType->componentType->nativeType == NATIVE_INT8
218
+ || arrayType->componentType->nativeType == NATIVE_UINT8;
219
+ }
220
+
233
221
  static VALUE
234
222
  array_field_get(VALUE self, VALUE pointer)
235
223
  {
236
224
  StructField* f;
237
225
  ArrayType* array;
238
- MemoryOp* op;
239
- AbstractMemory* memory = MEMORY(pointer);
240
226
  VALUE argv[2];
241
227
 
242
228
  Data_Get_Struct(self, StructField, f);
243
229
  Data_Get_Struct(f->rbType, ArrayType, array);
244
230
 
245
- op = memory_get_op(memory, array->componentType);
246
- if (op == NULL) {
247
- rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(array->rbComponentType));
248
- return Qnil;
249
- }
250
-
251
231
  argv[0] = pointer;
252
232
  argv[1] = self;
253
233
 
254
- return rb_class_new_instance(2, argv, rbffi_StructInlineArrayClass);
234
+ return rb_class_new_instance(2, argv, isCharArray(array)
235
+ ? rbffi_StructLayoutCharArrayClass : rbffi_StructInlineArrayClass);
255
236
  }
256
237
 
257
238
  static VALUE
258
- inline_struct_field_get(VALUE self, VALUE pointer)
239
+ array_field_put(VALUE self, VALUE pointer, VALUE value)
259
240
  {
260
241
  StructField* f;
261
- StructByValue* sbv;
262
- VALUE rbPointer = Qnil, rbOffset = Qnil;
242
+ ArrayType* array;
243
+
263
244
 
264
245
  Data_Get_Struct(self, StructField, f);
265
- Data_Get_Struct(f->rbType, StructByValue, sbv);
246
+ Data_Get_Struct(f->rbType, ArrayType, array);
247
+
248
+ if (isCharArray(array) && rb_obj_is_instance_of(value, rb_cString)) {
249
+ VALUE argv[2];
250
+
251
+ argv[0] = INT2FIX(f->offset);
252
+ argv[1] = value;
266
253
 
267
- rbOffset = UINT2NUM(f->offset);
268
- rbPointer = rb_funcall2(pointer, rb_intern("+"), 1, &rbOffset);
254
+ rb_funcall2(pointer, rb_intern("put_string"), 2, argv);
269
255
 
270
- return rb_class_new_instance(1, &rbPointer, sbv->rbStructClass);
256
+ } else {
257
+ #ifdef notyet
258
+ MemoryOp* op;
259
+ int count = RARRAY_LEN(value);
260
+ int i;
261
+ AbstractMemory* memory = MEMORY(pointer);
262
+
263
+ if (count > array->length) {
264
+ rb_raise(rb_eIndexError, "array too large");
265
+ }
266
+
267
+ // clear the contents in case of a short write
268
+ checkWrite(memory);
269
+ checkBounds(memory, f->offset, f->type->ffiType->size);
270
+ if (count < array->length) {
271
+ memset(memory->address + f->offset + (count * array->componentType->ffiType->size),
272
+ 0, (array->length - count) * array->componentType->ffiType->size);
273
+ }
274
+
275
+ // now copy each element in
276
+ if ((op = get_memory_op(array->componentType)) != NULL) {
277
+
278
+ for (i = 0; i < count; ++i) {
279
+ (*op->put)(memory, f->offset + (i * array->componentType->ffiType->size), rb_ary_entry(value, i));
280
+ }
281
+
282
+ } else if (array->componentType->nativeType == NATIVE_STRUCT) {
283
+
284
+ for (i = 0; i < count; ++i) {
285
+ VALUE entry = rb_ary_entry(value, i);
286
+ Struct* s;
287
+
288
+ if (!rb_obj_is_kind_of(entry, rbffi_StructClass)) {
289
+ rb_raise(rb_eTypeError, "array element not an instance of FFI::Struct");
290
+ break;
291
+ }
292
+
293
+ Data_Get_Struct(entry, Struct, s);
294
+ checkRead(s->pointer);
295
+ checkBounds(s->pointer, 0, array->componentType->ffiType->size);
296
+
297
+ memcpy(memory->address + f->offset + (i * array->componentType->ffiType->size),
298
+ s->pointer->address, array->componentType->ffiType->size);
299
+ }
300
+
301
+ } else {
302
+ rb_raise(rb_eNotImpError, "put not supported for arrays of type %s", rb_obj_classname(array->rbComponentType));
303
+ }
304
+ #else
305
+ rb_raise(rb_eNotImpError, "cannot set array field");
306
+ #endif
307
+ }
308
+
309
+ return value;
271
310
  }
272
311
 
312
+
273
313
  static VALUE
274
314
  struct_layout_allocate(VALUE klass)
275
315
  {
@@ -309,7 +349,7 @@ struct_layout_initialize(VALUE self, VALUE field_names, VALUE fields, VALUE size
309
349
  layout->base.ffiType->alignment = 1;
310
350
 
311
351
  ltype = layout->base.ffiType;
312
- for (i = 0; i < layout->fieldCount; ++i) {
352
+ for (i = 0; i < (int) layout->fieldCount; ++i) {
313
353
  VALUE rbName = rb_ary_entry(field_names, i);
314
354
  VALUE rbField = rb_hash_aref(fields, rbName);
315
355
  StructField* field;
@@ -405,6 +445,7 @@ struct_layout_free(StructLayout *layout)
405
445
  xfree(layout);
406
446
  }
407
447
 
448
+
408
449
  void
409
450
  rbffi_StructLayout_Init(VALUE moduleFFI)
410
451
  {
@@ -417,9 +458,6 @@ rbffi_StructLayout_Init(VALUE moduleFFI)
417
458
  rbffi_StructLayoutFunctionFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "Function", rbffi_StructLayoutFieldClass);
418
459
  rb_global_variable(&rbffi_StructLayoutFunctionFieldClass);
419
460
 
420
- rbffi_StructLayoutStructFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "StructByValue", rbffi_StructLayoutFieldClass);
421
- rb_global_variable(&rbffi_StructLayoutStructFieldClass);
422
-
423
461
  rbffi_StructLayoutArrayFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "Array", rbffi_StructLayoutFieldClass);
424
462
  rb_global_variable(&rbffi_StructLayoutArrayFieldClass);
425
463
 
@@ -429,7 +467,7 @@ rbffi_StructLayout_Init(VALUE moduleFFI)
429
467
  rb_define_method(rbffi_StructLayoutFieldClass, "size", struct_field_size, 0);
430
468
  rb_define_method(rbffi_StructLayoutFieldClass, "alignment", struct_field_alignment, 0);
431
469
  rb_define_method(rbffi_StructLayoutFieldClass, "name", struct_field_name, 0);
432
- rb_define_method(rbffi_StructLayoutFieldClass, "ffi_type", struct_field_ffi_type, 0);
470
+ rb_define_method(rbffi_StructLayoutFieldClass, "type", struct_field_type, 0);
433
471
  rb_define_method(rbffi_StructLayoutFieldClass, "put", struct_field_put, 2);
434
472
  rb_define_method(rbffi_StructLayoutFieldClass, "get", struct_field_get, 1);
435
473
 
@@ -437,8 +475,7 @@ rbffi_StructLayout_Init(VALUE moduleFFI)
437
475
  rb_define_method(rbffi_StructLayoutFunctionFieldClass, "get", function_field_get, 1);
438
476
 
439
477
  rb_define_method(rbffi_StructLayoutArrayFieldClass, "get", array_field_get, 1);
440
- rb_define_method(rbffi_StructLayoutStructFieldClass, "get", inline_struct_field_get, 1);
441
-
478
+ rb_define_method(rbffi_StructLayoutArrayFieldClass, "put", array_field_put, 2);
442
479
 
443
480
  rb_define_alloc_func(rbffi_StructLayoutClass, struct_layout_allocate);
444
481
  rb_define_method(rbffi_StructLayoutClass, "initialize", struct_layout_initialize, 4);
@@ -42,7 +42,7 @@ typedef struct BuiltinType_ {
42
42
 
43
43
  static void builtin_type_free(BuiltinType *);
44
44
 
45
- VALUE rbffi_TypeClass = Qnil;
45
+ VALUE rbffi_TypeClass = Qnil, rbffi_EnumTypeClass = Qnil;
46
46
 
47
47
  static VALUE classBuiltinType = Qnil;
48
48
  static VALUE typeMap = Qnil, sizeMap = Qnil;
@@ -243,7 +243,7 @@ rbffi_Type_Init(VALUE moduleFFI)
243
243
  {
244
244
  VALUE moduleNativeType;
245
245
  VALUE classType = rbffi_TypeClass = rb_define_class_under(moduleFFI, "Type", rb_cObject);
246
- VALUE classEnum = rb_define_class_under(moduleFFI, "Enum", classType);
246
+ VALUE classEnum = rbffi_EnumTypeClass = rb_define_class_under(moduleFFI, "Enum", classType);
247
247
 
248
248
  rb_define_const(moduleFFI, "TypeDefs", typeMap = rb_hash_new());
249
249
  rb_define_const(moduleFFI, "SizeTypes", sizeMap = rb_hash_new());
@@ -293,6 +293,8 @@ rbffi_Type_Init(VALUE moduleFFI)
293
293
  T(UINT32, &ffi_type_uint32);
294
294
  T(INT64, &ffi_type_sint64);
295
295
  T(UINT64, &ffi_type_uint64);
296
+ T(LONG, &ffi_type_slong);
297
+ T(ULONG, &ffi_type_ulong);
296
298
  T(FLOAT32, &ffi_type_float);
297
299
  T(FLOAT64, &ffi_type_double);
298
300
  T(POINTER, &ffi_type_pointer);
@@ -302,28 +304,9 @@ rbffi_Type_Init(VALUE moduleFFI)
302
304
  T(BUFFER_OUT, &ffi_type_pointer);
303
305
  T(BUFFER_INOUT, &ffi_type_pointer);
304
306
  T(ENUM, &ffi_type_sint);
305
- T(BOOL, &ffi_type_sint);
307
+ T(BOOL, &ffi_type_uchar);
306
308
 
307
309
 
308
310
  T(CHAR_ARRAY, &ffi_type_void);
309
311
  T(VARARGS, &ffi_type_void);
310
-
311
-
312
- if (sizeof(long) == 4) {
313
- VALUE t = Qnil;
314
- rb_define_const(classType, "LONG", t = builtin_type_new(classBuiltinType, NATIVE_INT32, &ffi_type_slong, "LONG"));
315
- rb_define_const(moduleNativeType, "LONG", t);
316
- rb_define_const(moduleFFI, "TYPE_LONG", t);
317
- rb_define_const(classType, "ULONG", t = builtin_type_new(classBuiltinType, NATIVE_UINT32, &ffi_type_slong, "ULONG"));
318
- rb_define_const(moduleNativeType, "ULONG", t);
319
- rb_define_const(moduleFFI, "TYPE_ULONG", t);
320
- } else {
321
- VALUE t = Qnil;
322
- rb_define_const(classType, "LONG", t = builtin_type_new(classBuiltinType, NATIVE_INT64, &ffi_type_slong, "LONG"));
323
- rb_define_const(moduleNativeType, "LONG", t);
324
- rb_define_const(moduleFFI, "TYPE_LONG", t);
325
- rb_define_const(classType, "ULONG", t = builtin_type_new(classBuiltinType, NATIVE_UINT64, &ffi_type_slong, "ULONG"));
326
- rb_define_const(moduleNativeType, "ULONG", t);
327
- rb_define_const(moduleFFI, "TYPE_ULONG", t);
328
- }
329
312
  }
@@ -44,7 +44,7 @@ struct Type_ {
44
44
  ffi_type* ffiType;
45
45
  };
46
46
 
47
- extern VALUE rbffi_TypeClass;
47
+ extern VALUE rbffi_TypeClass, rbffi_EnumTypeClass;
48
48
  extern int rbffi_Type_GetIntValue(VALUE type);
49
49
  extern VALUE rbffi_Type_Lookup(VALUE type);
50
50
  extern VALUE rbffi_Type_Find(VALUE type);
@@ -51,16 +51,22 @@ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr, VALUE enums)
51
51
  return INT2NUM((signed short) *(ffi_sarg *) ptr);
52
52
  case NATIVE_INT32:
53
53
  return INT2NUM((signed int) *(ffi_sarg *) ptr);
54
+ case NATIVE_LONG:
55
+ return LONG2NUM((signed long) *(ffi_sarg *) ptr);
56
+ case NATIVE_INT64:
57
+ return LL2NUM(*(signed long long *) ptr);
58
+
54
59
  case NATIVE_UINT8:
55
60
  return UINT2NUM((unsigned char) *(ffi_arg *) ptr);
56
61
  case NATIVE_UINT16:
57
62
  return UINT2NUM((unsigned short) *(ffi_arg *) ptr);
58
63
  case NATIVE_UINT32:
59
64
  return UINT2NUM((unsigned int) *(ffi_arg *) ptr);
60
- case NATIVE_INT64:
61
- return LL2NUM(*(signed long long *) ptr);
65
+ case NATIVE_ULONG:
66
+ return ULONG2NUM((unsigned long) *(ffi_arg *) ptr);
62
67
  case NATIVE_UINT64:
63
68
  return ULL2NUM(*(unsigned long long *) ptr);
69
+
64
70
  case NATIVE_FLOAT32:
65
71
  return rb_float_new(*(float *) ptr);
66
72
  case NATIVE_FLOAT64:
@@ -70,7 +76,7 @@ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr, VALUE enums)
70
76
  case NATIVE_POINTER:
71
77
  return rbffi_Pointer_NewInstance(*(void **) ptr);
72
78
  case NATIVE_BOOL:
73
- return ((int) *(ffi_arg *) ptr) ? Qtrue : Qfalse;
79
+ return ((unsigned char) *(ffi_arg *) ptr) ? Qtrue : Qfalse;
74
80
  case NATIVE_ENUM:
75
81
  return rb_funcall(rbType, id_find, 1, INT2NUM((unsigned int) *(ffi_arg *) ptr));
76
82
 
@@ -44,6 +44,8 @@ typedef enum {
44
44
  NATIVE_UINT32,
45
45
  NATIVE_INT64,
46
46
  NATIVE_UINT64,
47
+ NATIVE_LONG,
48
+ NATIVE_ULONG,
47
49
  NATIVE_FLOAT32,
48
50
  NATIVE_FLOAT64,
49
51
  NATIVE_POINTER,
@@ -4,21 +4,25 @@ require 'rbconfig'
4
4
  dir_config("ffi_c")
5
5
 
6
6
  unless Config::CONFIG['host_os'] =~ /mswin32|mingw32/
7
- pkg_config("libffi") || find_header("ffi.h", "/usr/local/include", "/opt/local/include")
8
- have_ffi_call = have_library("ffi", "ffi_call", [ "ffi.h" ])
9
- have_prep_closure = have_func("ffi_prep_closure")
10
- libffi_ok = have_ffi_call && have_prep_closure
11
- $defs << "-DHAVE_LIBFFI" if libffi_ok
12
- $defs << "-DHAVE_RAW_API" if have_func("ffi_raw_call") && have_func("ffi_prep_raw_closure")
7
+ if pkg_config("libffi") || find_header("ffi.h", "/usr/local/include")
8
+
9
+ # 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
+
12
+ # Check if the raw api is available.
13
+ $defs << "-DHAVE_RAW_API" if have_func("ffi_raw_call") && have_func("ffi_prep_raw_closure")
14
+ end
13
15
  end
16
+
14
17
  have_func('rb_thread_blocking_region')
15
18
 
16
19
  $defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works
20
+ $defs << "-DUSE_INTERNAL_LIBFFI" unless libffi_ok
17
21
 
18
22
  create_header
19
23
 
20
24
  $CFLAGS << " -mwin32 " if Config::CONFIG['host_os'] =~ /cygwin/
21
- $CFLAGS << " -Werror -Wunused -Wformat -Wimplicit -Wreturn-type "
25
+ #$CFLAGS << " -Werror -Wunused -Wformat -Wimplicit -Wreturn-type "
22
26
 
23
27
  create_makefile("ffi_c")
24
28
  unless libffi_ok