ffi 1.10.0

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.
Files changed (530) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +43 -0
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +98 -0
  7. data/COPYING +49 -0
  8. data/Gemfile +15 -0
  9. data/LICENSE +24 -0
  10. data/LICENSE.SPECS +22 -0
  11. data/README.md +112 -0
  12. data/Rakefile +268 -0
  13. data/appveyor.yml +22 -0
  14. data/ext/ffi_c/AbstractMemory.c +1109 -0
  15. data/ext/ffi_c/AbstractMemory.h +175 -0
  16. data/ext/ffi_c/ArrayType.c +162 -0
  17. data/ext/ffi_c/ArrayType.h +59 -0
  18. data/ext/ffi_c/Buffer.c +365 -0
  19. data/ext/ffi_c/Call.c +520 -0
  20. data/ext/ffi_c/Call.h +110 -0
  21. data/ext/ffi_c/ClosurePool.c +283 -0
  22. data/ext/ffi_c/ClosurePool.h +57 -0
  23. data/ext/ffi_c/DataConverter.c +91 -0
  24. data/ext/ffi_c/DynamicLibrary.c +339 -0
  25. data/ext/ffi_c/DynamicLibrary.h +98 -0
  26. data/ext/ffi_c/Function.c +1001 -0
  27. data/ext/ffi_c/Function.h +87 -0
  28. data/ext/ffi_c/FunctionInfo.c +271 -0
  29. data/ext/ffi_c/LastError.c +229 -0
  30. data/ext/ffi_c/LastError.h +47 -0
  31. data/ext/ffi_c/LongDouble.c +63 -0
  32. data/ext/ffi_c/LongDouble.h +51 -0
  33. data/ext/ffi_c/MappedType.c +168 -0
  34. data/ext/ffi_c/MappedType.h +59 -0
  35. data/ext/ffi_c/MemoryPointer.c +197 -0
  36. data/ext/ffi_c/MemoryPointer.h +53 -0
  37. data/ext/ffi_c/MethodHandle.c +358 -0
  38. data/ext/ffi_c/MethodHandle.h +55 -0
  39. data/ext/ffi_c/Platform.c +129 -0
  40. data/ext/ffi_c/Platform.h +45 -0
  41. data/ext/ffi_c/Pointer.c +508 -0
  42. data/ext/ffi_c/Pointer.h +63 -0
  43. data/ext/ffi_c/Struct.c +829 -0
  44. data/ext/ffi_c/Struct.h +106 -0
  45. data/ext/ffi_c/StructByReference.c +190 -0
  46. data/ext/ffi_c/StructByReference.h +50 -0
  47. data/ext/ffi_c/StructByValue.c +150 -0
  48. data/ext/ffi_c/StructByValue.h +55 -0
  49. data/ext/ffi_c/StructLayout.c +698 -0
  50. data/ext/ffi_c/Thread.c +353 -0
  51. data/ext/ffi_c/Thread.h +95 -0
  52. data/ext/ffi_c/Type.c +397 -0
  53. data/ext/ffi_c/Type.h +62 -0
  54. data/ext/ffi_c/Types.c +139 -0
  55. data/ext/ffi_c/Types.h +89 -0
  56. data/ext/ffi_c/Variadic.c +304 -0
  57. data/ext/ffi_c/compat.h +78 -0
  58. data/ext/ffi_c/extconf.rb +72 -0
  59. data/ext/ffi_c/ffi.c +98 -0
  60. data/ext/ffi_c/libffi.bsd.mk +40 -0
  61. data/ext/ffi_c/libffi.darwin.mk +105 -0
  62. data/ext/ffi_c/libffi.gnu.mk +32 -0
  63. data/ext/ffi_c/libffi.mk +18 -0
  64. data/ext/ffi_c/libffi.vc.mk +26 -0
  65. data/ext/ffi_c/libffi.vc64.mk +26 -0
  66. data/ext/ffi_c/libffi/.appveyor.yml +50 -0
  67. data/ext/ffi_c/libffi/.github/issue_template.md +10 -0
  68. data/ext/ffi_c/libffi/.gitignore +38 -0
  69. data/ext/ffi_c/libffi/.travis.yml +34 -0
  70. data/ext/ffi_c/libffi/.travis/ar-lib +270 -0
  71. data/ext/ffi_c/libffi/.travis/build.sh +34 -0
  72. data/ext/ffi_c/libffi/.travis/compile +351 -0
  73. data/ext/ffi_c/libffi/.travis/install.sh +22 -0
  74. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +60 -0
  75. data/ext/ffi_c/libffi/.travis/site.exp +18 -0
  76. data/ext/ffi_c/libffi/ChangeLog.libffi +584 -0
  77. data/ext/ffi_c/libffi/ChangeLog.libffi-3.1 +6000 -0
  78. data/ext/ffi_c/libffi/ChangeLog.libgcj +40 -0
  79. data/ext/ffi_c/libffi/ChangeLog.v1 +764 -0
  80. data/ext/ffi_c/libffi/LICENSE +21 -0
  81. data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +352 -0
  82. data/ext/ffi_c/libffi/Makefile.am +166 -0
  83. data/ext/ffi_c/libffi/README.md +461 -0
  84. data/ext/ffi_c/libffi/acinclude.m4 +479 -0
  85. data/ext/ffi_c/libffi/autogen.sh +2 -0
  86. data/ext/ffi_c/libffi/config.guess +1466 -0
  87. data/ext/ffi_c/libffi/config.sub +1836 -0
  88. data/ext/ffi_c/libffi/configure.ac +390 -0
  89. data/ext/ffi_c/libffi/configure.host +289 -0
  90. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +203 -0
  91. data/ext/ffi_c/libffi/include/Makefile.am +9 -0
  92. data/ext/ffi_c/libffi/include/ffi.h.in +511 -0
  93. data/ext/ffi_c/libffi/include/ffi_cfi.h +55 -0
  94. data/ext/ffi_c/libffi/include/ffi_common.h +149 -0
  95. data/ext/ffi_c/libffi/libffi.map.in +80 -0
  96. data/ext/ffi_c/libffi/libffi.pc.in +11 -0
  97. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +1043 -0
  98. data/ext/ffi_c/libffi/libtool-version +29 -0
  99. data/ext/ffi_c/libffi/m4/asmcfi.m4 +13 -0
  100. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +71 -0
  101. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +194 -0
  102. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +122 -0
  103. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +74 -0
  104. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +87 -0
  105. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
  106. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +302 -0
  107. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +263 -0
  108. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +89 -0
  109. data/ext/ffi_c/libffi/m4/ax_require_defined.m4 +37 -0
  110. data/ext/ffi_c/libffi/man/Makefile.am +8 -0
  111. data/ext/ffi_c/libffi/man/ffi.3 +41 -0
  112. data/ext/ffi_c/libffi/man/ffi_call.3 +103 -0
  113. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +68 -0
  114. data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +73 -0
  115. data/ext/ffi_c/libffi/msvcc.sh +328 -0
  116. data/ext/ffi_c/libffi/src/aarch64/ffi.c +941 -0
  117. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +81 -0
  118. data/ext/ffi_c/libffi/src/aarch64/internal.h +67 -0
  119. data/ext/ffi_c/libffi/src/aarch64/sysv.S +438 -0
  120. data/ext/ffi_c/libffi/src/alpha/ffi.c +521 -0
  121. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +57 -0
  122. data/ext/ffi_c/libffi/src/alpha/internal.h +23 -0
  123. data/ext/ffi_c/libffi/src/alpha/osf.S +282 -0
  124. data/ext/ffi_c/libffi/src/arc/arcompact.S +135 -0
  125. data/ext/ffi_c/libffi/src/arc/ffi.c +266 -0
  126. data/ext/ffi_c/libffi/src/arc/ffitarget.h +53 -0
  127. data/ext/ffi_c/libffi/src/arm/ffi.c +819 -0
  128. data/ext/ffi_c/libffi/src/arm/ffitarget.h +82 -0
  129. data/ext/ffi_c/libffi/src/arm/internal.h +7 -0
  130. data/ext/ffi_c/libffi/src/arm/sysv.S +383 -0
  131. data/ext/ffi_c/libffi/src/avr32/ffi.c +423 -0
  132. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +55 -0
  133. data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
  134. data/ext/ffi_c/libffi/src/bfin/ffi.c +196 -0
  135. data/ext/ffi_c/libffi/src/bfin/ffitarget.h +43 -0
  136. data/ext/ffi_c/libffi/src/bfin/sysv.S +179 -0
  137. data/ext/ffi_c/libffi/src/closures.c +966 -0
  138. data/ext/ffi_c/libffi/src/cris/ffi.c +386 -0
  139. data/ext/ffi_c/libffi/src/cris/ffitarget.h +56 -0
  140. data/ext/ffi_c/libffi/src/cris/sysv.S +215 -0
  141. data/ext/ffi_c/libffi/src/debug.c +64 -0
  142. data/ext/ffi_c/libffi/src/dlmalloc.c +5166 -0
  143. data/ext/ffi_c/libffi/src/frv/eabi.S +128 -0
  144. data/ext/ffi_c/libffi/src/frv/ffi.c +292 -0
  145. data/ext/ffi_c/libffi/src/frv/ffitarget.h +62 -0
  146. data/ext/ffi_c/libffi/src/ia64/ffi.c +604 -0
  147. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +56 -0
  148. data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +40 -0
  149. data/ext/ffi_c/libffi/src/ia64/unix.S +567 -0
  150. data/ext/ffi_c/libffi/src/java_raw_api.c +374 -0
  151. data/ext/ffi_c/libffi/src/m32r/ffi.c +232 -0
  152. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +53 -0
  153. data/ext/ffi_c/libffi/src/m32r/sysv.S +121 -0
  154. data/ext/ffi_c/libffi/src/m68k/ffi.c +362 -0
  155. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +54 -0
  156. data/ext/ffi_c/libffi/src/m68k/sysv.S +357 -0
  157. data/ext/ffi_c/libffi/src/m88k/ffi.c +400 -0
  158. data/ext/ffi_c/libffi/src/m88k/ffitarget.h +49 -0
  159. data/ext/ffi_c/libffi/src/m88k/obsd.S +209 -0
  160. data/ext/ffi_c/libffi/src/metag/ffi.c +330 -0
  161. data/ext/ffi_c/libffi/src/metag/ffitarget.h +53 -0
  162. data/ext/ffi_c/libffi/src/metag/sysv.S +311 -0
  163. data/ext/ffi_c/libffi/src/microblaze/ffi.c +321 -0
  164. data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +53 -0
  165. data/ext/ffi_c/libffi/src/microblaze/sysv.S +302 -0
  166. data/ext/ffi_c/libffi/src/mips/ffi.c +1130 -0
  167. data/ext/ffi_c/libffi/src/mips/ffitarget.h +244 -0
  168. data/ext/ffi_c/libffi/src/mips/n32.S +663 -0
  169. data/ext/ffi_c/libffi/src/mips/o32.S +502 -0
  170. data/ext/ffi_c/libffi/src/moxie/eabi.S +101 -0
  171. data/ext/ffi_c/libffi/src/moxie/ffi.c +285 -0
  172. data/ext/ffi_c/libffi/src/moxie/ffitarget.h +52 -0
  173. data/ext/ffi_c/libffi/src/nios2/ffi.c +304 -0
  174. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +52 -0
  175. data/ext/ffi_c/libffi/src/nios2/sysv.S +136 -0
  176. data/ext/ffi_c/libffi/src/or1k/ffi.c +328 -0
  177. data/ext/ffi_c/libffi/src/or1k/ffitarget.h +58 -0
  178. data/ext/ffi_c/libffi/src/or1k/sysv.S +107 -0
  179. data/ext/ffi_c/libffi/src/pa/ffi.c +719 -0
  180. data/ext/ffi_c/libffi/src/pa/ffitarget.h +85 -0
  181. data/ext/ffi_c/libffi/src/pa/hpux32.S +368 -0
  182. data/ext/ffi_c/libffi/src/pa/linux.S +357 -0
  183. data/ext/ffi_c/libffi/src/powerpc/aix.S +566 -0
  184. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +694 -0
  185. data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
  186. data/ext/ffi_c/libffi/src/powerpc/darwin.S +378 -0
  187. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +571 -0
  188. data/ext/ffi_c/libffi/src/powerpc/ffi.c +173 -0
  189. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +1440 -0
  190. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +974 -0
  191. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +94 -0
  192. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +923 -0
  193. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +198 -0
  194. data/ext/ffi_c/libffi/src/powerpc/linux64.S +228 -0
  195. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +488 -0
  196. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +397 -0
  197. data/ext/ffi_c/libffi/src/powerpc/sysv.S +175 -0
  198. data/ext/ffi_c/libffi/src/prep_cif.c +261 -0
  199. data/ext/ffi_c/libffi/src/raw_api.c +267 -0
  200. data/ext/ffi_c/libffi/src/riscv/ffi.c +445 -0
  201. data/ext/ffi_c/libffi/src/riscv/ffitarget.h +68 -0
  202. data/ext/ffi_c/libffi/src/riscv/sysv.S +214 -0
  203. data/ext/ffi_c/libffi/src/s390/ffi.c +756 -0
  204. data/ext/ffi_c/libffi/src/s390/ffitarget.h +70 -0
  205. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  206. data/ext/ffi_c/libffi/src/s390/sysv.S +325 -0
  207. data/ext/ffi_c/libffi/src/sh/ffi.c +717 -0
  208. data/ext/ffi_c/libffi/src/sh/ffitarget.h +54 -0
  209. data/ext/ffi_c/libffi/src/sh/sysv.S +850 -0
  210. data/ext/ffi_c/libffi/src/sh64/ffi.c +469 -0
  211. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +58 -0
  212. data/ext/ffi_c/libffi/src/sh64/sysv.S +539 -0
  213. data/ext/ffi_c/libffi/src/sparc/ffi.c +468 -0
  214. data/ext/ffi_c/libffi/src/sparc/ffi64.c +608 -0
  215. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +81 -0
  216. data/ext/ffi_c/libffi/src/sparc/internal.h +26 -0
  217. data/ext/ffi_c/libffi/src/sparc/v8.S +443 -0
  218. data/ext/ffi_c/libffi/src/sparc/v9.S +440 -0
  219. data/ext/ffi_c/libffi/src/tile/ffi.c +355 -0
  220. data/ext/ffi_c/libffi/src/tile/ffitarget.h +65 -0
  221. data/ext/ffi_c/libffi/src/tile/tile.S +360 -0
  222. data/ext/ffi_c/libffi/src/types.c +108 -0
  223. data/ext/ffi_c/libffi/src/vax/elfbsd.S +195 -0
  224. data/ext/ffi_c/libffi/src/vax/ffi.c +276 -0
  225. data/ext/ffi_c/libffi/src/vax/ffitarget.h +49 -0
  226. data/ext/ffi_c/libffi/src/x86/asmnames.h +30 -0
  227. data/ext/ffi_c/libffi/src/x86/ffi.c +753 -0
  228. data/ext/ffi_c/libffi/src/x86/ffi64.c +884 -0
  229. data/ext/ffi_c/libffi/src/x86/ffitarget.h +147 -0
  230. data/ext/ffi_c/libffi/src/x86/ffiw64.c +308 -0
  231. data/ext/ffi_c/libffi/src/x86/internal.h +29 -0
  232. data/ext/ffi_c/libffi/src/x86/internal64.h +22 -0
  233. data/ext/ffi_c/libffi/src/x86/sysv.S +1043 -0
  234. data/ext/ffi_c/libffi/src/x86/unix64.S +525 -0
  235. data/ext/ffi_c/libffi/src/x86/win64.S +232 -0
  236. data/ext/ffi_c/libffi/src/x86/win64_intel.S +237 -0
  237. data/ext/ffi_c/libffi/src/xtensa/ffi.c +298 -0
  238. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +53 -0
  239. data/ext/ffi_c/libffi/src/xtensa/sysv.S +258 -0
  240. data/ext/ffi_c/libffi/stamp-h.in +1 -0
  241. data/ext/ffi_c/libffi/testsuite/Makefile.am +117 -0
  242. data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
  243. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +636 -0
  244. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +283 -0
  245. data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +45 -0
  246. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/Makefile +28 -0
  247. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/README +78 -0
  248. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/alignof.h +50 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +58 -0
  250. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1745 -0
  251. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2885 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +743 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +46 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.call/align_stdcall.c +46 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +43 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +89 -0
  257. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +81 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +81 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +82 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +89 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +92 -0
  262. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +90 -0
  263. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_simple.c +55 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +94 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +95 -0
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +96 -0
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +102 -0
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +89 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +91 -0
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +93 -0
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +113 -0
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +90 -0
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +95 -0
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +90 -0
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +90 -0
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3float.c +95 -0
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +98 -0
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +90 -0
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +109 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +98 -0
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +124 -0
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +113 -0
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +99 -0
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +117 -0
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +97 -0
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +88 -0
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +90 -0
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +91 -0
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +93 -0
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +91 -0
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +92 -0
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +132 -0
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +115 -0
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +95 -0
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +91 -0
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +91 -0
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +92 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +91 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +91 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +93 -0
  302. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
  303. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +43 -0
  304. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +61 -0
  305. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +42 -0
  306. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
  307. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +61 -0
  308. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_args.c +70 -0
  309. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_float_double.c +55 -0
  310. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +74 -0
  311. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +74 -0
  312. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +86 -0
  313. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +91 -0
  314. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +74 -0
  315. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +86 -0
  316. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
  317. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +142 -0
  318. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +44 -0
  319. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +42 -0
  320. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +42 -0
  321. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_struct_va1.c +114 -0
  322. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +42 -0
  323. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar_va.c +44 -0
  324. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +43 -0
  325. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint_va.c +45 -0
  326. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulong_va.c +45 -0
  327. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +47 -0
  328. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +43 -0
  329. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort_va.c +44 -0
  330. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +36 -0
  331. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +26 -0
  332. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +138 -0
  333. data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +59 -0
  334. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +60 -0
  335. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +60 -0
  336. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +74 -0
  337. data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +62 -0
  338. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +107 -0
  339. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +341 -0
  340. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +59 -0
  341. data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +57 -0
  342. data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +70 -0
  343. data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +78 -0
  344. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +52 -0
  345. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +152 -0
  346. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +161 -0
  347. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +134 -0
  348. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct11.c +121 -0
  349. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +110 -0
  350. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +111 -0
  351. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +111 -0
  352. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +112 -0
  353. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +131 -0
  354. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +111 -0
  355. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +131 -0
  356. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +131 -0
  357. data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +46 -0
  358. data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +127 -0
  359. data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +90 -0
  360. data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +59 -0
  361. data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +114 -0
  362. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +36 -0
  363. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +43 -0
  364. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +42 -0
  365. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +35 -0
  366. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +36 -0
  367. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +49 -0
  368. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +42 -0
  369. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +34 -0
  370. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +41 -0
  371. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +43 -0
  372. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +36 -0
  373. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +38 -0
  374. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +38 -0
  375. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +38 -0
  376. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
  377. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
  378. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
  379. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +125 -0
  380. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +44 -0
  381. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +49 -0
  382. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +49 -0
  383. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +55 -0
  384. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +67 -0
  385. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +57 -0
  386. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +67 -0
  387. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +60 -0
  388. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +64 -0
  389. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +66 -0
  390. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +64 -0
  391. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +74 -0
  392. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +81 -0
  393. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +68 -0
  394. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
  395. data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +61 -0
  396. data/ext/ffi_c/libffi/testsuite/libffi.call/unwindtest.cc +117 -0
  397. data/ext/ffi_c/libffi/testsuite/libffi.call/unwindtest_ffi_call.cc +54 -0
  398. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +196 -0
  399. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +121 -0
  400. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +123 -0
  401. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +125 -0
  402. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +91 -0
  403. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +10 -0
  404. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +10 -0
  405. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +10 -0
  406. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +42 -0
  407. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +10 -0
  408. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +10 -0
  409. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +10 -0
  410. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +71 -0
  411. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +10 -0
  412. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +10 -0
  413. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +10 -0
  414. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +80 -0
  415. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +10 -0
  416. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +16 -0
  417. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +10 -0
  418. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.exp +36 -0
  419. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +51 -0
  420. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +7 -0
  421. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +7 -0
  422. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +7 -0
  423. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +10 -0
  424. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +10 -0
  425. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +86 -0
  426. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +10 -0
  427. data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +1 -0
  428. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +78 -0
  429. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +10 -0
  430. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +10 -0
  431. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +10 -0
  432. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +37 -0
  433. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +41 -0
  434. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +10 -0
  435. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +10 -0
  436. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +10 -0
  437. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +44 -0
  438. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +10 -0
  439. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +10 -0
  440. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +10 -0
  441. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +10 -0
  442. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +10 -0
  443. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +10 -0
  444. data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +34 -0
  445. data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +28 -0
  446. data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +1 -0
  447. data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +36 -0
  448. data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +19 -0
  449. data/ext/ffi_c/rbffi.h +57 -0
  450. data/ext/ffi_c/rbffi_endian.h +59 -0
  451. data/ext/ffi_c/win32/stdbool.h +8 -0
  452. data/ext/ffi_c/win32/stdint.h +201 -0
  453. data/ffi.gemspec +36 -0
  454. data/lib/ffi.rb +20 -0
  455. data/lib/ffi/autopointer.rb +203 -0
  456. data/lib/ffi/buffer.rb +4 -0
  457. data/lib/ffi/callback.rb +4 -0
  458. data/lib/ffi/enum.rb +296 -0
  459. data/lib/ffi/errno.rb +43 -0
  460. data/lib/ffi/ffi.rb +44 -0
  461. data/lib/ffi/io.rb +62 -0
  462. data/lib/ffi/library.rb +588 -0
  463. data/lib/ffi/managedstruct.rb +84 -0
  464. data/lib/ffi/memorypointer.rb +1 -0
  465. data/lib/ffi/platform.rb +170 -0
  466. data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
  467. data/lib/ffi/platform/aarch64-freebsd12/types.conf +128 -0
  468. data/lib/ffi/platform/aarch64-linux/types.conf +104 -0
  469. data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
  470. data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
  471. data/lib/ffi/platform/arm-linux/types.conf +104 -0
  472. data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  473. data/lib/ffi/platform/i386-darwin/types.conf +100 -0
  474. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  475. data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
  476. data/lib/ffi/platform/i386-gnu/types.conf +107 -0
  477. data/lib/ffi/platform/i386-linux/types.conf +103 -0
  478. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  479. data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
  480. data/lib/ffi/platform/i386-solaris/types.conf +122 -0
  481. data/lib/ffi/platform/i386-windows/types.conf +105 -0
  482. data/lib/ffi/platform/ia64-linux/types.conf +104 -0
  483. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  484. data/lib/ffi/platform/mips64-linux/types.conf +104 -0
  485. data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
  486. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  487. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +102 -0
  488. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +102 -0
  489. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +104 -0
  490. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +104 -0
  491. data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
  492. data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
  493. data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  494. data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
  495. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  496. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  497. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  498. data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
  499. data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
  500. data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
  501. data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
  502. data/lib/ffi/platform/x86_64-darwin/types.conf +126 -0
  503. data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
  504. data/lib/ffi/platform/x86_64-freebsd12/types.conf +128 -0
  505. data/lib/ffi/platform/x86_64-linux/types.conf +102 -0
  506. data/lib/ffi/platform/x86_64-netbsd/types.conf +128 -0
  507. data/lib/ffi/platform/x86_64-openbsd/types.conf +134 -0
  508. data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
  509. data/lib/ffi/platform/x86_64-windows/types.conf +120 -0
  510. data/lib/ffi/pointer.rb +160 -0
  511. data/lib/ffi/struct.rb +371 -0
  512. data/lib/ffi/struct_layout_builder.rb +227 -0
  513. data/lib/ffi/tools/const_generator.rb +229 -0
  514. data/lib/ffi/tools/generator.rb +60 -0
  515. data/lib/ffi/tools/generator_task.rb +36 -0
  516. data/lib/ffi/tools/struct_generator.rb +194 -0
  517. data/lib/ffi/tools/types_generator.rb +134 -0
  518. data/lib/ffi/types.rb +194 -0
  519. data/lib/ffi/union.rb +43 -0
  520. data/lib/ffi/variadic.rb +78 -0
  521. data/lib/ffi/version.rb +3 -0
  522. data/samples/getlogin.rb +8 -0
  523. data/samples/getpid.rb +8 -0
  524. data/samples/gettimeofday.rb +18 -0
  525. data/samples/hello.rb +7 -0
  526. data/samples/inotify.rb +60 -0
  527. data/samples/pty.rb +76 -0
  528. data/samples/qsort.rb +21 -0
  529. data/samples/sample_helper.rb +6 -0
  530. metadata +658 -0
@@ -0,0 +1,60 @@
1
+ module FFI
2
+
3
+ # @private
4
+ class Generator
5
+
6
+ def initialize(ffi_name, rb_name, options = {})
7
+ @ffi_name = ffi_name
8
+ @rb_name = rb_name
9
+ @options = options
10
+ @name = File.basename rb_name, '.rb'
11
+
12
+ file = File.read @ffi_name
13
+
14
+ new_file = file.gsub(/^( *)@@@(.*?)@@@/m) do
15
+ @constants = []
16
+ @structs = []
17
+
18
+ indent = $1
19
+ original_lines = $2.count "\n"
20
+
21
+ instance_eval $2, @ffi_name, $`.count("\n")
22
+
23
+ new_lines = []
24
+ @constants.each { |c| new_lines << c.to_ruby }
25
+ @structs.each { |s| new_lines << s.generate_layout }
26
+
27
+ new_lines = new_lines.join("\n").split "\n" # expand multiline blocks
28
+ new_lines = new_lines.map { |line| indent + line }
29
+
30
+ padding = original_lines - new_lines.length
31
+ new_lines += [nil] * padding if padding >= 0
32
+
33
+ new_lines.join "\n"
34
+ end
35
+
36
+ open @rb_name, 'w' do |f|
37
+ f.puts "# This file is generated by rake. Do not edit."
38
+ f.puts
39
+ f.puts new_file
40
+ end
41
+ end
42
+
43
+ def constants(options = {}, &block)
44
+ @constants << FFI::ConstGenerator.new(@name, @options.merge(options), &block)
45
+ end
46
+
47
+ def struct(options = {}, &block)
48
+ @structs << FFI::StructGenerator.new(@name, @options.merge(options), &block)
49
+ end
50
+
51
+ ##
52
+ # Utility converter for constants
53
+
54
+ def to_s
55
+ proc { |obj| obj.to_s.inspect }
56
+ end
57
+
58
+ end
59
+ end
60
+
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'ffi/struct_generator'
3
+ require 'ffi/const_generator'
4
+ require 'ffi/generator'
5
+ rescue LoadError
6
+ # from Rakefile
7
+ require 'lib/ffi/struct_generator'
8
+ require 'lib/ffi/const_generator'
9
+ require 'lib/ffi/generator'
10
+ end
11
+
12
+ require 'rake'
13
+ require 'rake/tasklib'
14
+ require 'tempfile'
15
+
16
+ ##
17
+ # Rake task that calculates C structs for FFI::Struct.
18
+
19
+ # @private
20
+ class FFI::Generator::Task < Rake::TaskLib
21
+
22
+ def initialize(rb_names)
23
+ task :clean do rm_f rb_names end
24
+
25
+ rb_names.each do |rb_name|
26
+ ffi_name = "#{rb_name}.ffi"
27
+
28
+ file rb_name => ffi_name do |t|
29
+ puts "Generating #{rb_name}..." if Rake.application.options.trace
30
+
31
+ FFI::Generator.new ffi_name, rb_name
32
+ end
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,194 @@
1
+ require 'tempfile'
2
+
3
+ module FFI
4
+
5
+ ##
6
+ # Generates an FFI Struct layout.
7
+ #
8
+ # Given the @@@ portion in:
9
+ #
10
+ # module Zlib::ZStream < FFI::Struct
11
+ # @@@
12
+ # name "struct z_stream_s"
13
+ # include "zlib.h"
14
+ #
15
+ # field :next_in, :pointer
16
+ # field :avail_in, :uint
17
+ # field :total_in, :ulong
18
+ #
19
+ # # ...
20
+ # @@@
21
+ # end
22
+ #
23
+ # StructGenerator will create the layout:
24
+ #
25
+ # layout :next_in, :pointer, 0,
26
+ # :avail_in, :uint, 4,
27
+ # :total_in, :ulong, 8,
28
+ # # ...
29
+ #
30
+ # StructGenerator does its best to pad the layout it produces to preserve
31
+ # line numbers. Place the struct definition as close to the top of the file
32
+ # for best results.
33
+
34
+ class StructGenerator
35
+ @options = {}
36
+ attr_accessor :size
37
+ attr_reader :fields
38
+
39
+ def initialize(name, options = {})
40
+ @name = name
41
+ @struct_name = nil
42
+ @includes = []
43
+ @fields = []
44
+ @found = false
45
+ @size = nil
46
+
47
+ if block_given? then
48
+ yield self
49
+ calculate self.class.options.merge(options)
50
+ end
51
+ end
52
+ def self.options=(options)
53
+ @options = options
54
+ end
55
+ def self.options
56
+ @options
57
+ end
58
+ def calculate(options = {})
59
+ binary = File.join Dir.tmpdir, "rb_struct_gen_bin_#{Process.pid}"
60
+
61
+ raise "struct name not set" if @struct_name.nil?
62
+
63
+ Tempfile.open("#{@name}.struct_generator") do |f|
64
+ f.puts "#include <stdio.h>"
65
+
66
+ @includes.each do |inc|
67
+ f.puts "#include <#{inc}>"
68
+ end
69
+
70
+ f.puts "#include <stddef.h>\n\n"
71
+ f.puts "int main(int argc, char **argv)\n{"
72
+ f.puts " #{@struct_name} s;"
73
+ f.puts %[ printf("sizeof(#{@struct_name}) %u\\n", (unsigned int) sizeof(#{@struct_name}));]
74
+
75
+ @fields.each do |field|
76
+ f.puts <<-EOF
77
+ printf("#{field.name} %u %u\\n", (unsigned int) offsetof(#{@struct_name}, #{field.name}),
78
+ (unsigned int) sizeof(s.#{field.name}));
79
+ EOF
80
+ end
81
+
82
+ f.puts "\n return 0;\n}"
83
+ f.flush
84
+
85
+ output = `gcc #{options[:cppflags]} #{options[:cflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -x c -Wall -Werror #{f.path} -o #{binary} 2>&1`
86
+
87
+ unless $?.success? then
88
+ @found = false
89
+ output = output.split("\n").map { |l| "\t#{l}" }.join "\n"
90
+ raise "Compilation error generating struct #{@name} (#{@struct_name}):\n#{output}"
91
+ end
92
+ end
93
+
94
+ output = `#{binary}`.split "\n"
95
+ File.unlink(binary + (FFI::Platform.windows? ? ".exe" : ""))
96
+ sizeof = output.shift
97
+ unless @size
98
+ m = /\s*sizeof\([^)]+\) (\d+)/.match sizeof
99
+ @size = m[1]
100
+ end
101
+
102
+ line_no = 0
103
+ output.each do |line|
104
+ md = line.match(/.+ (\d+) (\d+)/)
105
+ @fields[line_no].offset = md[1].to_i
106
+ @fields[line_no].size = md[2].to_i
107
+
108
+ line_no += 1
109
+ end
110
+
111
+ @found = true
112
+ end
113
+
114
+ def field(name, type=nil)
115
+ field = Field.new(name, type)
116
+ @fields << field
117
+ return field
118
+ end
119
+
120
+ def found?
121
+ @found
122
+ end
123
+
124
+ def dump_config(io)
125
+ io.puts "rbx.platform.#{@name}.sizeof = #{@size}"
126
+
127
+ @fields.each { |field| io.puts field.to_config(@name) }
128
+ end
129
+
130
+ def generate_layout
131
+ buf = ""
132
+
133
+ @fields.each_with_index do |field, i|
134
+ if buf.empty?
135
+ buf << "layout :#{field.name}, :#{field.type}, #{field.offset}"
136
+ else
137
+ buf << " :#{field.name}, :#{field.type}, #{field.offset}"
138
+ end
139
+
140
+ if i < @fields.length - 1
141
+ buf << ",\n"
142
+ end
143
+ end
144
+
145
+ buf
146
+ end
147
+
148
+ def get_field(name)
149
+ @fields.find { |f| name == f.name }
150
+ end
151
+
152
+ def include(i)
153
+ @includes << i
154
+ end
155
+
156
+ def name(n)
157
+ @struct_name = n
158
+ end
159
+
160
+ end
161
+
162
+ ##
163
+ # A field in a Struct.
164
+
165
+ class StructGenerator::Field
166
+
167
+ attr_reader :name
168
+ attr_reader :type
169
+ attr_reader :offset
170
+ attr_accessor :size
171
+
172
+ def initialize(name, type)
173
+ @name = name
174
+ @type = type
175
+ @offset = nil
176
+ @size = nil
177
+ end
178
+
179
+ def offset=(o)
180
+ @offset = o
181
+ end
182
+
183
+ def to_config(name)
184
+ buf = []
185
+ buf << "rbx.platform.#{name}.#{@name}.offset = #{@offset}"
186
+ buf << "rbx.platform.#{name}.#{@name}.size = #{@size}"
187
+ buf << "rbx.platform.#{name}.#{@name}.type = #{@type}" if @type
188
+ buf
189
+ end
190
+
191
+ end
192
+
193
+ end
194
+
@@ -0,0 +1,134 @@
1
+ require 'tempfile'
2
+
3
+ module FFI
4
+
5
+ # @private
6
+ class TypesGenerator
7
+
8
+ ##
9
+ # Maps different C types to the C type representations we use
10
+
11
+ TYPE_MAP = {
12
+ "char" => :char,
13
+ "signed char" => :char,
14
+ "__signed char" => :char,
15
+ "unsigned char" => :uchar,
16
+
17
+ "short" => :short,
18
+ "signed short" => :short,
19
+ "signed short int" => :short,
20
+ "unsigned short" => :ushort,
21
+ "unsigned short int" => :ushort,
22
+
23
+ "int" => :int,
24
+ "signed int" => :int,
25
+ "unsigned int" => :uint,
26
+
27
+ "long" => :long,
28
+ "long int" => :long,
29
+ "signed long" => :long,
30
+ "signed long int" => :long,
31
+ "unsigned long" => :ulong,
32
+ "unsigned long int" => :ulong,
33
+ "long unsigned int" => :ulong,
34
+
35
+ "long long" => :long_long,
36
+ "long long int" => :long_long,
37
+ "signed long long" => :long_long,
38
+ "signed long long int" => :long_long,
39
+ "unsigned long long" => :ulong_long,
40
+ "unsigned long long int" => :ulong_long,
41
+
42
+ "char *" => :string,
43
+ "void *" => :pointer,
44
+ }
45
+
46
+ def self.generate(options = {})
47
+ typedefs = nil
48
+ Tempfile.open 'ffi_types_generator' do |io|
49
+ io.puts <<-C
50
+ #include <sys/types.h>
51
+ #if !(defined(WIN32))
52
+ #include <sys/socket.h>
53
+ #include <sys/resource.h>
54
+ #endif
55
+ C
56
+
57
+ io.close
58
+ cc = ENV['CC'] || 'gcc'
59
+ cmd = "#{cc} -E -x c #{options[:cppflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -c"
60
+ if options[:input]
61
+ typedefs = File.read(options[:input])
62
+ elsif options[:remote]
63
+ typedefs = `ssh #{options[:remote]} #{cmd} - < #{io.path}`
64
+ else
65
+ typedefs = `#{cmd} #{io.path}`
66
+ end
67
+ end
68
+
69
+ code = ""
70
+
71
+ typedefs.each_line do |type|
72
+ # We only care about single line typedef
73
+ next unless type =~ /typedef/
74
+ # Ignore unions or structs
75
+ next if type =~ /union|struct/
76
+
77
+ # strip off the starting typedef and ending ;
78
+ type.gsub!(/^(.*typedef\s*)/, "")
79
+ type.gsub!(/\s*;\s*$/, "")
80
+
81
+ parts = type.split(/\s+/)
82
+ def_type = parts.join(" ")
83
+
84
+ # GCC does mapping with __attribute__ stuf, also see
85
+ # http://hal.cs.berkeley.edu/cil/cil016.html section 16.2.7. Problem
86
+ # with this is that the __attribute__ stuff can either occur before or
87
+ # after the new type that is defined...
88
+ if type =~ /__attribute__/
89
+ if parts.last =~ /__QI__|__HI__|__SI__|__DI__|__word__/
90
+
91
+ # In this case, the new type is BEFORE __attribute__ we need to
92
+ # find the final_type as the type before the part that starts with
93
+ # __attribute__
94
+ final_type = ""
95
+ parts.each do |p|
96
+ break if p =~ /__attribute__/
97
+ final_type = p
98
+ end
99
+ else
100
+ final_type = parts.pop
101
+ end
102
+
103
+ def_type = case type
104
+ when /__QI__/ then "char"
105
+ when /__HI__/ then "short"
106
+ when /__SI__/ then "int"
107
+ when /__DI__/ then "long long"
108
+ when /__word__/ then "long"
109
+ else "int"
110
+ end
111
+
112
+ def_type = "unsigned #{def_type}" if type =~ /unsigned/
113
+ else
114
+ final_type = parts.pop
115
+ def_type = parts.join(" ")
116
+ end
117
+
118
+ if type = TYPE_MAP[def_type]
119
+ code << "rbx.platform.typedef.#{final_type} = #{type}\n"
120
+ TYPE_MAP[final_type] = TYPE_MAP[def_type]
121
+ else
122
+ # Fallback to an ordinary pointer if we don't know the type
123
+ if def_type =~ /\*/
124
+ code << "rbx.platform.typedef.#{final_type} = pointer\n"
125
+ TYPE_MAP[final_type] = :pointer
126
+ end
127
+ end
128
+ end
129
+
130
+ code
131
+ end
132
+ end
133
+ end
134
+
@@ -0,0 +1,194 @@
1
+ #
2
+ # Copyright (C) 2008-2010 Wayne Meissner
3
+ # Copyright (c) 2007, 2008 Evan Phoenix
4
+ #
5
+ # This file is part of ruby-ffi.
6
+ #
7
+ # All rights reserved.
8
+ #
9
+ # Redistribution and use in source and binary forms, with or without
10
+ # modification, are permitted provided that the following conditions are met:
11
+ #
12
+ # * Redistributions of source code must retain the above copyright notice, this
13
+ # list of conditions and the following disclaimer.
14
+ # * Redistributions in binary form must reproduce the above copyright notice
15
+ # this list of conditions and the following disclaimer in the documentation
16
+ # and/or other materials provided with the distribution.
17
+ # * Neither the name of the Ruby FFI project nor the names of its contributors
18
+ # may be used to endorse or promote products derived from this software
19
+ # without specific prior written permission.
20
+ #
21
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
25
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+
33
+ # see {file:README}
34
+ module FFI
35
+
36
+ # @param [Type, DataConverter, Symbol] old type definition used by {FFI.find_type}
37
+ # @param [Symbol] add new type definition's name to add
38
+ # @return [Type]
39
+ # Add a definition type to type definitions.
40
+ def self.typedef(old, add)
41
+ TypeDefs[add] = self.find_type(old)
42
+ end
43
+
44
+ # (see FFI.typedef)
45
+ def self.add_typedef(old, add)
46
+ typedef old, add
47
+ end
48
+
49
+
50
+ # @param [Type, DataConverter, Symbol] name
51
+ # @param [Hash] type_map if nil, {FFI::TypeDefs} is used
52
+ # @return [Type]
53
+ # Find a type in +type_map+ ({FFI::TypeDefs}, by default) from
54
+ # a type objet, a type name (symbol). If +name+ is a {DataConverter},
55
+ # a new {Type::Mapped} is created.
56
+ def self.find_type(name, type_map = nil)
57
+ if name.is_a?(Type)
58
+ name
59
+
60
+ elsif type_map && type_map.has_key?(name)
61
+ type_map[name]
62
+
63
+ elsif TypeDefs.has_key?(name)
64
+ TypeDefs[name]
65
+
66
+ elsif name.is_a?(DataConverter)
67
+ (type_map || TypeDefs)[name] = Type::Mapped.new(name)
68
+ else
69
+ raise TypeError, "unable to resolve type '#{name}'"
70
+ end
71
+ end
72
+
73
+ # List of type definitions
74
+ TypeDefs.merge!({
75
+ # The C void type; only useful for function return types
76
+ :void => Type::VOID,
77
+
78
+ # C boolean type
79
+ :bool => Type::BOOL,
80
+
81
+ # C nul-terminated string
82
+ :string => Type::STRING,
83
+
84
+ # C signed char
85
+ :char => Type::CHAR,
86
+ # C unsigned char
87
+ :uchar => Type::UCHAR,
88
+
89
+ # C signed short
90
+ :short => Type::SHORT,
91
+ # C unsigned short
92
+ :ushort => Type::USHORT,
93
+
94
+ # C signed int
95
+ :int => Type::INT,
96
+ # C unsigned int
97
+ :uint => Type::UINT,
98
+
99
+ # C signed long
100
+ :long => Type::LONG,
101
+
102
+ # C unsigned long
103
+ :ulong => Type::ULONG,
104
+
105
+ # C signed long long integer
106
+ :long_long => Type::LONG_LONG,
107
+
108
+ # C unsigned long long integer
109
+ :ulong_long => Type::ULONG_LONG,
110
+
111
+ # C single precision float
112
+ :float => Type::FLOAT,
113
+
114
+ # C double precision float
115
+ :double => Type::DOUBLE,
116
+
117
+ # C long double
118
+ :long_double => Type::LONGDOUBLE,
119
+
120
+ # Native memory address
121
+ :pointer => Type::POINTER,
122
+
123
+ # 8 bit signed integer
124
+ :int8 => Type::INT8,
125
+ # 8 bit unsigned integer
126
+ :uint8 => Type::UINT8,
127
+
128
+ # 16 bit signed integer
129
+ :int16 => Type::INT16,
130
+ # 16 bit unsigned integer
131
+ :uint16 => Type::UINT16,
132
+
133
+ # 32 bit signed integer
134
+ :int32 => Type::INT32,
135
+ # 32 bit unsigned integer
136
+ :uint32 => Type::UINT32,
137
+
138
+ # 64 bit signed integer
139
+ :int64 => Type::INT64,
140
+ # 64 bit unsigned integer
141
+ :uint64 => Type::UINT64,
142
+
143
+ :buffer_in => Type::BUFFER_IN,
144
+ :buffer_out => Type::BUFFER_OUT,
145
+ :buffer_inout => Type::BUFFER_INOUT,
146
+
147
+ # Used in function prototypes to indicate the arguments are variadic
148
+ :varargs => Type::VARARGS,
149
+ })
150
+
151
+ # This will convert a pointer to a Ruby string (just like `:string`), but
152
+ # also allow to work with the pointer itself. This is useful when you want
153
+ # a Ruby string already containing a copy of the data, but also the pointer
154
+ # to the data for you to do something with it, like freeing it, in case the
155
+ # library handed the memory to off to the caller (Ruby-FFI).
156
+ #
157
+ # It's {typedef}'d as +:strptr+.
158
+ class StrPtrConverter
159
+ extend DataConverter
160
+ native_type Type::POINTER
161
+
162
+ # @param [Pointer] val
163
+ # @param ctx not used
164
+ # @return [Array(String, Pointer)]
165
+ # Returns a [ String, Pointer ] tuple so the C memory for the string can be freed
166
+ def self.from_native(val, ctx)
167
+ [ val.null? ? nil : val.get_string(0), val ]
168
+ end
169
+ end
170
+
171
+ typedef(StrPtrConverter, :strptr)
172
+
173
+ # @param type +type+ is an instance of class accepted by {FFI.find_type}
174
+ # @return [Numeric]
175
+ # Get +type+ size, in bytes.
176
+ def self.type_size(type)
177
+ find_type(type).size
178
+ end
179
+
180
+ # Load all the platform dependent types
181
+ begin
182
+ File.open(File.join(Platform::CONF_DIR, 'types.conf'), "r") do |f|
183
+ prefix = "rbx.platform.typedef."
184
+ f.each_line { |line|
185
+ if line.index(prefix) == 0
186
+ new_type, orig_type = line.chomp.slice(prefix.length..-1).split(/\s*=\s*/)
187
+ typedef(orig_type.to_sym, new_type.to_sym)
188
+ end
189
+ }
190
+ end
191
+ typedef :pointer, :caddr_t
192
+ rescue Errno::ENOENT
193
+ end
194
+ end