ffi 1.1.5 → 1.15.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (629) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +338 -0
  3. data/COPYING +49 -0
  4. data/Gemfile +14 -0
  5. data/LICENSE +21 -11
  6. data/LICENSE.SPECS +22 -0
  7. data/README.md +136 -0
  8. data/Rakefile +149 -154
  9. data/ext/ffi_c/AbstractMemory.c +133 -57
  10. data/ext/ffi_c/AbstractMemory.h +21 -12
  11. data/ext/ffi_c/ArrayType.c +27 -14
  12. data/ext/ffi_c/ArrayType.h +21 -12
  13. data/ext/ffi_c/Buffer.c +29 -25
  14. data/ext/ffi_c/Call.c +154 -125
  15. data/ext/ffi_c/Call.h +43 -20
  16. data/ext/ffi_c/ClosurePool.c +100 -42
  17. data/ext/ffi_c/ClosurePool.h +24 -13
  18. data/ext/ffi_c/DynamicLibrary.c +47 -28
  19. data/ext/ffi_c/DynamicLibrary.h +70 -12
  20. data/ext/ffi_c/Function.c +119 -167
  21. data/ext/ffi_c/Function.h +23 -19
  22. data/ext/ffi_c/FunctionInfo.c +55 -25
  23. data/ext/ffi_c/LastError.c +70 -21
  24. data/ext/ffi_c/LastError.h +21 -12
  25. data/ext/ffi_c/LongDouble.c +15 -9
  26. data/ext/ffi_c/LongDouble.h +21 -16
  27. data/ext/ffi_c/MappedType.c +22 -15
  28. data/ext/ffi_c/MappedType.h +21 -12
  29. data/ext/ffi_c/MemoryPointer.c +58 -33
  30. data/ext/ffi_c/MemoryPointer.h +22 -19
  31. data/ext/ffi_c/MethodHandle.c +49 -50
  32. data/ext/ffi_c/MethodHandle.h +24 -14
  33. data/ext/ffi_c/Platform.c +28 -62
  34. data/ext/ffi_c/Platform.h +21 -12
  35. data/ext/ffi_c/Pointer.c +63 -46
  36. data/ext/ffi_c/Pointer.h +22 -19
  37. data/ext/ffi_c/Struct.c +198 -80
  38. data/ext/ffi_c/Struct.h +33 -18
  39. data/ext/ffi_c/StructByValue.c +23 -20
  40. data/ext/ffi_c/StructByValue.h +21 -12
  41. data/ext/ffi_c/StructLayout.c +184 -39
  42. data/ext/ffi_c/Thread.c +73 -270
  43. data/ext/ffi_c/Thread.h +32 -35
  44. data/ext/ffi_c/Type.c +26 -32
  45. data/ext/ffi_c/Type.h +24 -10
  46. data/ext/ffi_c/Types.c +28 -20
  47. data/ext/ffi_c/Types.h +25 -16
  48. data/ext/ffi_c/Variadic.c +78 -39
  49. data/ext/ffi_c/compat.h +25 -17
  50. data/ext/ffi_c/extconf.rb +68 -31
  51. data/ext/ffi_c/ffi.c +27 -20
  52. data/ext/ffi_c/libffi/.appveyor.yml +66 -0
  53. data/ext/ffi_c/libffi/.gitattributes +4 -0
  54. data/ext/ffi_c/libffi/.github/issue_template.md +10 -0
  55. data/ext/ffi_c/libffi/.gitignore +38 -0
  56. data/ext/ffi_c/libffi/.travis/ar-lib +270 -0
  57. data/ext/ffi_c/libffi/.travis/bfin-sim.exp +58 -0
  58. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +14 -0
  59. data/ext/ffi_c/libffi/.travis/build-in-container.sh +12 -0
  60. data/ext/ffi_c/libffi/.travis/build.sh +142 -0
  61. data/ext/ffi_c/libffi/.travis/compile +351 -0
  62. data/ext/ffi_c/libffi/.travis/install.sh +71 -0
  63. data/ext/ffi_c/libffi/.travis/m32r-sim.exp +58 -0
  64. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +60 -0
  65. data/ext/ffi_c/libffi/.travis/or1k-sim.exp +58 -0
  66. data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +58 -0
  67. data/ext/ffi_c/libffi/.travis/site.exp +27 -0
  68. data/ext/ffi_c/libffi/.travis/wine-sim.exp +55 -0
  69. data/ext/ffi_c/libffi/.travis.yml +83 -0
  70. data/ext/ffi_c/libffi/{ChangeLog → ChangeLog.old} +6366 -3559
  71. data/ext/ffi_c/libffi/LICENSE +1 -1
  72. data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +353 -0
  73. data/ext/ffi_c/libffi/Makefile.am +123 -169
  74. data/ext/ffi_c/libffi/Makefile.in +1243 -1003
  75. data/ext/ffi_c/libffi/README.md +486 -0
  76. data/ext/ffi_c/libffi/acinclude.m4 +387 -0
  77. data/ext/ffi_c/libffi/autogen.sh +2 -0
  78. data/ext/ffi_c/libffi/config.guess +690 -504
  79. data/ext/ffi_c/libffi/config.sub +1353 -1207
  80. data/ext/ffi_c/libffi/configure +7308 -2449
  81. data/ext/ffi_c/libffi/configure.ac +178 -259
  82. data/ext/ffi_c/libffi/configure.host +311 -4
  83. data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
  84. data/ext/ffi_c/libffi/doc/Makefile.in +815 -0
  85. data/ext/ffi_c/libffi/doc/libffi.texi +455 -58
  86. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  87. data/ext/ffi_c/libffi/fficonfig.h.in +37 -13
  88. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +201 -0
  89. data/ext/ffi_c/libffi/include/Makefile.am +3 -3
  90. data/ext/ffi_c/libffi/include/Makefile.in +196 -75
  91. data/ext/ffi_c/libffi/include/ffi.h.in +163 -67
  92. data/ext/ffi_c/libffi/include/ffi_cfi.h +55 -0
  93. data/ext/ffi_c/libffi/include/ffi_common.h +39 -12
  94. data/ext/ffi_c/libffi/install-sh +207 -209
  95. data/ext/ffi_c/libffi/libffi.map.in +76 -0
  96. data/ext/ffi_c/libffi/libffi.pc.in +3 -2
  97. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +997 -0
  98. data/ext/ffi_c/libffi/libtool-ldflags +106 -0
  99. data/ext/ffi_c/libffi/libtool-version +1 -1
  100. data/ext/ffi_c/libffi/ltmain.sh +3641 -2026
  101. data/ext/ffi_c/libffi/m4/asmcfi.m4 +13 -0
  102. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +50 -0
  103. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +32 -14
  104. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +33 -106
  105. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +53 -0
  106. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +38 -13
  107. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +8 -29
  108. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +11 -9
  109. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +104 -52
  110. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +18 -8
  111. data/ext/ffi_c/libffi/m4/ax_require_defined.m4 +37 -0
  112. data/ext/ffi_c/libffi/make_sunver.pl +333 -0
  113. data/ext/ffi_c/libffi/man/Makefile.am +2 -2
  114. data/ext/ffi_c/libffi/man/Makefile.in +151 -55
  115. data/ext/ffi_c/libffi/man/ffi.3 +10 -0
  116. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +6 -4
  117. data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +73 -0
  118. data/ext/ffi_c/libffi/missing +153 -314
  119. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.sln +33 -0
  120. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj +130 -0
  121. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.filters +57 -0
  122. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user +4 -0
  123. data/ext/ffi_c/libffi/{include/ffi.h.vc64 → msvc_build/aarch64/aarch64_include/ffi.h} +151 -67
  124. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/fficonfig.h +219 -0
  125. data/ext/ffi_c/libffi/msvcc.sh +176 -20
  126. data/ext/ffi_c/libffi/src/aarch64/ffi.c +1025 -0
  127. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +97 -0
  128. data/ext/ffi_c/libffi/src/aarch64/internal.h +68 -0
  129. data/ext/ffi_c/libffi/src/aarch64/sysv.S +451 -0
  130. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
  131. data/ext/ffi_c/libffi/src/alpha/ffi.c +335 -98
  132. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +10 -1
  133. data/ext/ffi_c/libffi/src/alpha/internal.h +23 -0
  134. data/ext/ffi_c/libffi/src/alpha/osf.S +161 -266
  135. data/ext/ffi_c/libffi/src/arc/arcompact.S +135 -0
  136. data/ext/ffi_c/libffi/src/arc/ffi.c +266 -0
  137. data/ext/ffi_c/libffi/src/arc/ffitarget.h +53 -0
  138. data/ext/ffi_c/libffi/src/arm/ffi.c +663 -515
  139. data/ext/ffi_c/libffi/src/arm/ffitarget.h +32 -8
  140. data/ext/ffi_c/libffi/src/arm/internal.h +7 -0
  141. data/ext/ffi_c/libffi/src/arm/sysv.S +305 -417
  142. data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
  143. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +6 -1
  144. data/ext/ffi_c/libffi/src/bfin/ffi.c +196 -0
  145. data/ext/ffi_c/libffi/src/bfin/ffitarget.h +43 -0
  146. data/ext/ffi_c/libffi/src/bfin/sysv.S +179 -0
  147. data/ext/ffi_c/libffi/src/closures.c +465 -59
  148. data/ext/ffi_c/libffi/src/cris/ffi.c +10 -7
  149. data/ext/ffi_c/libffi/src/cris/ffitarget.h +6 -1
  150. data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
  151. data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
  152. data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
  153. data/ext/ffi_c/libffi/src/debug.c +6 -1
  154. data/ext/ffi_c/libffi/src/dlmalloc.c +17 -12
  155. data/ext/ffi_c/libffi/src/frv/ffi.c +2 -2
  156. data/ext/ffi_c/libffi/src/frv/ffitarget.h +6 -1
  157. data/ext/ffi_c/libffi/src/ia64/ffi.c +35 -13
  158. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +8 -2
  159. data/ext/ffi_c/libffi/src/ia64/unix.S +8 -1
  160. data/ext/ffi_c/libffi/src/java_raw_api.c +23 -5
  161. data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
  162. data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
  163. data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
  164. data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
  165. data/ext/ffi_c/libffi/src/m32r/ffi.c +1 -1
  166. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +6 -1
  167. data/ext/ffi_c/libffi/src/m68k/ffi.c +87 -13
  168. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +6 -1
  169. data/ext/ffi_c/libffi/src/m68k/sysv.S +119 -32
  170. data/ext/ffi_c/libffi/src/m88k/ffi.c +400 -0
  171. data/ext/ffi_c/libffi/src/m88k/ffitarget.h +49 -0
  172. data/ext/ffi_c/libffi/src/m88k/obsd.S +209 -0
  173. data/ext/ffi_c/libffi/src/metag/ffi.c +330 -0
  174. data/ext/ffi_c/libffi/{fficonfig.hw → src/metag/ffitarget.h} +22 -26
  175. data/ext/ffi_c/libffi/src/metag/sysv.S +311 -0
  176. data/ext/ffi_c/libffi/src/microblaze/ffi.c +321 -0
  177. data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +53 -0
  178. data/ext/ffi_c/libffi/src/microblaze/sysv.S +302 -0
  179. data/ext/ffi_c/libffi/src/mips/ffi.c +135 -37
  180. data/ext/ffi_c/libffi/src/mips/ffitarget.h +16 -14
  181. data/ext/ffi_c/libffi/src/mips/n32.S +128 -56
  182. data/ext/ffi_c/libffi/src/mips/o32.S +150 -27
  183. data/ext/ffi_c/libffi/src/moxie/eabi.S +55 -82
  184. data/ext/ffi_c/libffi/src/moxie/ffi.c +55 -46
  185. data/ext/ffi_c/libffi/src/moxie/ffitarget.h +52 -0
  186. data/ext/ffi_c/libffi/src/nios2/ffi.c +304 -0
  187. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +52 -0
  188. data/ext/ffi_c/libffi/src/nios2/sysv.S +136 -0
  189. data/ext/ffi_c/libffi/src/or1k/ffi.c +328 -0
  190. data/ext/ffi_c/libffi/src/or1k/ffitarget.h +58 -0
  191. data/ext/ffi_c/libffi/src/or1k/sysv.S +107 -0
  192. data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
  193. data/ext/ffi_c/libffi/src/pa/ffitarget.h +9 -7
  194. data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
  195. data/ext/ffi_c/libffi/src/pa/linux.S +27 -4
  196. data/ext/ffi_c/libffi/src/powerpc/aix.S +245 -7
  197. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +253 -4
  198. data/ext/ffi_c/libffi/src/powerpc/asm.h +2 -2
  199. data/ext/ffi_c/libffi/src/powerpc/darwin.S +2 -7
  200. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +22 -26
  201. data/ext/ffi_c/libffi/src/powerpc/ffi.c +105 -1378
  202. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +123 -30
  203. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1153 -0
  204. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +105 -0
  205. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +923 -0
  206. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +110 -45
  207. data/ext/ffi_c/libffi/src/powerpc/linux64.S +189 -85
  208. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +436 -108
  209. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +138 -68
  210. data/ext/ffi_c/libffi/src/powerpc/sysv.S +73 -119
  211. data/ext/ffi_c/libffi/src/prep_cif.c +111 -25
  212. data/ext/ffi_c/libffi/src/raw_api.c +18 -5
  213. data/ext/ffi_c/libffi/src/riscv/ffi.c +481 -0
  214. data/ext/ffi_c/libffi/src/riscv/ffitarget.h +69 -0
  215. data/ext/ffi_c/libffi/src/riscv/sysv.S +293 -0
  216. data/ext/ffi_c/libffi/src/s390/ffi.c +294 -318
  217. data/ext/ffi_c/libffi/src/s390/ffitarget.h +9 -1
  218. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  219. data/ext/ffi_c/libffi/src/s390/sysv.S +257 -366
  220. data/ext/ffi_c/libffi/src/sh/ffi.c +4 -3
  221. data/ext/ffi_c/libffi/src/sh/ffitarget.h +6 -1
  222. data/ext/ffi_c/libffi/src/sh64/ffi.c +3 -2
  223. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +6 -1
  224. data/ext/ffi_c/libffi/src/sparc/ffi.c +326 -527
  225. data/ext/ffi_c/libffi/src/sparc/ffi64.c +608 -0
  226. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +20 -7
  227. data/ext/ffi_c/libffi/src/sparc/internal.h +26 -0
  228. data/ext/ffi_c/libffi/src/sparc/v8.S +364 -234
  229. data/ext/ffi_c/libffi/src/sparc/v9.S +340 -207
  230. data/ext/ffi_c/libffi/src/tile/ffi.c +355 -0
  231. data/ext/ffi_c/libffi/src/tile/ffitarget.h +65 -0
  232. data/ext/ffi_c/libffi/src/tile/tile.S +360 -0
  233. data/ext/ffi_c/libffi/src/types.c +46 -15
  234. data/ext/ffi_c/libffi/src/vax/elfbsd.S +195 -0
  235. data/ext/ffi_c/libffi/src/vax/ffi.c +276 -0
  236. data/ext/ffi_c/libffi/src/vax/ffitarget.h +49 -0
  237. data/ext/ffi_c/libffi/src/x86/asmnames.h +30 -0
  238. data/ext/ffi_c/libffi/src/x86/ffi.c +624 -498
  239. data/ext/ffi_c/libffi/src/x86/ffi64.c +379 -119
  240. data/ext/ffi_c/libffi/src/x86/ffitarget.h +74 -35
  241. data/ext/ffi_c/libffi/src/x86/ffiw64.c +318 -0
  242. data/ext/ffi_c/libffi/src/x86/internal.h +29 -0
  243. data/ext/ffi_c/libffi/src/x86/internal64.h +22 -0
  244. data/ext/ffi_c/libffi/src/x86/sysv.S +1070 -400
  245. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +995 -0
  246. data/ext/ffi_c/libffi/src/x86/unix64.S +494 -299
  247. data/ext/ffi_c/libffi/src/x86/win64.S +231 -458
  248. data/ext/ffi_c/libffi/src/x86/win64_intel.S +238 -0
  249. data/ext/ffi_c/libffi/src/xtensa/ffi.c +298 -0
  250. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +53 -0
  251. data/ext/ffi_c/libffi/src/xtensa/sysv.S +258 -0
  252. data/ext/ffi_c/libffi/stamp-h.in +1 -0
  253. data/ext/ffi_c/libffi/testsuite/Makefile.am +115 -73
  254. data/ext/ffi_c/libffi/testsuite/Makefile.in +262 -114
  255. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +334 -24
  256. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +21 -1
  257. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/Makefile +28 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/README +78 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/alignof.h +50 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +63 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1745 -0
  262. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2885 -0
  263. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +743 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +46 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/align_stdcall.c +46 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +28 -6
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -2
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +25 -40
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +3 -1
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +15 -12
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +4 -2
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +107 -0
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +6 -16
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +57 -0
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +70 -0
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +78 -0
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +0 -1
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +46 -0
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +127 -0
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +1 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +1 -1
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +1 -1
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +1 -1
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +2 -2
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +49 -0
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +49 -0
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +55 -0
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +9 -7
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +57 -0
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +7 -7
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +7 -6
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +9 -8
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +9 -8
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +9 -9
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +9 -9
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +9 -8
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +9 -8
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +61 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +196 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +121 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +123 -0
  302. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +125 -0
  303. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure.exp +67 -0
  304. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn0.c +0 -0
  305. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn1.c +0 -0
  306. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn2.c +0 -0
  307. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn3.c +0 -0
  308. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn4.c +0 -0
  309. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn5.c +0 -0
  310. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn6.c +0 -0
  311. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_loc_fn0.c +0 -0
  312. data/ext/ffi_c/libffi/testsuite/{libffi.call/closure_stdcall.c → libffi.closures/closure_simple.c} +7 -16
  313. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_12byte.c +4 -4
  314. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_16byte.c +4 -4
  315. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_18byte.c +4 -4
  316. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_19byte.c +4 -4
  317. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_1_1byte.c +4 -4
  318. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte.c +4 -4
  319. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte1.c +4 -4
  320. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_24byte.c +5 -5
  321. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_2byte.c +4 -4
  322. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3_1byte.c +4 -4
  323. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte1.c +4 -4
  324. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte2.c +4 -4
  325. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +95 -0
  326. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4_1byte.c +4 -4
  327. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4byte.c +4 -4
  328. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5_1_byte.c +4 -4
  329. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5byte.c +4 -4
  330. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_64byte.c +5 -5
  331. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6_1_byte.c +4 -4
  332. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6byte.c +4 -4
  333. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7_1_byte.c +4 -4
  334. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7byte.c +4 -4
  335. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_8byte.c +4 -4
  336. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte1.c +4 -4
  337. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte2.c +4 -4
  338. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_double.c +4 -4
  339. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_float.c +4 -4
  340. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble.c +4 -4
  341. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split.c +4 -6
  342. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split2.c +4 -6
  343. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_pointer.c +4 -4
  344. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint16.c +4 -4
  345. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint32.c +4 -4
  346. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint64.c +4 -4
  347. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint16.c +4 -4
  348. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint32.c +4 -4
  349. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint64.c +4 -4
  350. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_dbls_struct.c +4 -4
  351. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double.c +0 -0
  352. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double_va.c +10 -9
  353. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_float.c +0 -0
  354. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble.c +3 -3
  355. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble_va.c +10 -9
  356. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_many_mixed_args.c +70 -0
  357. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_many_mixed_float_double.c +55 -0
  358. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_schar.c +0 -0
  359. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshort.c +0 -0
  360. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshortchar.c +0 -0
  361. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_uchar.c +0 -0
  362. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushort.c +0 -0
  363. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushortchar.c +0 -0
  364. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer.c +1 -1
  365. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer_stack.c +11 -9
  366. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_schar.c +0 -0
  367. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sint.c +0 -0
  368. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sshort.c +0 -0
  369. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +114 -0
  370. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar.c +0 -0
  371. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +44 -0
  372. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint.c +0 -0
  373. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +45 -0
  374. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +45 -0
  375. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulonglong.c +5 -5
  376. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort.c +0 -0
  377. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +44 -0
  378. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/err_bad_abi.c +0 -0
  379. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +138 -0
  380. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/huge_struct.c +20 -19
  381. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct.c +6 -6
  382. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct1.c +8 -8
  383. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct10.c +7 -6
  384. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +121 -0
  385. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct2.c +5 -5
  386. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct3.c +5 -5
  387. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct4.c +5 -5
  388. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct5.c +5 -5
  389. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct6.c +6 -6
  390. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct7.c +5 -5
  391. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct8.c +6 -6
  392. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct9.c +6 -6
  393. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/problem1.c +0 -0
  394. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large.c +7 -7
  395. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large2.c +7 -7
  396. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium.c +5 -5
  397. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium2.c +5 -5
  398. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/testclosure.c +2 -2
  399. data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.closures}/unwindtest.cc +3 -10
  400. data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.closures}/unwindtest_ffi_call.cc +3 -2
  401. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +91 -0
  402. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +10 -0
  403. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +10 -0
  404. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +10 -0
  405. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +42 -0
  406. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +10 -0
  407. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +10 -0
  408. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +10 -0
  409. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +71 -0
  410. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +10 -0
  411. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +10 -0
  412. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +10 -0
  413. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +80 -0
  414. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +10 -0
  415. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +16 -0
  416. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +10 -0
  417. data/ext/ffi_c/libffi/testsuite/{libffi.special/special.exp → libffi.complex/complex.exp} +9 -8
  418. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +51 -0
  419. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +7 -0
  420. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +7 -0
  421. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +7 -0
  422. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +10 -0
  423. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +10 -0
  424. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +86 -0
  425. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +10 -0
  426. data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +1 -0
  427. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +78 -0
  428. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +10 -0
  429. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +10 -0
  430. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +10 -0
  431. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +37 -0
  432. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +41 -0
  433. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +10 -0
  434. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +10 -0
  435. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +10 -0
  436. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +44 -0
  437. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +10 -0
  438. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +10 -0
  439. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +10 -0
  440. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +10 -0
  441. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +10 -0
  442. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +10 -0
  443. data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +34 -0
  444. data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +28 -0
  445. data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +1 -0
  446. data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +36 -0
  447. data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +19 -0
  448. data/ext/ffi_c/libffi.bsd.mk +12 -6
  449. data/ext/ffi_c/libffi.darwin.mk +21 -9
  450. data/ext/ffi_c/libffi.gnu.mk +3 -2
  451. data/ext/ffi_c/libffi.mk +11 -6
  452. data/ext/ffi_c/libffi.vc.mk +1 -1
  453. data/ext/ffi_c/libffi.vc64.mk +1 -1
  454. data/ext/ffi_c/rbffi.h +22 -14
  455. data/ext/ffi_c/rbffi_endian.h +11 -2
  456. data/ffi.gemspec +42 -0
  457. data/lib/ffi/abstract_memory.rb +44 -0
  458. data/lib/ffi/autopointer.rb +70 -50
  459. data/lib/ffi/data_converter.rb +67 -0
  460. data/lib/ffi/enum.rb +159 -24
  461. data/lib/ffi/errno.rb +21 -11
  462. data/lib/ffi/ffi.rb +25 -11
  463. data/lib/ffi/io.rb +24 -14
  464. data/lib/ffi/library.rb +174 -67
  465. data/lib/ffi/managedstruct.rb +63 -34
  466. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  467. data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
  468. data/lib/ffi/platform/aarch64-freebsd12/types.conf +181 -0
  469. data/lib/ffi/platform/aarch64-linux/types.conf +104 -0
  470. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  471. data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
  472. data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
  473. data/lib/ffi/platform/arm-linux/types.conf +110 -82
  474. data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  475. data/lib/ffi/platform/i386-darwin/types.conf +63 -63
  476. data/lib/ffi/platform/i386-freebsd/types.conf +89 -89
  477. data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
  478. data/lib/ffi/platform/{i486-gnu → i386-gnu}/types.conf +84 -84
  479. data/lib/ffi/platform/i386-linux/types.conf +77 -77
  480. data/lib/ffi/platform/i386-netbsd/types.conf +87 -87
  481. data/lib/ffi/platform/i386-openbsd/types.conf +89 -87
  482. data/lib/ffi/platform/i386-solaris/types.conf +96 -96
  483. data/lib/ffi/platform/i386-windows/types.conf +43 -96
  484. data/lib/ffi/platform/ia64-linux/types.conf +79 -79
  485. data/lib/ffi/platform/mips-linux/types.conf +79 -79
  486. data/lib/ffi/platform/mips64-linux/types.conf +104 -0
  487. data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
  488. data/lib/ffi/platform/mipsel-linux/types.conf +79 -79
  489. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +102 -0
  490. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +102 -0
  491. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +104 -0
  492. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +104 -0
  493. data/lib/ffi/platform/powerpc-aix/types.conf +155 -155
  494. data/lib/ffi/platform/powerpc-darwin/types.conf +63 -63
  495. data/lib/ffi/platform/powerpc-linux/types.conf +108 -78
  496. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  497. data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
  498. data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
  499. data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
  500. data/lib/ffi/platform/s390-linux/types.conf +79 -79
  501. data/lib/ffi/platform/s390x-linux/types.conf +79 -79
  502. data/lib/ffi/platform/sparc-linux/types.conf +79 -79
  503. data/lib/ffi/platform/sparc-solaris/types.conf +103 -103
  504. data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
  505. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  506. data/lib/ffi/platform/sparcv9-solaris/types.conf +103 -103
  507. data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
  508. data/lib/ffi/platform/x86_64-darwin/types.conf +93 -63
  509. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
  510. data/lib/ffi/platform/x86_64-freebsd/types.conf +90 -88
  511. data/lib/ffi/platform/x86_64-freebsd12/types.conf +158 -0
  512. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  513. data/lib/ffi/platform/x86_64-linux/types.conf +107 -77
  514. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  515. data/lib/ffi/platform/x86_64-netbsd/types.conf +89 -87
  516. data/lib/ffi/platform/x86_64-openbsd/types.conf +100 -92
  517. data/lib/ffi/platform/x86_64-solaris/types.conf +96 -96
  518. data/lib/ffi/platform/x86_64-windows/types.conf +52 -0
  519. data/lib/ffi/platform.rb +81 -26
  520. data/lib/ffi/pointer.rb +72 -27
  521. data/lib/ffi/struct.rb +99 -66
  522. data/lib/ffi/struct_by_reference.rb +72 -0
  523. data/lib/ffi/struct_layout.rb +96 -0
  524. data/lib/ffi/struct_layout_builder.rb +82 -17
  525. data/lib/ffi/tools/const_generator.rb +11 -8
  526. data/lib/ffi/tools/generator.rb +48 -1
  527. data/lib/ffi/tools/generator_task.rb +13 -16
  528. data/lib/ffi/tools/struct_generator.rb +6 -5
  529. data/lib/ffi/tools/types_generator.rb +14 -10
  530. data/lib/ffi/types.rb +31 -14
  531. data/lib/ffi/union.rb +23 -12
  532. data/lib/ffi/variadic.rb +25 -21
  533. data/lib/ffi/version.rb +3 -0
  534. data/lib/ffi.rb +20 -8
  535. data/rakelib/ffi_gem_helper.rb +65 -0
  536. data/samples/getlogin.rb +8 -0
  537. data/samples/getpid.rb +8 -0
  538. data/samples/gettimeofday.rb +18 -0
  539. data/samples/hello.rb +8 -0
  540. data/samples/inotify.rb +60 -0
  541. data/samples/pty.rb +75 -0
  542. data/samples/qsort.rb +20 -0
  543. metadata +413 -263
  544. data/History.txt +0 -1
  545. data/README.rdoc +0 -102
  546. data/ext/ffi_c/DataConverter.c +0 -91
  547. data/ext/ffi_c/Ffi_c.iml +0 -12
  548. data/ext/ffi_c/StructByReference.c +0 -158
  549. data/ext/ffi_c/StructByReference.h +0 -50
  550. data/ext/ffi_c/libffi/ChangeLog.libffi +0 -584
  551. data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
  552. data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
  553. data/ext/ffi_c/libffi/Makefile.vc +0 -141
  554. data/ext/ffi_c/libffi/Makefile.vc64 +0 -141
  555. data/ext/ffi_c/libffi/README +0 -342
  556. data/ext/ffi_c/libffi/aclocal.m4 +0 -1873
  557. data/ext/ffi_c/libffi/build-ios.sh +0 -67
  558. data/ext/ffi_c/libffi/compile +0 -143
  559. data/ext/ffi_c/libffi/depcomp +0 -630
  560. data/ext/ffi_c/libffi/doc/libffi.info +0 -593
  561. data/ext/ffi_c/libffi/doc/stamp-vti +0 -4
  562. data/ext/ffi_c/libffi/include/ffi.h.vc +0 -427
  563. data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +0 -76
  564. data/ext/ffi_c/libffi/m4/libtool.m4 +0 -7831
  565. data/ext/ffi_c/libffi/m4/ltoptions.m4 +0 -369
  566. data/ext/ffi_c/libffi/m4/ltsugar.m4 +0 -123
  567. data/ext/ffi_c/libffi/m4/ltversion.m4 +0 -23
  568. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +0 -98
  569. data/ext/ffi_c/libffi/mdate-sh +0 -201
  570. data/ext/ffi_c/libffi/src/arm/gentramp.sh +0 -118
  571. data/ext/ffi_c/libffi/src/arm/trampoline.S +0 -4450
  572. data/ext/ffi_c/libffi/src/x86/darwin.S +0 -444
  573. data/ext/ffi_c/libffi/src/x86/darwin64.S +0 -416
  574. data/ext/ffi_c/libffi/src/x86/freebsd.S +0 -458
  575. data/ext/ffi_c/libffi/src/x86/win32.S +0 -1065
  576. data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +0 -300
  577. data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +0 -63
  578. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +0 -44
  579. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +0 -96
  580. data/ext/ffi_c/libffi/texinfo.tex +0 -7210
  581. data/ext/ffi_c/win32/stdint.h +0 -199
  582. data/gen/Rakefile +0 -30
  583. data/gen/log +0 -1
  584. data/lib/Lib.iml +0 -13
  585. data/spec/ffi/Ffi.iml +0 -12
  586. data/spec/ffi/async_callback_spec.rb +0 -46
  587. data/spec/ffi/bool_spec.rb +0 -40
  588. data/spec/ffi/buffer_spec.rb +0 -215
  589. data/spec/ffi/callback_spec.rb +0 -668
  590. data/spec/ffi/custom_param_type.rb +0 -47
  591. data/spec/ffi/custom_type_spec.rb +0 -85
  592. data/spec/ffi/dup_spec.rb +0 -65
  593. data/spec/ffi/enum_spec.rb +0 -227
  594. data/spec/ffi/errno_spec.rb +0 -29
  595. data/spec/ffi/ffi_spec.rb +0 -40
  596. data/spec/ffi/function_spec.rb +0 -87
  597. data/spec/ffi/library_spec.rb +0 -208
  598. data/spec/ffi/long_double.rb +0 -41
  599. data/spec/ffi/managed_struct_spec.rb +0 -72
  600. data/spec/ffi/number_spec.rb +0 -247
  601. data/spec/ffi/pointer_spec.rb +0 -214
  602. data/spec/ffi/rbx/attach_function_spec.rb +0 -28
  603. data/spec/ffi/rbx/memory_pointer_spec.rb +0 -115
  604. data/spec/ffi/rbx/spec_helper.rb +0 -1
  605. data/spec/ffi/rbx/struct_spec.rb +0 -13
  606. data/spec/ffi/spec_helper.rb +0 -35
  607. data/spec/ffi/string_spec.rb +0 -119
  608. data/spec/ffi/strptr_spec.rb +0 -61
  609. data/spec/ffi/struct_callback_spec.rb +0 -80
  610. data/spec/ffi/struct_initialize_spec.rb +0 -46
  611. data/spec/ffi/struct_packed_spec.rb +0 -62
  612. data/spec/ffi/struct_spec.rb +0 -719
  613. data/spec/ffi/typedef_spec.rb +0 -89
  614. data/spec/ffi/union_spec.rb +0 -76
  615. data/spec/ffi/variadic_spec.rb +0 -103
  616. data/spec/spec.opts +0 -4
  617. data/tasks/ann.rake +0 -80
  618. data/tasks/extension.rake +0 -32
  619. data/tasks/gem.rake +0 -199
  620. data/tasks/git.rake +0 -41
  621. data/tasks/notes.rake +0 -27
  622. data/tasks/post_load.rake +0 -34
  623. data/tasks/rdoc.rake +0 -50
  624. data/tasks/rubyforge.rake +0 -55
  625. data/tasks/setup.rb +0 -301
  626. data/tasks/spec.rake +0 -54
  627. data/tasks/svn.rake +0 -47
  628. data/tasks/test.rake +0 -40
  629. data/tasks/yard.rake +0 -11
@@ -1,7 +1,8 @@
1
1
  \input texinfo @c -*-texinfo-*-
2
2
  @c %**start of header
3
3
  @setfilename libffi.info
4
- @settitle libffi
4
+ @include version.texi
5
+ @settitle libffi: the portable foreign function interface library
5
6
  @setchapternewpage off
6
7
  @c %**end of header
7
8
 
@@ -12,32 +13,43 @@
12
13
  @syncodeindex pg cp
13
14
  @syncodeindex tp cp
14
15
 
15
- @include version.texi
16
-
17
16
  @copying
18
17
 
19
- This manual is for Libffi, a portable foreign-function interface
18
+ This manual is for libffi, a portable foreign function interface
20
19
  library.
21
20
 
22
- Copyright @copyright{} 2008, 2010 Red Hat, Inc.
21
+ Copyright @copyright{} 2008--2019 Anthony Green and Red Hat, Inc.
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining
24
+ a copy of this software and associated documentation files (the
25
+ ``Software''), to deal in the Software without restriction, including
26
+ without limitation the rights to use, copy, modify, merge, publish,
27
+ distribute, sublicense, and/or sell copies of the Software, and to
28
+ permit persons to whom the Software is furnished to do so, subject to
29
+ the following conditions:
23
30
 
24
- @quotation
25
- Permission is granted to copy, distribute and/or modify this document
26
- under the terms of the GNU General Public License as published by the
27
- Free Software Foundation; either version 2, or (at your option) any
28
- later version. A copy of the license is included in the
29
- section entitled ``GNU General Public License''.
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
37
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
38
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
39
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
41
 
31
- @end quotation
32
42
  @end copying
33
43
 
34
44
  @dircategory Development
35
45
  @direntry
36
- * libffi: (libffi). Portable foreign-function interface library.
46
+ * libffi: (libffi). Portable foreign function interface library.
37
47
  @end direntry
38
48
 
39
49
  @titlepage
40
- @title Libffi
50
+ @title libffi: a foreign function interface library
51
+ @subtitle For Version @value{VERSION} of libffi
52
+ @author Anthony Green
41
53
  @page
42
54
  @vskip 0pt plus 1filll
43
55
  @insertcopying
@@ -107,6 +119,7 @@ values passed between the two languages.
107
119
  * Multiple ABIs:: Different passing styles on one platform.
108
120
  * The Closure API:: Writing a generic function.
109
121
  * Closure Example:: A closure example.
122
+ * Thread Safety:: Thread safety.
110
123
  @end menu
111
124
 
112
125
 
@@ -133,8 +146,6 @@ This initializes @var{cif} according to the given parameters.
133
146
  you want. @ref{Multiple ABIs} for more information.
134
147
 
135
148
  @var{nargs} is the number of arguments that this function accepts.
136
- @samp{libffi} does not yet handle varargs functions; see @ref{Missing
137
- Features} for more information.
138
149
 
139
150
  @var{rtype} is a pointer to an @code{ffi_type} structure that
140
151
  describes the return type of the function. @xref{Types}.
@@ -150,6 +161,34 @@ objects is incorrect; or @code{FFI_BAD_ABI} if the @var{abi} parameter
150
161
  is invalid.
151
162
  @end defun
152
163
 
164
+ If the function being called is variadic (varargs) then
165
+ @code{ffi_prep_cif_var} must be used instead of @code{ffi_prep_cif}.
166
+
167
+ @findex ffi_prep_cif_var
168
+ @defun ffi_status ffi_prep_cif_var (ffi_cif *@var{cif}, ffi_abi @var{abi}, unsigned int @var{nfixedargs}, unsigned int @var{ntotalargs}, ffi_type *@var{rtype}, ffi_type **@var{argtypes})
169
+ This initializes @var{cif} according to the given parameters for
170
+ a call to a variadic function. In general its operation is the
171
+ same as for @code{ffi_prep_cif} except that:
172
+
173
+ @var{nfixedargs} is the number of fixed arguments, prior to any
174
+ variadic arguments. It must be greater than zero.
175
+
176
+ @var{ntotalargs} the total number of arguments, including variadic
177
+ and fixed arguments. @var{argtypes} must have this many elements.
178
+
179
+ Note that, different cif's must be prepped for calls to the same
180
+ function when different numbers of arguments are passed.
181
+
182
+ Also note that a call to @code{ffi_prep_cif_var} with
183
+ @var{nfixedargs}=@var{nototalargs} is NOT equivalent to a call to
184
+ @code{ffi_prep_cif}.
185
+
186
+ @end defun
187
+
188
+ Note that the resulting @code{ffi_cif} holds pointers to all the
189
+ @code{ffi_type} objects that were used during initialization. You
190
+ must ensure that these type objects have a lifetime at least as long
191
+ as that of the @code{ffi_cif}.
153
192
 
154
193
  To call a function using an initialized @code{ffi_cif}, use the
155
194
  @code{ffi_call} function:
@@ -162,11 +201,21 @@ This calls the function @var{fn} according to the description given in
162
201
 
163
202
  @var{rvalue} is a pointer to a chunk of memory that will hold the
164
203
  result of the function call. This must be large enough to hold the
165
- result and must be suitably aligned; it is the caller's responsibility
204
+ result, no smaller than the system register size (generally 32 or 64
205
+ bits), and must be suitably aligned; it is the caller's responsibility
166
206
  to ensure this. If @var{cif} declares that the function returns
167
207
  @code{void} (using @code{ffi_type_void}), then @var{rvalue} is
168
- ignored. If @var{rvalue} is @samp{NULL}, then the return value is
169
- discarded.
208
+ ignored.
209
+
210
+ In most situations, @samp{libffi} will handle promotion according to
211
+ the ABI. However, for historical reasons, there is a special case
212
+ with return values that must be handled by your code. In particular,
213
+ for integral (not @code{struct}) types that are narrower than the
214
+ system register size, the return value will be widened by
215
+ @samp{libffi}. @samp{libffi} provides a type, @code{ffi_arg}, that
216
+ can be used as the return type. For example, if the CIF was defined
217
+ with a return type of @code{char}, @samp{libffi} will try to store a
218
+ full @code{ffi_arg} into the return value.
170
219
 
171
220
  @var{avalues} is a vector of @code{void *} pointers that point to the
172
221
  memory locations holding the argument values for a call. If @var{cif}
@@ -174,6 +223,13 @@ declares that the function has no arguments (i.e., @var{nargs} was 0),
174
223
  then @var{avalues} is ignored. Note that argument values may be
175
224
  modified by the callee (for instance, structs passed by value); the
176
225
  burden of copying pass-by-value arguments is placed on the caller.
226
+
227
+ Note that while the return value must be register-sized, arguments
228
+ should exactly match their declared type. For example, if an argument
229
+ is a @code{short}, then the entry in @var{avalues} should point to an
230
+ object declared as @code{short}; but if the return type is
231
+ @code{short}, then @var{rvalue} should point to an object declared as
232
+ a larger type -- usually @code{ffi_arg}.
177
233
  @end defun
178
234
 
179
235
 
@@ -192,7 +248,7 @@ int main()
192
248
  ffi_type *args[1];
193
249
  void *values[1];
194
250
  char *s;
195
- int rc;
251
+ ffi_arg rc;
196
252
 
197
253
  /* Initialize the argument info vectors */
198
254
  args[0] = &ffi_type_pointer;
@@ -200,7 +256,7 @@ int main()
200
256
 
201
257
  /* Initialize the cif */
202
258
  if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
203
- &ffi_type_uint, args) == FFI_OK)
259
+ &ffi_type_sint, args) == FFI_OK)
204
260
  @{
205
261
  s = "Hello World!";
206
262
  ffi_call(&cif, puts, &rc, values);
@@ -224,7 +280,11 @@ int main()
224
280
  @menu
225
281
  * Primitive Types:: Built-in types.
226
282
  * Structures:: Structure types.
283
+ * Size and Alignment:: Size and alignment of types.
284
+ * Arrays Unions Enums:: Arrays, unions, and enumerations.
227
285
  * Type Example:: Structure type example.
286
+ * Complex:: Complex types.
287
+ * Complex Type Example:: Complex type example.
228
288
  @end menu
229
289
 
230
290
  @node Primitive Types
@@ -323,6 +383,20 @@ On other platforms, it is not.
323
383
  @tindex ffi_type_pointer
324
384
  A generic @code{void *} pointer. You should use this for all
325
385
  pointers, regardless of their real type.
386
+
387
+ @item ffi_type_complex_float
388
+ @tindex ffi_type_complex_float
389
+ The C @code{_Complex float} type.
390
+
391
+ @item ffi_type_complex_double
392
+ @tindex ffi_type_complex_double
393
+ The C @code{_Complex double} type.
394
+
395
+ @item ffi_type_complex_longdouble
396
+ @tindex ffi_type_complex_longdouble
397
+ The C @code{_Complex long double} type.
398
+ On platforms that have a C @code{long double} type, this is defined.
399
+ On other platforms, it is not.
326
400
  @end table
327
401
 
328
402
  Each of these is of type @code{ffi_type}, so you must take the address
@@ -332,13 +406,12 @@ when passing to @code{ffi_prep_cif}.
332
406
  @node Structures
333
407
  @subsection Structures
334
408
 
335
- Although @samp{libffi} has no special support for unions or
336
- bit-fields, it is perfectly happy passing structures back and forth.
409
+ @samp{libffi} is perfectly happy passing structures back and forth.
337
410
  You must first describe the structure to @samp{libffi} by creating a
338
411
  new @code{ffi_type} object for it.
339
412
 
340
413
  @tindex ffi_type
341
- @deftp ffi_type
414
+ @deftp {Data type} ffi_type
342
415
  The @code{ffi_type} has the following members:
343
416
  @table @code
344
417
  @item size_t size
@@ -353,9 +426,166 @@ For a structure, this should be set to @code{FFI_TYPE_STRUCT}.
353
426
  @item ffi_type **elements
354
427
  This is a @samp{NULL}-terminated array of pointers to @code{ffi_type}
355
428
  objects. There is one element per field of the struct.
429
+
430
+ Note that @samp{libffi} has no special support for bit-fields. You
431
+ must manage these manually.
356
432
  @end table
357
433
  @end deftp
358
434
 
435
+ The @code{size} and @code{alignment} fields will be filled in by
436
+ @code{ffi_prep_cif} or @code{ffi_prep_cif_var}, as needed.
437
+
438
+ @node Size and Alignment
439
+ @subsection Size and Alignment
440
+
441
+ @code{libffi} will set the @code{size} and @code{alignment} fields of
442
+ an @code{ffi_type} object for you. It does so using its knowledge of
443
+ the ABI.
444
+
445
+ You might expect that you can simply read these fields for a type that
446
+ has been laid out by @code{libffi}. However, there are some caveats.
447
+
448
+ @itemize @bullet
449
+ @item
450
+ The size or alignment of some of the built-in types may vary depending
451
+ on the chosen ABI.
452
+
453
+ @item
454
+ The size and alignment of a new structure type will not be set by
455
+ @code{libffi} until it has been passed to @code{ffi_prep_cif} or
456
+ @code{ffi_get_struct_offsets}.
457
+
458
+ @item
459
+ A structure type cannot be shared across ABIs. Instead each ABI needs
460
+ its own copy of the structure type.
461
+ @end itemize
462
+
463
+ So, before examining these fields, it is safest to pass the
464
+ @code{ffi_type} object to @code{ffi_prep_cif} or
465
+ @code{ffi_get_struct_offsets} first. This function will do all the
466
+ needed setup.
467
+
468
+ @example
469
+ ffi_type *desired_type;
470
+ ffi_abi desired_abi;
471
+ @dots{}
472
+ ffi_cif cif;
473
+ if (ffi_prep_cif (&cif, desired_abi, 0, desired_type, NULL) == FFI_OK)
474
+ @{
475
+ size_t size = desired_type->size;
476
+ unsigned short alignment = desired_type->alignment;
477
+ @}
478
+ @end example
479
+
480
+ @code{libffi} also provides a way to get the offsets of the members of
481
+ a structure.
482
+
483
+ @findex ffi_get_struct_offsets
484
+ @defun ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type, size_t *offsets)
485
+ Compute the offset of each element of the given structure type.
486
+ @var{abi} is the ABI to use; this is needed because in some cases the
487
+ layout depends on the ABI.
488
+
489
+ @var{offsets} is an out parameter. The caller is responsible for
490
+ providing enough space for all the results to be written -- one
491
+ element per element type in @var{struct_type}. If @var{offsets} is
492
+ @code{NULL}, then the type will be laid out but not otherwise
493
+ modified. This can be useful for accessing the type's size or layout,
494
+ as mentioned above.
495
+
496
+ This function returns @code{FFI_OK} on success; @code{FFI_BAD_ABI} if
497
+ @var{abi} is invalid; or @code{FFI_BAD_TYPEDEF} if @var{struct_type}
498
+ is invalid in some way. Note that only @code{FFI_STRUCT} types are
499
+ valid here.
500
+ @end defun
501
+
502
+ @node Arrays Unions Enums
503
+ @subsection Arrays, Unions, and Enumerations
504
+
505
+ @subsubsection Arrays
506
+
507
+ @samp{libffi} does not have direct support for arrays or unions.
508
+ However, they can be emulated using structures.
509
+
510
+ To emulate an array, simply create an @code{ffi_type} using
511
+ @code{FFI_TYPE_STRUCT} with as many members as there are elements in
512
+ the array.
513
+
514
+ @example
515
+ ffi_type array_type;
516
+ ffi_type **elements
517
+ int i;
518
+
519
+ elements = malloc ((n + 1) * sizeof (ffi_type *));
520
+ for (i = 0; i < n; ++i)
521
+ elements[i] = array_element_type;
522
+ elements[n] = NULL;
523
+
524
+ array_type.size = array_type.alignment = 0;
525
+ array_type.type = FFI_TYPE_STRUCT;
526
+ array_type.elements = elements;
527
+ @end example
528
+
529
+ Note that arrays cannot be passed or returned by value in C --
530
+ structure types created like this should only be used to refer to
531
+ members of real @code{FFI_TYPE_STRUCT} objects.
532
+
533
+ However, a phony array type like this will not cause any errors from
534
+ @samp{libffi} if you use it as an argument or return type. This may
535
+ be confusing.
536
+
537
+ @subsubsection Unions
538
+
539
+ A union can also be emulated using @code{FFI_TYPE_STRUCT}. In this
540
+ case, however, you must make sure that the size and alignment match
541
+ the real requirements of the union.
542
+
543
+ One simple way to do this is to ensue that each element type is laid
544
+ out. Then, give the new structure type a single element; the size of
545
+ the largest element; and the largest alignment seen as well.
546
+
547
+ This example uses the @code{ffi_prep_cif} trick to ensure that each
548
+ element type is laid out.
549
+
550
+ @example
551
+ ffi_abi desired_abi;
552
+ ffi_type union_type;
553
+ ffi_type **union_elements;
554
+
555
+ int i;
556
+ ffi_type element_types[2];
557
+
558
+ element_types[1] = NULL;
559
+
560
+ union_type.size = union_type.alignment = 0;
561
+ union_type.type = FFI_TYPE_STRUCT;
562
+ union_type.elements = element_types;
563
+
564
+ for (i = 0; union_elements[i]; ++i)
565
+ @{
566
+ ffi_cif cif;
567
+ if (ffi_prep_cif (&cif, desired_abi, 0, union_elements[i], NULL) == FFI_OK)
568
+ @{
569
+ if (union_elements[i]->size > union_type.size)
570
+ @{
571
+ union_type.size = union_elements[i];
572
+ size = union_elements[i]->size;
573
+ @}
574
+ if (union_elements[i]->alignment > union_type.alignment)
575
+ union_type.alignment = union_elements[i]->alignment;
576
+ @}
577
+ @}
578
+ @end example
579
+
580
+ @subsubsection Enumerations
581
+
582
+ @code{libffi} does not have any special support for C @code{enum}s.
583
+ Although any given @code{enum} is implemented using a specific
584
+ underlying integral type, exactly which type will be used cannot be
585
+ determined by @code{libffi} -- it may depend on the values in the
586
+ enumeration or on compiler flags such as @option{-fshort-enums}.
587
+ @xref{Structures unions enumerations and bit-fields implementation, , , gcc},
588
+ for more information about how GCC handles enumerations.
359
589
 
360
590
  @node Type Example
361
591
  @subsection Type Example
@@ -392,6 +622,7 @@ Here is the corresponding code to describe this struct to
392
622
  int i;
393
623
 
394
624
  tm_type.size = tm_type.alignment = 0;
625
+ tm_type.type = FFI_TYPE_STRUCT;
395
626
  tm_type.elements = &tm_type_elements;
396
627
 
397
628
  for (i = 0; i < 9; i++)
@@ -406,6 +637,135 @@ Here is the corresponding code to describe this struct to
406
637
  @}
407
638
  @end example
408
639
 
640
+ @node Complex
641
+ @subsection Complex Types
642
+
643
+ @samp{libffi} supports the complex types defined by the C99
644
+ standard (@code{_Complex float}, @code{_Complex double} and
645
+ @code{_Complex long double} with the built-in type descriptors
646
+ @code{ffi_type_complex_float}, @code{ffi_type_complex_double} and
647
+ @code{ffi_type_complex_longdouble}.
648
+
649
+ Custom complex types like @code{_Complex int} can also be used.
650
+ An @code{ffi_type} object has to be defined to describe the
651
+ complex type to @samp{libffi}.
652
+
653
+ @tindex ffi_type
654
+ @deftp {Data type} ffi_type
655
+ @table @code
656
+ @item size_t size
657
+ This must be manually set to the size of the complex type.
658
+
659
+ @item unsigned short alignment
660
+ This must be manually set to the alignment of the complex type.
661
+
662
+ @item unsigned short type
663
+ For a complex type, this must be set to @code{FFI_TYPE_COMPLEX}.
664
+
665
+ @item ffi_type **elements
666
+
667
+ This is a @samp{NULL}-terminated array of pointers to
668
+ @code{ffi_type} objects. The first element is set to the
669
+ @code{ffi_type} of the complex's base type. The second element
670
+ must be set to @code{NULL}.
671
+ @end table
672
+ @end deftp
673
+
674
+ The section @ref{Complex Type Example} shows a way to determine
675
+ the @code{size} and @code{alignment} members in a platform
676
+ independent way.
677
+
678
+ For platforms that have no complex support in @code{libffi} yet,
679
+ the functions @code{ffi_prep_cif} and @code{ffi_prep_args} abort
680
+ the program if they encounter a complex type.
681
+
682
+ @node Complex Type Example
683
+ @subsection Complex Type Example
684
+
685
+ This example demonstrates how to use complex types:
686
+
687
+ @example
688
+ #include <stdio.h>
689
+ #include <ffi.h>
690
+ #include <complex.h>
691
+
692
+ void complex_fn(_Complex float cf,
693
+ _Complex double cd,
694
+ _Complex long double cld)
695
+ @{
696
+ printf("cf=%f+%fi\ncd=%f+%fi\ncld=%f+%fi\n",
697
+ (float)creal (cf), (float)cimag (cf),
698
+ (float)creal (cd), (float)cimag (cd),
699
+ (float)creal (cld), (float)cimag (cld));
700
+ @}
701
+
702
+ int main()
703
+ @{
704
+ ffi_cif cif;
705
+ ffi_type *args[3];
706
+ void *values[3];
707
+ _Complex float cf;
708
+ _Complex double cd;
709
+ _Complex long double cld;
710
+
711
+ /* Initialize the argument info vectors */
712
+ args[0] = &ffi_type_complex_float;
713
+ args[1] = &ffi_type_complex_double;
714
+ args[2] = &ffi_type_complex_longdouble;
715
+ values[0] = &cf;
716
+ values[1] = &cd;
717
+ values[2] = &cld;
718
+
719
+ /* Initialize the cif */
720
+ if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
721
+ &ffi_type_void, args) == FFI_OK)
722
+ @{
723
+ cf = 1.0 + 20.0 * I;
724
+ cd = 300.0 + 4000.0 * I;
725
+ cld = 50000.0 + 600000.0 * I;
726
+ /* Call the function */
727
+ ffi_call(&cif, (void (*)(void))complex_fn, 0, values);
728
+ @}
729
+
730
+ return 0;
731
+ @}
732
+ @end example
733
+
734
+ This is an example for defining a custom complex type descriptor
735
+ for compilers that support them:
736
+
737
+ @example
738
+ /*
739
+ * This macro can be used to define new complex type descriptors
740
+ * in a platform independent way.
741
+ *
742
+ * name: Name of the new descriptor is ffi_type_complex_<name>.
743
+ * type: The C base type of the complex type.
744
+ */
745
+ #define FFI_COMPLEX_TYPEDEF(name, type, ffitype) \
746
+ static ffi_type *ffi_elements_complex_##name [2] = @{ \
747
+ (ffi_type *)(&ffitype), NULL \
748
+ @}; \
749
+ struct struct_align_complex_##name @{ \
750
+ char c; \
751
+ _Complex type x; \
752
+ @}; \
753
+ ffi_type ffi_type_complex_##name = @{ \
754
+ sizeof(_Complex type), \
755
+ offsetof(struct struct_align_complex_##name, x), \
756
+ FFI_TYPE_COMPLEX, \
757
+ (ffi_type **)ffi_elements_complex_##name \
758
+ @}
759
+
760
+ /* Define new complex type descriptors using the macro: */
761
+ /* ffi_type_complex_sint */
762
+ FFI_COMPLEX_TYPEDEF(sint, int, ffi_type_sint);
763
+ /* ffi_type_complex_uchar */
764
+ FFI_COMPLEX_TYPEDEF(uchar, unsigned char, ffi_type_uint8);
765
+ @end example
766
+
767
+ The new type descriptors can then be used like one of the built-in
768
+ type descriptors in the previous example.
409
769
 
410
770
  @node Multiple ABIs
411
771
  @section Multiple ABIs
@@ -462,30 +822,47 @@ the closure function:
462
822
 
463
823
  @findex ffi_prep_closure_loc
464
824
  @defun ffi_status ffi_prep_closure_loc (ffi_closure *@var{closure}, ffi_cif *@var{cif}, void (*@var{fun}) (ffi_cif *@var{cif}, void *@var{ret}, void **@var{args}, void *@var{user_data}), void *@var{user_data}, void *@var{codeloc})
465
- Prepare a closure function.
825
+ Prepare a closure function. The arguments to
826
+ @code{ffi_prep_closure_loc} are:
466
827
 
467
- @var{closure} is the address of a @code{ffi_closure} object; this is
468
- the writable address returned by @code{ffi_closure_alloc}.
828
+ @table @var
829
+ @item closure
830
+ The address of a @code{ffi_closure} object; this is the writable
831
+ address returned by @code{ffi_closure_alloc}.
469
832
 
470
- @var{cif} is the @code{ffi_cif} describing the function parameters.
833
+ @item cif
834
+ The @code{ffi_cif} describing the function parameters. Note that this
835
+ object, and the types to which it refers, must be kept alive until the
836
+ closure itself is freed.
837
+
838
+ @item user_data
839
+ An arbitrary datum that is passed, uninterpreted, to your closure
840
+ function.
471
841
 
472
- @var{user_data} is an arbitrary datum that is passed, uninterpreted,
473
- to your closure function.
842
+ @item codeloc
843
+ The executable address returned by @code{ffi_closure_alloc}.
474
844
 
475
- @var{codeloc} is the executable address returned by
476
- @code{ffi_closure_alloc}.
845
+ @item fun
846
+ The function which will be called when the closure is invoked. It is
847
+ called with the arguments:
477
848
 
478
- @var{fun} is the function which will be called when the closure is
479
- invoked. It is called with the arguments:
480
849
  @table @var
481
850
  @item cif
482
851
  The @code{ffi_cif} passed to @code{ffi_prep_closure_loc}.
483
852
 
484
853
  @item ret
485
854
  A pointer to the memory used for the function's return value.
486
- @var{fun} must fill this, unless the function is declared as returning
487
- @code{void}.
488
- @c FIXME: is this NULL for void-returning functions?
855
+
856
+ If the function is declared as returning @code{void}, then this value
857
+ is garbage and should not be used.
858
+
859
+ Otherwise, @var{fun} must fill the object to which this points,
860
+ following the same special promotion behavior as @code{ffi_call}.
861
+ That is, in most cases, @var{ret} points to an object of exactly the
862
+ size of the type specified when @var{cif} was constructed. However,
863
+ integral types narrower than the system register size are widened. In
864
+ these cases your program may assume that @var{ret} points to an
865
+ @code{ffi_arg} object.
489
866
 
490
867
  @item args
491
868
  A vector of pointers to memory holding the arguments to the function.
@@ -494,10 +871,10 @@ A vector of pointers to memory holding the arguments to the function.
494
871
  The same @var{user_data} that was passed to
495
872
  @code{ffi_prep_closure_loc}.
496
873
  @end table
874
+ @end table
497
875
 
498
876
  @code{ffi_prep_closure_loc} will return @code{FFI_OK} if everything
499
- went ok, and something else on error.
500
- @c FIXME: what?
877
+ went ok, and one of the other @code{ffi_status} values on error.
501
878
 
502
879
  After calling @code{ffi_prep_closure_loc}, you can cast @var{codeloc}
503
880
  to the appropriate pointer-to-function type.
@@ -511,28 +888,30 @@ writable and executable addresses.
511
888
  @section Closure Example
512
889
 
513
890
  A trivial example that creates a new @code{puts} by binding
514
- @code{fputs} with @code{stdin}.
891
+ @code{fputs} with @code{stdout}.
515
892
 
516
893
  @example
517
894
  #include <stdio.h>
518
895
  #include <ffi.h>
519
896
 
520
897
  /* Acts like puts with the file given at time of enclosure. */
521
- void puts_binding(ffi_cif *cif, unsigned int *ret, void* args[],
522
- FILE *stream)
898
+ void puts_binding(ffi_cif *cif, void *ret, void* args[],
899
+ void *stream)
523
900
  @{
524
- *ret = fputs(*(char **)args[0], stream);
901
+ *(ffi_arg *)ret = fputs(*(char **)args[0], (FILE *)stream);
525
902
  @}
526
903
 
904
+ typedef int (*puts_t)(char *);
905
+
527
906
  int main()
528
907
  @{
529
908
  ffi_cif cif;
530
909
  ffi_type *args[1];
531
910
  ffi_closure *closure;
532
911
 
533
- int (*bound_puts)(char *);
912
+ void *bound_puts;
534
913
  int rc;
535
-
914
+
536
915
  /* Allocate closure and bound_puts */
537
916
  closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);
538
917
 
@@ -543,13 +922,13 @@ int main()
543
922
 
544
923
  /* Initialize the cif */
545
924
  if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
546
- &ffi_type_uint, args) == FFI_OK)
925
+ &ffi_type_sint, args) == FFI_OK)
547
926
  @{
548
927
  /* Initialize the closure, setting stream to stdout */
549
- if (ffi_prep_closure_loc(closure, &cif, puts_binding,
928
+ if (ffi_prep_closure_loc(closure, &cif, puts_binding,
550
929
  stdout, bound_puts) == FFI_OK)
551
930
  @{
552
- rc = bound_puts("Hello World!");
931
+ rc = ((puts_t)bound_puts)("Hello World!");
553
932
  /* rc now holds the result of the call to fputs */
554
933
  @}
555
934
  @}
@@ -563,6 +942,28 @@ int main()
563
942
 
564
943
  @end example
565
944
 
945
+ @node Thread Safety
946
+ @section Thread Safety
947
+
948
+ @code{libffi} is not completely thread-safe. However, many parts are,
949
+ and if you follow some simple rules, you can use it safely in a
950
+ multi-threaded program.
951
+
952
+ @itemize @bullet
953
+ @item
954
+ @code{ffi_prep_cif} may modify the @code{ffi_type} objects passed to
955
+ it. It is best to ensure that only a single thread prepares a given
956
+ @code{ffi_cif} at a time.
957
+
958
+ @item
959
+ On some platforms, @code{ffi_prep_cif} may modify the size and
960
+ alignment of some types, depending on the chosen ABI. On these
961
+ platforms, if you switch between ABIs, you must ensure that there is
962
+ only one call to @code{ffi_prep_cif} at a time.
963
+
964
+ Currently the only affected platform is PowerPC and the only affected
965
+ type is @code{long double}.
966
+ @end itemize
566
967
 
567
968
  @node Missing Features
568
969
  @chapter Missing Features
@@ -572,25 +973,21 @@ support for these.
572
973
 
573
974
  @itemize @bullet
574
975
  @item
575
- There is no support for calling varargs functions. This may work on
576
- some platforms, depending on how the ABI is defined, but it is not
577
- reliable.
976
+ Variadic closures.
578
977
 
579
978
  @item
580
979
  There is no support for bit fields in structures.
581
980
 
582
- @item
583
- The closure API is
584
-
585
- @c FIXME: ...
586
-
587
981
  @item
588
982
  The ``raw'' API is undocumented.
589
- @c argument promotion?
590
- @c unions?
591
983
  @c anything else?
984
+
985
+ @item
986
+ The Go API is undocumented.
592
987
  @end itemize
593
988
 
989
+ Note that variadic support is very new and tested on a relatively
990
+ small number of platforms.
594
991
 
595
992
  @node Index
596
993
  @unnumbered Index