ffi 1.1.2 → 1.17.0

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