ffi-aitrus 0.9.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (369) hide show
  1. data/History.txt +102 -0
  2. data/LICENSE +14 -0
  3. data/README.rdoc +70 -0
  4. data/Rakefile +189 -0
  5. data/ext/ffi_c/AbstractMemory.c +510 -0
  6. data/ext/ffi_c/AbstractMemory.h +155 -0
  7. data/ext/ffi_c/ArrayType.c +129 -0
  8. data/ext/ffi_c/ArrayType.h +58 -0
  9. data/ext/ffi_c/Buffer.c +242 -0
  10. data/ext/ffi_c/Call.c +393 -0
  11. data/ext/ffi_c/Call.h +90 -0
  12. data/ext/ffi_c/ClosurePool.c +304 -0
  13. data/ext/ffi_c/ClosurePool.h +29 -0
  14. data/ext/ffi_c/DataConverter.c +62 -0
  15. data/ext/ffi_c/DynamicLibrary.c +235 -0
  16. data/ext/ffi_c/DynamicLibrary.h +22 -0
  17. data/ext/ffi_c/Function.c +718 -0
  18. data/ext/ffi_c/Function.h +80 -0
  19. data/ext/ffi_c/FunctionInfo.c +221 -0
  20. data/ext/ffi_c/LastError.c +159 -0
  21. data/ext/ffi_c/LastError.h +18 -0
  22. data/ext/ffi_c/MappedType.c +146 -0
  23. data/ext/ffi_c/MappedType.h +57 -0
  24. data/ext/ffi_c/MemoryPointer.c +157 -0
  25. data/ext/ffi_c/MemoryPointer.h +20 -0
  26. data/ext/ffi_c/MethodHandle.c +346 -0
  27. data/ext/ffi_c/MethodHandle.h +53 -0
  28. data/ext/ffi_c/Platform.c +61 -0
  29. data/ext/ffi_c/Platform.h +16 -0
  30. data/ext/ffi_c/Pointer.c +276 -0
  31. data/ext/ffi_c/Pointer.h +49 -0
  32. data/ext/ffi_c/Struct.c +631 -0
  33. data/ext/ffi_c/Struct.h +95 -0
  34. data/ext/ffi_c/StructByReference.c +150 -0
  35. data/ext/ffi_c/StructByReference.h +50 -0
  36. data/ext/ffi_c/StructByValue.c +140 -0
  37. data/ext/ffi_c/StructByValue.h +53 -0
  38. data/ext/ffi_c/StructLayout.c +498 -0
  39. data/ext/ffi_c/Type.c +283 -0
  40. data/ext/ffi_c/Type.h +47 -0
  41. data/ext/ffi_c/Types.c +124 -0
  42. data/ext/ffi_c/Types.h +87 -0
  43. data/ext/ffi_c/Variadic.c +252 -0
  44. data/ext/ffi_c/compat.h +72 -0
  45. data/ext/ffi_c/endian.h +40 -0
  46. data/ext/ffi_c/extconf.rb +43 -0
  47. data/ext/ffi_c/ffi.c +88 -0
  48. data/ext/ffi_c/libffi.bsd.mk +34 -0
  49. data/ext/ffi_c/libffi.darwin.mk +75 -0
  50. data/ext/ffi_c/libffi.gnu.mk +29 -0
  51. data/ext/ffi_c/libffi.mk +13 -0
  52. data/ext/ffi_c/libffi/ChangeLog +4059 -0
  53. data/ext/ffi_c/libffi/ChangeLog.libffi +658 -0
  54. data/ext/ffi_c/libffi/ChangeLog.libgcj +40 -0
  55. data/ext/ffi_c/libffi/ChangeLog.v1 +764 -0
  56. data/ext/ffi_c/libffi/LICENSE +21 -0
  57. data/ext/ffi_c/libffi/Makefile.am +187 -0
  58. data/ext/ffi_c/libffi/Makefile.in +1791 -0
  59. data/ext/ffi_c/libffi/README +306 -0
  60. data/ext/ffi_c/libffi/acinclude.m4 +92 -0
  61. data/ext/ffi_c/libffi/aclocal.m4 +8998 -0
  62. data/ext/ffi_c/libffi/compile +142 -0
  63. data/ext/ffi_c/libffi/config.guess +1498 -0
  64. data/ext/ffi_c/libffi/config.sub +1702 -0
  65. data/ext/ffi_c/libffi/configure +17281 -0
  66. data/ext/ffi_c/libffi/configure.ac +404 -0
  67. data/ext/ffi_c/libffi/configure.host +11 -0
  68. data/ext/ffi_c/libffi/depcomp +584 -0
  69. data/ext/ffi_c/libffi/doc/libffi.info +533 -0
  70. data/ext/ffi_c/libffi/doc/libffi.texi +541 -0
  71. data/ext/ffi_c/libffi/doc/stamp-vti +4 -0
  72. data/ext/ffi_c/libffi/doc/version.texi +4 -0
  73. data/ext/ffi_c/libffi/fficonfig.h.in +181 -0
  74. data/ext/ffi_c/libffi/include/Makefile.am +9 -0
  75. data/ext/ffi_c/libffi/include/Makefile.in +469 -0
  76. data/ext/ffi_c/libffi/include/ffi.h.in +399 -0
  77. data/ext/ffi_c/libffi/include/ffi_common.h +122 -0
  78. data/ext/ffi_c/libffi/install-sh +323 -0
  79. data/ext/ffi_c/libffi/libffi.pc.in +10 -0
  80. data/ext/ffi_c/libffi/libtool-version +29 -0
  81. data/ext/ffi_c/libffi/ltmain.sh +8406 -0
  82. data/ext/ffi_c/libffi/m4/libtool.m4 +7360 -0
  83. data/ext/ffi_c/libffi/m4/ltoptions.m4 +368 -0
  84. data/ext/ffi_c/libffi/m4/ltsugar.m4 +123 -0
  85. data/ext/ffi_c/libffi/m4/ltversion.m4 +23 -0
  86. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +92 -0
  87. data/ext/ffi_c/libffi/man/Makefile.am +8 -0
  88. data/ext/ffi_c/libffi/man/Makefile.in +448 -0
  89. data/ext/ffi_c/libffi/man/ffi.3 +31 -0
  90. data/ext/ffi_c/libffi/man/ffi_call.3 +103 -0
  91. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +66 -0
  92. data/ext/ffi_c/libffi/mdate-sh +201 -0
  93. data/ext/ffi_c/libffi/missing +360 -0
  94. data/ext/ffi_c/libffi/src/alpha/ffi.c +284 -0
  95. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +48 -0
  96. data/ext/ffi_c/libffi/src/alpha/osf.S +366 -0
  97. data/ext/ffi_c/libffi/src/arm/ffi.c +309 -0
  98. data/ext/ffi_c/libffi/src/arm/ffitarget.h +49 -0
  99. data/ext/ffi_c/libffi/src/arm/sysv.S +306 -0
  100. data/ext/ffi_c/libffi/src/avr32/ffi.c +421 -0
  101. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +50 -0
  102. data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
  103. data/ext/ffi_c/libffi/src/closures.c +633 -0
  104. data/ext/ffi_c/libffi/src/cris/ffi.c +383 -0
  105. data/ext/ffi_c/libffi/src/cris/ffitarget.h +51 -0
  106. data/ext/ffi_c/libffi/src/cris/sysv.S +215 -0
  107. data/ext/ffi_c/libffi/src/debug.c +59 -0
  108. data/ext/ffi_c/libffi/src/dlmalloc.c +5099 -0
  109. data/ext/ffi_c/libffi/src/frv/eabi.S +128 -0
  110. data/ext/ffi_c/libffi/src/frv/ffi.c +292 -0
  111. data/ext/ffi_c/libffi/src/frv/ffitarget.h +61 -0
  112. data/ext/ffi_c/libffi/src/ia64/ffi.c +580 -0
  113. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +50 -0
  114. data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +40 -0
  115. data/ext/ffi_c/libffi/src/ia64/unix.S +560 -0
  116. data/ext/ffi_c/libffi/src/java_raw_api.c +356 -0
  117. data/ext/ffi_c/libffi/src/m32r/ffi.c +232 -0
  118. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +48 -0
  119. data/ext/ffi_c/libffi/src/m32r/sysv.S +121 -0
  120. data/ext/ffi_c/libffi/src/m68k/ffi.c +278 -0
  121. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +49 -0
  122. data/ext/ffi_c/libffi/src/m68k/sysv.S +234 -0
  123. data/ext/ffi_c/libffi/src/mips/ffi.c +1029 -0
  124. data/ext/ffi_c/libffi/src/mips/ffitarget.h +235 -0
  125. data/ext/ffi_c/libffi/src/mips/n32.S +591 -0
  126. data/ext/ffi_c/libffi/src/mips/o32.S +381 -0
  127. data/ext/ffi_c/libffi/src/pa/ffi.c +716 -0
  128. data/ext/ffi_c/libffi/src/pa/ffitarget.h +77 -0
  129. data/ext/ffi_c/libffi/src/pa/hpux32.S +368 -0
  130. data/ext/ffi_c/libffi/src/pa/linux.S +357 -0
  131. data/ext/ffi_c/libffi/src/powerpc/aix.S +324 -0
  132. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +443 -0
  133. data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
  134. data/ext/ffi_c/libffi/src/powerpc/darwin.S +245 -0
  135. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +317 -0
  136. data/ext/ffi_c/libffi/src/powerpc/ffi.c +1442 -0
  137. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +928 -0
  138. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +126 -0
  139. data/ext/ffi_c/libffi/src/powerpc/linux64.S +187 -0
  140. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +236 -0
  141. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +327 -0
  142. data/ext/ffi_c/libffi/src/powerpc/sysv.S +219 -0
  143. data/ext/ffi_c/libffi/src/prep_cif.c +174 -0
  144. data/ext/ffi_c/libffi/src/raw_api.c +254 -0
  145. data/ext/ffi_c/libffi/src/s390/ffi.c +780 -0
  146. data/ext/ffi_c/libffi/src/s390/ffitarget.h +60 -0
  147. data/ext/ffi_c/libffi/src/s390/sysv.S +434 -0
  148. data/ext/ffi_c/libffi/src/sh/ffi.c +716 -0
  149. data/ext/ffi_c/libffi/src/sh/ffitarget.h +49 -0
  150. data/ext/ffi_c/libffi/src/sh/sysv.S +850 -0
  151. data/ext/ffi_c/libffi/src/sh64/ffi.c +468 -0
  152. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +53 -0
  153. data/ext/ffi_c/libffi/src/sh64/sysv.S +539 -0
  154. data/ext/ffi_c/libffi/src/sparc/ffi.c +625 -0
  155. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +66 -0
  156. data/ext/ffi_c/libffi/src/sparc/v8.S +313 -0
  157. data/ext/ffi_c/libffi/src/sparc/v9.S +307 -0
  158. data/ext/ffi_c/libffi/src/types.c +77 -0
  159. data/ext/ffi_c/libffi/src/x86/darwin.S +444 -0
  160. data/ext/ffi_c/libffi/src/x86/darwin64.S +416 -0
  161. data/ext/ffi_c/libffi/src/x86/ffi.c +682 -0
  162. data/ext/ffi_c/libffi/src/x86/ffi64.c +626 -0
  163. data/ext/ffi_c/libffi/src/x86/ffitarget.h +120 -0
  164. data/ext/ffi_c/libffi/src/x86/freebsd.S +458 -0
  165. data/ext/ffi_c/libffi/src/x86/sysv.S +454 -0
  166. data/ext/ffi_c/libffi/src/x86/unix64.S +422 -0
  167. data/ext/ffi_c/libffi/src/x86/win32.S +877 -0
  168. data/ext/ffi_c/libffi/src/x86/win64.S +460 -0
  169. data/ext/ffi_c/libffi/testsuite/Makefile.am +80 -0
  170. data/ext/ffi_c/libffi/testsuite/Makefile.in +482 -0
  171. data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
  172. data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +300 -0
  173. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +263 -0
  174. data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +45 -0
  175. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +36 -0
  176. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +89 -0
  177. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +81 -0
  178. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +81 -0
  179. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +82 -0
  180. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +89 -0
  181. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +92 -0
  182. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +90 -0
  183. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
  184. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_stdcall.c +64 -0
  185. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +94 -0
  186. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +95 -0
  187. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +96 -0
  188. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +102 -0
  189. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +89 -0
  190. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +91 -0
  191. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +93 -0
  192. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +113 -0
  193. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +90 -0
  194. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +95 -0
  195. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +90 -0
  196. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +90 -0
  197. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +98 -0
  198. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +90 -0
  199. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +109 -0
  200. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +98 -0
  201. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +124 -0
  202. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +113 -0
  203. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +99 -0
  204. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +117 -0
  205. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +97 -0
  206. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +88 -0
  207. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +90 -0
  208. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +91 -0
  209. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +93 -0
  210. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +91 -0
  211. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +92 -0
  212. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +134 -0
  213. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +117 -0
  214. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +95 -0
  215. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +91 -0
  216. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +91 -0
  217. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +91 -0
  218. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +91 -0
  219. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +91 -0
  220. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +92 -0
  221. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
  222. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +43 -0
  223. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +57 -0
  224. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +42 -0
  225. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
  226. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +57 -0
  227. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +74 -0
  228. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +74 -0
  229. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +86 -0
  230. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +91 -0
  231. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +74 -0
  232. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +86 -0
  233. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
  234. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +140 -0
  235. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +44 -0
  236. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +42 -0
  237. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +42 -0
  238. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +42 -0
  239. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +43 -0
  240. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +46 -0
  241. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +43 -0
  242. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +37 -0
  243. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +25 -0
  244. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +117 -0
  245. data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +59 -0
  246. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +58 -0
  247. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +58 -0
  248. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +72 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +62 -0
  250. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +342 -0
  251. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +69 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +63 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +53 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +152 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +161 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +133 -0
  257. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +110 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +111 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +111 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +112 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +131 -0
  262. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +111 -0
  263. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +131 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +131 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +90 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +59 -0
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +114 -0
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +35 -0
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +43 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +42 -0
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +35 -0
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +36 -0
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +49 -0
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +42 -0
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +34 -0
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +41 -0
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +42 -0
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +36 -0
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +38 -0
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +38 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +38 -0
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +124 -0
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +44 -0
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +44 -0
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +65 -0
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +67 -0
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +59 -0
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +63 -0
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +65 -0
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +64 -0
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +74 -0
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +80 -0
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +67 -0
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
  298. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +96 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +37 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +124 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc +53 -0
  302. data/ext/ffi_c/libffi/texinfo.tex +7210 -0
  303. data/ext/ffi_c/rbffi.h +27 -0
  304. data/gen/Rakefile +14 -0
  305. data/lib/ffi.rb +11 -0
  306. data/lib/ffi/autopointer.rb +121 -0
  307. data/lib/ffi/buffer.rb +4 -0
  308. data/lib/ffi/callback.rb +4 -0
  309. data/lib/ffi/enum.rb +119 -0
  310. data/lib/ffi/errno.rb +28 -0
  311. data/lib/ffi/ffi.rb +32 -0
  312. data/lib/ffi/io.rb +41 -0
  313. data/lib/ffi/library.rb +290 -0
  314. data/lib/ffi/managedstruct.rb +55 -0
  315. data/lib/ffi/memorypointer.rb +33 -0
  316. data/lib/ffi/platform.rb +111 -0
  317. data/lib/ffi/pointer.rb +140 -0
  318. data/lib/ffi/struct.rb +286 -0
  319. data/lib/ffi/struct_layout_builder.rb +158 -0
  320. data/lib/ffi/tools/const_generator.rb +177 -0
  321. data/lib/ffi/tools/generator.rb +58 -0
  322. data/lib/ffi/tools/generator_task.rb +35 -0
  323. data/lib/ffi/tools/struct_generator.rb +194 -0
  324. data/lib/ffi/tools/types_generator.rb +123 -0
  325. data/lib/ffi/types.rb +153 -0
  326. data/lib/ffi/union.rb +32 -0
  327. data/lib/ffi/variadic.rb +65 -0
  328. data/spec/ffi/async_callback_spec.rb +23 -0
  329. data/spec/ffi/bool_spec.rb +24 -0
  330. data/spec/ffi/buffer_spec.rb +202 -0
  331. data/spec/ffi/callback_spec.rb +653 -0
  332. data/spec/ffi/custom_param_type.rb +31 -0
  333. data/spec/ffi/custom_type_spec.rb +73 -0
  334. data/spec/ffi/enum_spec.rb +183 -0
  335. data/spec/ffi/errno_spec.rb +13 -0
  336. data/spec/ffi/ffi_spec.rb +24 -0
  337. data/spec/ffi/function_spec.rb +73 -0
  338. data/spec/ffi/library_spec.rb +174 -0
  339. data/spec/ffi/managed_struct_spec.rb +56 -0
  340. data/spec/ffi/number_spec.rb +231 -0
  341. data/spec/ffi/pointer_spec.rb +210 -0
  342. data/spec/ffi/rbx/attach_function_spec.rb +28 -0
  343. data/spec/ffi/rbx/memory_pointer_spec.rb +109 -0
  344. data/spec/ffi/rbx/spec_helper.rb +1 -0
  345. data/spec/ffi/rbx/struct_spec.rb +13 -0
  346. data/spec/ffi/spec_helper.rb +21 -0
  347. data/spec/ffi/string_spec.rb +103 -0
  348. data/spec/ffi/strptr_spec.rb +36 -0
  349. data/spec/ffi/struct_callback_spec.rb +64 -0
  350. data/spec/ffi/struct_initialize_spec.rb +30 -0
  351. data/spec/ffi/struct_packed_spec.rb +46 -0
  352. data/spec/ffi/struct_spec.rb +638 -0
  353. data/spec/ffi/typedef_spec.rb +62 -0
  354. data/spec/ffi/union_spec.rb +60 -0
  355. data/spec/ffi/variadic_spec.rb +84 -0
  356. data/spec/spec.opts +4 -0
  357. data/tasks/ann.rake +80 -0
  358. data/tasks/extension.rake +25 -0
  359. data/tasks/gem.rake +200 -0
  360. data/tasks/git.rake +41 -0
  361. data/tasks/notes.rake +27 -0
  362. data/tasks/post_load.rake +34 -0
  363. data/tasks/rdoc.rake +50 -0
  364. data/tasks/rubyforge.rake +55 -0
  365. data/tasks/setup.rb +301 -0
  366. data/tasks/spec.rake +54 -0
  367. data/tasks/svn.rake +47 -0
  368. data/tasks/test.rake +40 -0
  369. metadata +474 -0
data/History.txt ADDED
@@ -0,0 +1,102 @@
1
+ == 0.5.0 / 2009-10-06
2
+
3
+ * Major improvements
4
+ * New Function class
5
+ * Structs can be passed and returned by value
6
+ * Implement a custom trampoline for x86_64, resulting in roughly 30% speedup
7
+ * Improve dispatch of functions which take (0..6) char/short/int/long/pointer arguments by between 50% and 200% on x86_64
8
+ * Callbacks are now approximately 100% faster on x86_64
9
+ * Minor improvements
10
+ * Add support for MacOSX Snow Leopard
11
+ * Improve support for Windows releasing fat binaries on rubyforge
12
+ * Better introspection in structs:
13
+ * Add StructLayout::Field#type, size, offset, alignment and name
14
+ methods
15
+ * Add StructLayout#fields which returns an array of
16
+ StructLayout::Field objects
17
+ * Add automagic deducing of library name from module name.
18
+ Idea and prototype implementation from Matt Hulse
19
+ * Callback fields in structs can now be both read and written
20
+ * Add a bunch of new benchmarks
21
+ * Lots of refactoring
22
+ * Experimental features
23
+ * blocking functions (i.e. native code that blocks the thread) support
24
+ * Bug fixes
25
+ * Fix RUBY-FFI_43 (rake gem dependency)
26
+
27
+ == 0.4.0 / 2009-08-05
28
+
29
+ * Major improvements
30
+ * Add support for boolean types
31
+ * Add support for methods as callbacks
32
+ * Add FFI::IO.read as described in JRUBY-3636
33
+ * Minor improvements
34
+ * Add Pointer::NULL constant
35
+ * Add AbstractMemory#get_array_of_string()
36
+ * Implement Pointer.new(address) and Pointer.new(:type, address)
37
+ * Bug fixes
38
+ * Fix RUBY_FFI-38
39
+ * Fix issues related to 1.9.1 build
40
+ * Fix issues related to OSX build
41
+ * Fix issues related to FreeBSD build
42
+ * Fix issues related to OpenSolaris build
43
+
44
+ == 0.3.5 / 2009-05-08
45
+
46
+ * Bug fixes
47
+ * Fix RUBY_FFI-17
48
+ * Fix RUBY_FFI-21
49
+
50
+ == 0.3.4 / 2009-05-01
51
+
52
+ * Minor improvements
53
+ * Add return statements to functions that call rb_raise(), in case
54
+ rb_raise is not declared noreturn, to avoid gcc warnings.
55
+
56
+ == 0.3.3 / 2009-04-27
57
+
58
+ * Minor improvements
59
+ * Implement RUBY_FFI-16 - Add support for anonymous callbacks
60
+ * Add support for callback parameters in callbacks
61
+ * Add support for function pointer return values
62
+ * Callbacks can now coerce proc objects into function pointers for
63
+ return values.
64
+ * Implement FFI::Type and FFI::Type::Builtin
65
+ * Add support for enumerations
66
+ * Bug fixes
67
+ * Fix RUBY_FFI-19
68
+ * Fix RUBY_FFI-15
69
+
70
+ == 0.3.2 / 2009-05-01
71
+
72
+ * Bug fixes
73
+ * Fix JRUBY-3527 by passing RTLD_GLOBAL instead of RTLD_LOCAL
74
+
75
+ == 0.3.1 / 2009-03-23
76
+
77
+ * Bug fixes
78
+ * Correctly save errno/GetLastError after each call.
79
+
80
+ == 0.3.0 / 2009-03-19
81
+
82
+ * Switch compilation to rake-compiler
83
+ * Makes cross-compilation from linux -> win32 super easy
84
+ * win32 support is available now, but highly experimental
85
+ * Performance improvements
86
+ * struct field access approx 3x faster than 0.2.0
87
+ * function invocation approx 20% faster than 0.2.0
88
+ * A bunch of minor improvements
89
+ * Struct instances can now be passed as :pointer parameters without calling
90
+ Struct#pointer
91
+ * Support for array struct members
92
+ * Structs are now padded correctly to the alignment of the struct's
93
+ largest field
94
+ * Global library variables
95
+ * Callbacks in global library variables
96
+ * Strings passed in as :string arguments are scrubbed to avoid
97
+ poison-null-byte attacks.
98
+ * Union support
99
+ * nil can be passed as a :string argument (passed as NULL)
100
+ * Structs can now be fields inside another struct
101
+ * Lots of internal cleanups and refactorings.
102
+
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2008-2010 Ruby-FFI contributors
2
+ All rights reserved.
3
+
4
+ This code is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Lesser General Public License version 3 only, as
6
+ published by the Free Software Foundation.
7
+
8
+ This code is distributed in the hope that it will be useful, but WITHOUT
9
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ version 3 for more details.
12
+
13
+ You should have received a copy of the GNU Lesser General Public License
14
+ version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
data/README.rdoc ADDED
@@ -0,0 +1,70 @@
1
+ ruby-ffi
2
+ by Wayne Meissner
3
+ http://wiki.github.com/ffi/ffi
4
+
5
+ == DESCRIPTION:
6
+
7
+ Ruby-FFI is a ruby extension for programmatically loading dynamic
8
+ libraries, binding functions within them, and calling those functions
9
+ from Ruby code. Moreover, a Ruby-FFI extension works without changes
10
+ on Ruby and JRuby. Discover why should you write your next extension
11
+ using Ruby-FFI here[http://wiki.github.com/ffi/ffi/why-use-ffi].
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ * It has a very intuitive DSL
16
+ * It supports all C native types
17
+ * It supports C structs (also nested), enums and global variables
18
+ * It supports callbacks
19
+ * It has smart methods to handle memory management of pointers and structs
20
+
21
+ == SYNOPSIS:
22
+
23
+ require 'ffi'
24
+
25
+ module MyLib
26
+ extend FFI::Library
27
+ ffi_lib 'c'
28
+ attach_function :puts, [ :string ], :int
29
+ end
30
+
31
+ MyLib.puts 'Hello boys using libc!'
32
+
33
+ For less minimalistic and more sane examples you may look at:
34
+
35
+ * the samples/ folder
36
+ * the examples on the wiki[http://wiki.github.com/ffi/ffi]
37
+ * the projects using FFI listed on this page[http://wiki.github.com/ffi/ffi/projects-using-ffi]
38
+
39
+ == REQUIREMENTS:
40
+
41
+ * You need a sane building environment in order to compile the extension.
42
+
43
+ == DOWNLOAD/INSTALL:
44
+
45
+ From rubyforge:
46
+
47
+ [sudo] gem install ffi
48
+
49
+ or from the git repository on github:
50
+
51
+ git clone git://github.com/ffi/ffi.git
52
+ cd ffi
53
+ rake gem:install
54
+
55
+ == CREDITS:
56
+
57
+ Special thanks to:
58
+
59
+ * Yehuda Katz
60
+ * Luc Heinrich
61
+ * Andrea Fazzi
62
+ * Mike Dalessio
63
+ * Hongli Lai
64
+ * Evan Phoenix
65
+ * Aman Gupta
66
+ * Beoran
67
+
68
+ == LICENSE:
69
+
70
+ See LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,189 @@
1
+ require 'rubygems'
2
+ require 'rbconfig'
3
+
4
+ USE_RAKE_COMPILER = (RUBY_PLATFORM =~ /java/) ? false : true
5
+ if USE_RAKE_COMPILER
6
+ gem 'rake-compiler', '>=0.6.0'
7
+ require 'rake/extensiontask'
8
+ ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
9
+ end
10
+
11
+ require 'date'
12
+ require 'fileutils'
13
+ require 'rbconfig'
14
+
15
+ load 'tasks/setup.rb'
16
+
17
+ LIBEXT = case Config::CONFIG['host_os'].downcase
18
+ when /darwin/
19
+ "dylib"
20
+ when /mswin|mingw/
21
+ "dll"
22
+ else
23
+ Config::CONFIG['DLEXT']
24
+ end
25
+
26
+ CPU = case Config::CONFIG['host_cpu'].downcase
27
+ when /i[3456]86/
28
+ # Darwin always reports i686, even when running in 64bit mode
29
+ if Config::CONFIG['host_os'] =~ /darwin/ && 0xfee1deadbeef.is_a?(Fixnum)
30
+ "x86_64"
31
+ else
32
+ "i386"
33
+ end
34
+
35
+ when /amd64|x86_64/
36
+ "x86_64"
37
+
38
+ when /ppc64|powerpc64/
39
+ "powerpc64"
40
+
41
+ when /ppc|powerpc/
42
+ "powerpc"
43
+
44
+ else
45
+ Config::CONFIG['host_cpu']
46
+ end
47
+
48
+ OS = case Config::CONFIG['host_os'].downcase
49
+ when /linux/
50
+ "linux"
51
+ when /darwin/
52
+ "darwin"
53
+ when /freebsd/
54
+ "freebsd"
55
+ when /openbsd/
56
+ "openbsd"
57
+ when /sunos|solaris/
58
+ "solaris"
59
+ when /mswin|mingw/
60
+ "win32"
61
+ else
62
+ Config::CONFIG['host_os'].downcase
63
+ end
64
+
65
+ CC=ENV['CC'] || Config::CONFIG['CC'] || "gcc"
66
+
67
+ GMAKE = Config::CONFIG['host_os'].downcase =~ /bsd|solaris/ ? "gmake" : "make"
68
+
69
+ LIBTEST = "build/libtest.#{LIBEXT}"
70
+ BUILD_DIR = "build"
71
+ BUILD_EXT_DIR = File.join(BUILD_DIR, "#{Config::CONFIG['arch']}", 'ffi_c', RUBY_VERSION)
72
+
73
+ # Project general information
74
+ PROJ.name = 'ffi-aitrus'
75
+ PROJ.authors = 'Wayne Meissner'
76
+ PROJ.email = 'wmeissner@gmail.com'
77
+ PROJ.url = 'http://wiki.github.com/ffi/ffi'
78
+ PROJ.version = '0.9.0.beta'
79
+ PROJ.rubyforge.name = 'ffi-aitrus'
80
+ PROJ.readme_file = 'README.rdoc'
81
+
82
+ # Annoucement
83
+ PROJ.ann.paragraphs << 'FEATURES' << 'SYNOPSIS' << 'REQUIREMENTS' << 'DOWNLOAD/INSTALL' << 'CREDITS' << 'LICENSE'
84
+
85
+ PROJ.ann.email[:from] = 'andrea.fazzi@alcacoop.it'
86
+ PROJ.ann.email[:to] = ['ruby-ffi@googlegroups.com']
87
+ PROJ.ann.email[:server] = 'smtp.gmail.com'
88
+
89
+ # Gem specifications
90
+ PROJ.gem.need_tar = false
91
+ PROJ.gem.files = %w(History.txt LICENSE README.rdoc Rakefile) + Dir.glob("{ext,gen,lib,spec,tasks}/**/*")
92
+ PROJ.gem.platform = Gem::Platform::RUBY
93
+
94
+ # Override Mr. Bones autogenerated extensions and force ours in
95
+ PROJ.gem.extras['extensions'] = %w(ext/ffi_c/extconf.rb gen/Rakefile)
96
+
97
+ # RDoc
98
+ PROJ.rdoc.exclude << '^ext\/'
99
+ PROJ.rdoc.opts << '-x' << 'ext'
100
+
101
+ # Ruby
102
+ PROJ.ruby_opts = []
103
+ PROJ.ruby_opts << '-I' << BUILD_EXT_DIR unless RUBY_PLATFORM == "java"
104
+
105
+ # RSpec
106
+ PROJ.spec.files.exclude /rbx/
107
+ PROJ.spec.opts << '--color' << '-fs'
108
+
109
+ # Dependencies
110
+
111
+ depend_on 'rake', '>=0.8.7'
112
+
113
+ TEST_DEPS = [ LIBTEST ]
114
+ if RUBY_PLATFORM == "java"
115
+ desc "Run all specs"
116
+ task :specs => TEST_DEPS do
117
+ sh %{#{Gem.ruby} -S spec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
118
+ end
119
+ desc "Run rubinius specs"
120
+ task :rbxspecs => TEST_DEPS do
121
+ sh %{#{Gem.ruby} -S spec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
122
+ end
123
+ else
124
+ TEST_DEPS.unshift :compile
125
+ desc "Run all specs"
126
+ task :specs => TEST_DEPS do
127
+ ENV["MRI_FFI"] = "1"
128
+ sh %{#{Gem.ruby} -Ilib -I#{BUILD_EXT_DIR} -S spec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
129
+ end
130
+ desc "Run rubinius specs"
131
+ task :rbxspecs => TEST_DEPS do
132
+ ENV["MRI_FFI"] = "1"
133
+ sh %{#{Gem.ruby} -Ilib -I#{BUILD_EXT_DIR} -S spec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
134
+ end
135
+ end
136
+
137
+ desc "Build all packages"
138
+ task :package => 'gem:package'
139
+
140
+ desc "Install the gem locally"
141
+ task :install => 'gem:install'
142
+
143
+
144
+ desc "Clean all built files"
145
+ task :distclean => :clobber do
146
+ FileUtils.rm_rf('build')
147
+ FileUtils.rm_rf(Dir["lib/**/ffi_c.#{Config::CONFIG['DLEXT']}"])
148
+ FileUtils.rm_rf('lib/1.8')
149
+ FileUtils.rm_rf('lib/1.9')
150
+ FileUtils.rm_rf('lib/ffi/types.conf')
151
+ FileUtils.rm_rf('conftest.dSYM')
152
+ FileUtils.rm_rf('pkg')
153
+ end
154
+
155
+
156
+ desc "Build the native test lib"
157
+ task "build/libtest.#{LIBEXT}" do
158
+ sh %{#{GMAKE} -f libtest/GNUmakefile CPU=#{CPU} OS=#{OS} }
159
+ end
160
+
161
+
162
+ desc "Build test helper lib"
163
+ task :libtest => "build/libtest.#{LIBEXT}"
164
+
165
+ desc "Test the extension"
166
+ task :test => [ :specs, :rbxspecs ]
167
+
168
+
169
+ namespace :bench do
170
+ ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000
171
+ bench_libs = "-Ilib -I#{BUILD_DIR}" unless RUBY_PLATFORM == "java"
172
+ bench_files = Dir["bench/bench_*.rb"].reject { |f| f == "bench_helper.rb" }
173
+ bench_files.each do |bench|
174
+ task File.basename(bench, ".rb")[6..-1] => TEST_DEPS do
175
+ sh %{#{Gem.ruby} #{bench_libs} #{bench} #{ITER}}
176
+ end
177
+ end
178
+ task :all => TEST_DEPS do
179
+ bench_files.each do |bench|
180
+ sh %{#{Gem.ruby} #{bench_libs} #{bench}}
181
+ end
182
+ end
183
+ end
184
+
185
+ task 'spec:run' => TEST_DEPS
186
+ task 'spec:specdoc' => TEST_DEPS
187
+
188
+ task :default => :specs
189
+
@@ -0,0 +1,510 @@
1
+ /*
2
+ * Copyright (c) 2008, 2009, 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
+ #include <sys/types.h>
22
+ #include <sys/param.h>
23
+ #include <stdint.h>
24
+ #include <stdbool.h>
25
+ #include <limits.h>
26
+ #include <ruby.h>
27
+ #include "rbffi.h"
28
+ #include "compat.h"
29
+ #include "AbstractMemory.h"
30
+ #include "Pointer.h"
31
+ #include "Function.h"
32
+
33
+
34
+ static inline char* memory_address(VALUE self);
35
+ VALUE rbffi_AbstractMemoryClass = Qnil;
36
+ static VALUE NullPointerErrorClass = Qnil;
37
+ static ID id_to_ptr = 0, id_plus = 0, id_call = 0;
38
+
39
+ static VALUE
40
+ memory_allocate(VALUE klass)
41
+ {
42
+ AbstractMemory* memory;
43
+ VALUE obj;
44
+ obj = Data_Make_Struct(klass, AbstractMemory, NULL, -1, memory);
45
+ memory->flags = MEM_RD | MEM_WR;
46
+
47
+ return obj;
48
+ }
49
+ #define VAL(x, swap) (unlikely(((memory->flags & MEM_SWAP) != 0)) ? swap((x)) : (x))
50
+
51
+ #define NUM_OP(name, type, toNative, fromNative, swap) \
52
+ static void memory_op_put_##name(AbstractMemory* memory, long off, VALUE value); \
53
+ static void \
54
+ memory_op_put_##name(AbstractMemory* memory, long off, VALUE value) \
55
+ { \
56
+ type tmp = (type) VAL(toNative(value), swap); \
57
+ checkWrite(memory); \
58
+ checkBounds(memory, off, sizeof(type)); \
59
+ memcpy(memory->address + off, &tmp, sizeof(tmp)); \
60
+ } \
61
+ static VALUE memory_put_##name(VALUE self, VALUE offset, VALUE value); \
62
+ static VALUE \
63
+ memory_put_##name(VALUE self, VALUE offset, VALUE value) \
64
+ { \
65
+ AbstractMemory* memory; \
66
+ Data_Get_Struct(self, AbstractMemory, memory); \
67
+ memory_op_put_##name(memory, NUM2LONG(offset), value); \
68
+ return self; \
69
+ } \
70
+ static VALUE memory_op_get_##name(AbstractMemory* memory, long off); \
71
+ static VALUE \
72
+ memory_op_get_##name(AbstractMemory* memory, long off) \
73
+ { \
74
+ type tmp; \
75
+ checkRead(memory); \
76
+ checkBounds(memory, off, sizeof(type)); \
77
+ memcpy(&tmp, memory->address + off, sizeof(tmp)); \
78
+ return fromNative(VAL(tmp, swap)); \
79
+ } \
80
+ static VALUE memory_get_##name(VALUE self, VALUE offset); \
81
+ static VALUE \
82
+ memory_get_##name(VALUE self, VALUE offset) \
83
+ { \
84
+ AbstractMemory* memory; \
85
+ Data_Get_Struct(self, AbstractMemory, memory); \
86
+ return memory_op_get_##name(memory, NUM2LONG(offset)); \
87
+ } \
88
+ static MemoryOp memory_op_##name = { memory_op_get_##name, memory_op_put_##name }; \
89
+ \
90
+ static VALUE memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary); \
91
+ static VALUE \
92
+ memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \
93
+ { \
94
+ long count = RARRAY_LEN(ary); \
95
+ long off = NUM2LONG(offset); \
96
+ AbstractMemory* memory = MEMORY(self); \
97
+ long i; \
98
+ checkWrite(memory); \
99
+ checkBounds(memory, off, count * sizeof(type)); \
100
+ for (i = 0; i < count; i++) { \
101
+ type tmp = (type) VAL(toNative(RARRAY_PTR(ary)[i]), swap); \
102
+ memcpy(memory->address + off + (i * sizeof(type)), &tmp, sizeof(tmp)); \
103
+ } \
104
+ return self; \
105
+ } \
106
+ static VALUE memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length); \
107
+ static VALUE \
108
+ memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length) \
109
+ { \
110
+ long count = NUM2LONG(length); \
111
+ long off = NUM2LONG(offset); \
112
+ AbstractMemory* memory = MEMORY(self); \
113
+ long i; \
114
+ checkRead(memory); \
115
+ checkBounds(memory, off, count * sizeof(type)); \
116
+ VALUE retVal = rb_ary_new2(count); \
117
+ for (i = 0; i < count; ++i) { \
118
+ type tmp; \
119
+ memcpy(&tmp, memory->address + off + (i * sizeof(type)), sizeof(tmp)); \
120
+ rb_ary_push(retVal, fromNative(VAL(tmp, swap))); \
121
+ } \
122
+ return retVal; \
123
+ }
124
+
125
+ #define NOSWAP(x) (x)
126
+ #define bswap16(x) (((x) >> 8) & 0xff) | (((x) << 8) & 0xff00);
127
+ static inline int16_t
128
+ SWAPS16(int16_t x)
129
+ {
130
+ return bswap16(x);
131
+ }
132
+
133
+ static inline uint16_t
134
+ SWAPU16(uint16_t x)
135
+ {
136
+ return bswap16(x);
137
+ }
138
+
139
+ #define SWAP16(x) (x)
140
+ #define SWAP32(x) __builtin_bswap32(x)
141
+ #define SWAP64(x) __builtin_bswap64(x)
142
+
143
+ #if LONG_MAX > INT_MAX
144
+ # define SWAPLONG SWAP64
145
+ #else
146
+ # define SWAPLONG SWAP32
147
+ #endif
148
+
149
+ NUM_OP(int8, int8_t, NUM2INT, INT2NUM, NOSWAP);
150
+ NUM_OP(uint8, uint8_t, NUM2UINT, UINT2NUM, NOSWAP);
151
+ NUM_OP(int16, int16_t, NUM2INT, INT2NUM, SWAP16);
152
+ NUM_OP(uint16, uint16_t, NUM2UINT, UINT2NUM, SWAP16);
153
+ NUM_OP(int32, int32_t, NUM2INT, INT2NUM, SWAP32);
154
+ NUM_OP(uint32, uint32_t, NUM2UINT, UINT2NUM, SWAP32);
155
+ NUM_OP(int64, int64_t, NUM2LL, LL2NUM, SWAP64);
156
+ NUM_OP(uint64, uint64_t, NUM2ULL, ULL2NUM, SWAP64);
157
+ NUM_OP(long, long, NUM2LONG, LONG2NUM, SWAPLONG);
158
+ NUM_OP(ulong, unsigned long, NUM2ULONG, ULONG2NUM, SWAPLONG);
159
+ NUM_OP(float32, float, NUM2DBL, rb_float_new, NOSWAP);
160
+ NUM_OP(float64, double, NUM2DBL, rb_float_new, NOSWAP);
161
+
162
+ static inline void*
163
+ get_pointer_value(VALUE value)
164
+ {
165
+ const int type = TYPE(value);
166
+ if (type == T_DATA && rb_obj_is_kind_of(value, rbffi_PointerClass)) {
167
+ return memory_address(value);
168
+ } else if (type == T_NIL) {
169
+ return NULL;
170
+ } else if (type == T_FIXNUM) {
171
+ return (void *) (uintptr_t) FIX2INT(value);
172
+ } else if (type == T_BIGNUM) {
173
+ return (void *) (uintptr_t) NUM2ULL(value);
174
+ } else if (rb_respond_to(value, id_to_ptr)) {
175
+ return MEMORY_PTR(rb_funcall2(value, id_to_ptr, 0, NULL));
176
+ } else {
177
+ rb_raise(rb_eArgError, "value is not a pointer");
178
+ return NULL;
179
+ }
180
+ }
181
+
182
+ NUM_OP(pointer, void *, get_pointer_value, rbffi_Pointer_NewInstance, NOSWAP);
183
+
184
+ static VALUE
185
+ memory_clear(VALUE self)
186
+ {
187
+ AbstractMemory* ptr = MEMORY(self);
188
+ memset(ptr->address, 0, ptr->size);
189
+ return self;
190
+ }
191
+
192
+ static VALUE
193
+ memory_size(VALUE self)
194
+ {
195
+ AbstractMemory* ptr;
196
+
197
+ Data_Get_Struct(self, AbstractMemory, ptr);
198
+
199
+ return LONG2NUM(ptr->size);
200
+ }
201
+
202
+ static VALUE
203
+ memory_get_string(int argc, VALUE* argv, VALUE self)
204
+ {
205
+ VALUE length = Qnil, offset = Qnil;
206
+ AbstractMemory* ptr = MEMORY(self);
207
+ long off, len;
208
+ char* end;
209
+ int nargs = rb_scan_args(argc, argv, "11", &offset, &length);
210
+
211
+ off = NUM2LONG(offset);
212
+ len = nargs > 1 && length != Qnil ? NUM2LONG(length) : (ptr->size - off);
213
+ checkRead(ptr);
214
+ checkBounds(ptr, off, len);
215
+
216
+ end = memchr(ptr->address + off, 0, len);
217
+ return rb_tainted_str_new((char *) ptr->address + off,
218
+ (end != NULL ? end - ptr->address - off : len));
219
+ }
220
+
221
+ static VALUE
222
+ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
223
+ {
224
+ VALUE offset = Qnil, countnum = Qnil, retVal = Qnil;
225
+ AbstractMemory* ptr;
226
+ long off;
227
+ int count;
228
+
229
+ rb_scan_args(argc, argv, "11", &offset, &countnum);
230
+ off = NUM2LONG(offset);
231
+ count = (countnum == Qnil ? 0 : NUM2INT(countnum));
232
+ retVal = rb_ary_new2(count);
233
+
234
+ Data_Get_Struct(self, AbstractMemory, ptr);
235
+ checkRead(ptr);
236
+
237
+ if (countnum != Qnil) {
238
+ int i;
239
+
240
+ checkBounds(ptr, off, count * sizeof (char*));
241
+
242
+ for (i = 0; i < count; ++i) {
243
+ const char* strptr = *((const char**) (ptr->address + off) + i);
244
+ rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_tainted_str_new2(strptr)));
245
+ }
246
+
247
+ } else {
248
+ checkBounds(ptr, off, sizeof (char*));
249
+ for ( ; off < ptr->size - (long) sizeof (void *); off += (long) sizeof (void *)) {
250
+ const char* strptr = *(const char**) (ptr->address + off);
251
+ if (strptr == NULL) {
252
+ break;
253
+ }
254
+ rb_ary_push(retVal, rb_tainted_str_new2(strptr));
255
+ }
256
+ }
257
+
258
+ return retVal;
259
+ }
260
+
261
+ static VALUE
262
+ memory_put_string(VALUE self, VALUE offset, VALUE str)
263
+ {
264
+ AbstractMemory* ptr = MEMORY(self);
265
+ long off, len;
266
+
267
+ Check_Type(str, T_STRING);
268
+ off = NUM2LONG(offset);
269
+ len = RSTRING_LEN(str);
270
+
271
+ checkWrite(ptr);
272
+ checkBounds(ptr, off, len + 1);
273
+
274
+ if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
275
+ rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
276
+ return Qnil;
277
+ }
278
+
279
+ memcpy(ptr->address + off, RSTRING_PTR(str), len);
280
+ *((char *) ptr->address + off + len) = '\0';
281
+
282
+ return self;
283
+ }
284
+
285
+ static VALUE
286
+ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
287
+ {
288
+ AbstractMemory* ptr = MEMORY(self);
289
+ long off, len;
290
+
291
+ off = NUM2LONG(offset);
292
+ len = NUM2LONG(length);
293
+
294
+ checkRead(ptr);
295
+ checkBounds(ptr, off, len);
296
+
297
+ return rb_tainted_str_new((char *) ptr->address + off, len);
298
+ }
299
+
300
+ static VALUE
301
+ memory_put_bytes(int argc, VALUE* argv, VALUE self)
302
+ {
303
+ AbstractMemory* ptr = MEMORY(self);
304
+ VALUE offset = Qnil, str = Qnil, rbIndex = Qnil, rbLength = Qnil;
305
+ long off, len, idx;
306
+ int nargs = rb_scan_args(argc, argv, "22", &offset, &str, &rbIndex, &rbLength);
307
+
308
+ Check_Type(str, T_STRING);
309
+
310
+ off = NUM2LONG(offset);
311
+ idx = nargs > 2 ? NUM2LONG(rbIndex) : 0;
312
+ if (idx < 0) {
313
+ rb_raise(rb_eRangeError, "index canot be less than zero");
314
+ return Qnil;
315
+ }
316
+ len = nargs > 3 ? NUM2LONG(rbLength) : (RSTRING_LEN(str) - idx);
317
+ if ((idx + len) > RSTRING_LEN(str)) {
318
+ rb_raise(rb_eRangeError, "index+length is greater than size of string");
319
+ return Qnil;
320
+ }
321
+
322
+ checkWrite(ptr);
323
+ checkBounds(ptr, off, len);
324
+
325
+ if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
326
+ rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
327
+ return Qnil;
328
+ }
329
+ memcpy(ptr->address + off, RSTRING_PTR(str) + idx, len);
330
+
331
+ return self;
332
+ }
333
+
334
+ static VALUE
335
+ memory_type_size(VALUE self)
336
+ {
337
+ AbstractMemory* ptr;
338
+
339
+ Data_Get_Struct(self, AbstractMemory, ptr);
340
+
341
+ return INT2NUM(ptr->typeSize);
342
+ }
343
+
344
+ static VALUE
345
+ memory_aref(VALUE self, VALUE idx)
346
+ {
347
+ AbstractMemory* ptr;
348
+ VALUE rbOffset = Qnil;
349
+
350
+ Data_Get_Struct(self, AbstractMemory, ptr);
351
+
352
+ rbOffset = ULONG2NUM(NUM2ULONG(idx) * ptr->typeSize);
353
+
354
+ return rb_funcall2(self, id_plus, 1, &rbOffset);
355
+ }
356
+
357
+ static inline char*
358
+ memory_address(VALUE obj)
359
+ {
360
+ return ((AbstractMemory *) DATA_PTR(obj))->address;
361
+ }
362
+
363
+ AbstractMemory*
364
+ rbffi_AbstractMemory_Cast(VALUE obj, VALUE klass)
365
+ {
366
+ if (rb_obj_is_kind_of(obj, klass)) {
367
+ AbstractMemory* memory;
368
+ Data_Get_Struct(obj, AbstractMemory, memory);
369
+ return memory;
370
+ }
371
+
372
+ rb_raise(rb_eArgError, "Invalid Memory object");
373
+ return NULL;
374
+ }
375
+
376
+ void
377
+ rbffi_AbstractMemory_Error(AbstractMemory *mem, int op)
378
+ {
379
+ VALUE rbErrorClass = mem->address == NULL ? NullPointerErrorClass : rb_eRuntimeError;
380
+ if (op == MEM_RD) {
381
+ rb_raise(rbErrorClass, "invalid memory read at address=%p", mem->address);
382
+ } else if (op == MEM_WR) {
383
+ rb_raise(rbErrorClass, "invalid memory write at address=%p", mem->address);
384
+ } else {
385
+ rb_raise(rbErrorClass, "invalid memory access at address=%p", mem->address);
386
+ }
387
+ }
388
+
389
+ static VALUE
390
+ memory_op_get_strptr(AbstractMemory* ptr, long offset)
391
+ {
392
+ void* tmp = NULL;
393
+
394
+ if (ptr != NULL && ptr->address != NULL) {
395
+ checkRead(ptr);
396
+ checkBounds(ptr, offset, sizeof(tmp));
397
+ memcpy(&tmp, ptr->address + offset, sizeof(tmp));
398
+ }
399
+
400
+ return tmp != NULL ? rb_tainted_str_new2(tmp) : Qnil;
401
+ }
402
+
403
+ static void
404
+ memory_op_put_strptr(AbstractMemory* ptr, long offset, VALUE value)
405
+ {
406
+ rb_raise(rb_eArgError, "Cannot set :string fields");
407
+ }
408
+
409
+ static MemoryOp memory_op_strptr = { memory_op_get_strptr, memory_op_put_strptr };
410
+
411
+ //static MemoryOp memory_op_pointer = { memory_op_get_pointer, memory_op_put_pointer };
412
+
413
+ MemoryOps rbffi_AbstractMemoryOps = {
414
+ .int8 = &memory_op_int8,
415
+ .uint8 = &memory_op_uint8,
416
+ .int16 = &memory_op_int16,
417
+ .uint16 = &memory_op_uint16,
418
+ .int32 = &memory_op_int32,
419
+ .uint32 = &memory_op_uint32,
420
+ .int64 = &memory_op_int64,
421
+ .uint64 = &memory_op_uint64,
422
+ .slong = &memory_op_long,
423
+ .ulong = &memory_op_ulong,
424
+ .float32 = &memory_op_float32,
425
+ .float64 = &memory_op_float64,
426
+ .pointer = &memory_op_pointer,
427
+ .strptr = &memory_op_strptr,
428
+ };
429
+
430
+ void
431
+ rbffi_AbstractMemory_Init(VALUE moduleFFI)
432
+ {
433
+ VALUE classMemory = rb_define_class_under(moduleFFI, "AbstractMemory", rb_cObject);
434
+ rbffi_AbstractMemoryClass = classMemory;
435
+ rb_global_variable(&rbffi_AbstractMemoryClass);
436
+ rb_define_alloc_func(classMemory, memory_allocate);
437
+
438
+ NullPointerErrorClass = rb_define_class_under(moduleFFI, "NullPointerError", rb_eRuntimeError);
439
+ rb_global_variable(&NullPointerErrorClass);
440
+
441
+
442
+ #undef INT
443
+ #define INT(type) \
444
+ rb_define_method(classMemory, "put_" #type, memory_put_##type, 2); \
445
+ rb_define_method(classMemory, "get_" #type, memory_get_##type, 1); \
446
+ rb_define_method(classMemory, "put_u" #type, memory_put_u##type, 2); \
447
+ rb_define_method(classMemory, "get_u" #type, memory_get_u##type, 1); \
448
+ rb_define_method(classMemory, "put_array_of_" #type, memory_put_array_of_##type, 2); \
449
+ rb_define_method(classMemory, "get_array_of_" #type, memory_get_array_of_##type, 2); \
450
+ rb_define_method(classMemory, "put_array_of_u" #type, memory_put_array_of_u##type, 2); \
451
+ rb_define_method(classMemory, "get_array_of_u" #type, memory_get_array_of_u##type, 2);
452
+
453
+ INT(int8);
454
+ INT(int16);
455
+ INT(int32);
456
+ INT(int64);
457
+ INT(long);
458
+
459
+ #define ALIAS(name, old) \
460
+ rb_define_alias(classMemory, "put_" #name, "put_" #old); \
461
+ rb_define_alias(classMemory, "get_" #name, "get_" #old); \
462
+ rb_define_alias(classMemory, "put_u" #name, "put_u" #old); \
463
+ rb_define_alias(classMemory, "get_u" #name, "get_u" #old); \
464
+ rb_define_alias(classMemory, "put_array_of_" #name, "put_array_of_" #old); \
465
+ rb_define_alias(classMemory, "get_array_of_" #name, "get_array_of_" #old); \
466
+ rb_define_alias(classMemory, "put_array_of_u" #name, "put_array_of_u" #old); \
467
+ rb_define_alias(classMemory, "get_array_of_u" #name, "get_array_of_u" #old);
468
+
469
+ ALIAS(char, int8);
470
+ ALIAS(short, int16);
471
+ ALIAS(int, int32);
472
+ ALIAS(long_long, int64);
473
+
474
+ rb_define_method(classMemory, "put_float32", memory_put_float32, 2);
475
+ rb_define_method(classMemory, "get_float32", memory_get_float32, 1);
476
+ rb_define_alias(classMemory, "put_float", "put_float32");
477
+ rb_define_alias(classMemory, "get_float", "get_float32");
478
+ rb_define_method(classMemory, "put_array_of_float32", memory_put_array_of_float32, 2);
479
+ rb_define_method(classMemory, "get_array_of_float32", memory_get_array_of_float32, 2);
480
+ rb_define_alias(classMemory, "put_array_of_float", "put_array_of_float32");
481
+ rb_define_alias(classMemory, "get_array_of_float", "get_array_of_float32");
482
+ rb_define_method(classMemory, "put_float64", memory_put_float64, 2);
483
+ rb_define_method(classMemory, "get_float64", memory_get_float64, 1);
484
+ rb_define_alias(classMemory, "put_double", "put_float64");
485
+ rb_define_alias(classMemory, "get_double", "get_float64");
486
+ rb_define_method(classMemory, "put_array_of_float64", memory_put_array_of_float64, 2);
487
+ rb_define_method(classMemory, "get_array_of_float64", memory_get_array_of_float64, 2);
488
+ rb_define_alias(classMemory, "put_array_of_double", "put_array_of_float64");
489
+ rb_define_alias(classMemory, "get_array_of_double", "get_array_of_float64");
490
+ rb_define_method(classMemory, "put_pointer", memory_put_pointer, 2);
491
+ rb_define_method(classMemory, "get_pointer", memory_get_pointer, 1);
492
+ rb_define_method(classMemory, "put_array_of_pointer", memory_put_array_of_pointer, 2);
493
+ rb_define_method(classMemory, "get_array_of_pointer", memory_get_array_of_pointer, 2);
494
+ rb_define_method(classMemory, "get_string", memory_get_string, -1);
495
+ rb_define_method(classMemory, "put_string", memory_put_string, 2);
496
+ rb_define_method(classMemory, "get_bytes", memory_get_bytes, 2);
497
+ rb_define_method(classMemory, "put_bytes", memory_put_bytes, -1);
498
+ rb_define_method(classMemory, "get_array_of_string", memory_get_array_of_string, -1);
499
+
500
+ rb_define_method(classMemory, "clear", memory_clear, 0);
501
+ rb_define_method(classMemory, "total", memory_size, 0);
502
+ rb_define_alias(classMemory, "size", "total");
503
+ rb_define_method(classMemory, "type_size", memory_type_size, 0);
504
+ rb_define_method(classMemory, "[]", memory_aref, 1);
505
+
506
+ id_to_ptr = rb_intern("to_ptr");
507
+ id_call = rb_intern("call");
508
+ id_plus = rb_intern("+");
509
+ }
510
+