ffi 1.15.4 → 1.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (312) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +90 -0
  4. data/Gemfile +1 -1
  5. data/README.md +3 -2
  6. data/Rakefile +28 -11
  7. data/ext/ffi_c/AbstractMemory.c +60 -36
  8. data/ext/ffi_c/AbstractMemory.h +3 -2
  9. data/ext/ffi_c/ArrayType.c +49 -13
  10. data/ext/ffi_c/ArrayType.h +1 -0
  11. data/ext/ffi_c/Buffer.c +86 -29
  12. data/ext/ffi_c/Call.c +18 -7
  13. data/ext/ffi_c/DynamicLibrary.c +89 -26
  14. data/ext/ffi_c/Function.c +244 -98
  15. data/ext/ffi_c/Function.h +1 -0
  16. data/ext/ffi_c/FunctionInfo.c +80 -24
  17. data/ext/ffi_c/LastError.c +25 -7
  18. data/ext/ffi_c/MappedType.c +66 -23
  19. data/ext/ffi_c/MappedType.h +0 -2
  20. data/ext/ffi_c/MemoryPointer.c +34 -7
  21. data/ext/ffi_c/MethodHandle.c +3 -1
  22. data/ext/ffi_c/Pointer.c +68 -29
  23. data/ext/ffi_c/Pointer.h +1 -0
  24. data/ext/ffi_c/Struct.c +155 -80
  25. data/ext/ffi_c/Struct.h +7 -4
  26. data/ext/ffi_c/StructByValue.c +48 -16
  27. data/ext/ffi_c/StructLayout.c +117 -48
  28. data/ext/ffi_c/Type.c +104 -36
  29. data/ext/ffi_c/Type.h +3 -1
  30. data/ext/ffi_c/Types.c +1 -1
  31. data/ext/ffi_c/Variadic.c +65 -23
  32. data/ext/ffi_c/compat.h +22 -22
  33. data/ext/ffi_c/extconf.rb +19 -2
  34. data/ext/ffi_c/ffi.c +4 -0
  35. data/ext/ffi_c/libffi/.appveyor/site.exp +16 -0
  36. data/ext/ffi_c/libffi/.appveyor/unix-noexec.exp +7 -0
  37. data/ext/ffi_c/libffi/.appveyor.yml +27 -9
  38. data/ext/ffi_c/libffi/.ci/build-cross-in-container.sh +18 -0
  39. data/ext/ffi_c/libffi/{.travis → .ci}/build-in-container.sh +4 -6
  40. data/ext/ffi_c/libffi/.ci/build.sh +124 -0
  41. data/ext/ffi_c/libffi/{.travis → .ci}/install.sh +14 -7
  42. data/ext/ffi_c/libffi/.ci/msvs-detect +1103 -0
  43. data/ext/ffi_c/libffi/{.travis → .ci}/site.exp +5 -3
  44. data/ext/ffi_c/libffi/.circleci/config.yml +156 -0
  45. data/ext/ffi_c/libffi/.github/workflows/build.yml +460 -0
  46. data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +171 -0
  47. data/ext/ffi_c/libffi/.gitignore +10 -2
  48. data/ext/ffi_c/libffi/LICENSE +1 -1
  49. data/ext/ffi_c/libffi/Makefile.am +12 -5
  50. data/ext/ffi_c/libffi/Makefile.in +92 -34
  51. data/ext/ffi_c/libffi/README.md +144 -104
  52. data/ext/ffi_c/libffi/acinclude.m4 +10 -112
  53. data/ext/ffi_c/libffi/compile +348 -0
  54. data/ext/ffi_c/libffi/config.guess +623 -556
  55. data/ext/ffi_c/libffi/config.sub +75 -34
  56. data/ext/ffi_c/libffi/configure +4567 -3822
  57. data/ext/ffi_c/libffi/configure.ac +64 -28
  58. data/ext/ffi_c/libffi/configure.host +25 -6
  59. data/ext/ffi_c/libffi/doc/Makefile.in +9 -6
  60. data/ext/ffi_c/libffi/doc/libffi.texi +82 -33
  61. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  62. data/ext/ffi_c/libffi/fficonfig.h.in +12 -47
  63. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +163 -52
  64. data/ext/ffi_c/libffi/include/Makefile.am +1 -1
  65. data/ext/ffi_c/libffi/include/Makefile.in +10 -9
  66. data/ext/ffi_c/libffi/include/ffi.h.in +54 -50
  67. data/ext/ffi_c/libffi/include/ffi_cfi.h +21 -0
  68. data/ext/ffi_c/libffi/include/ffi_common.h +29 -0
  69. data/ext/ffi_c/libffi/include/tramp.h +45 -0
  70. data/ext/ffi_c/libffi/libtool-version +2 -2
  71. data/ext/ffi_c/libffi/ltmain.sh +512 -315
  72. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +18 -14
  73. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +108 -72
  74. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +76 -45
  75. data/ext/ffi_c/libffi/m4/ax_prepend_flag.m4 +51 -0
  76. data/ext/ffi_c/libffi/man/Makefile.in +9 -6
  77. data/ext/ffi_c/libffi/missing +1 -1
  78. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +1 -1
  79. data/ext/ffi_c/libffi/msvcc.sh +1 -1
  80. data/ext/ffi_c/libffi/src/aarch64/ffi.c +146 -42
  81. data/ext/ffi_c/libffi/src/aarch64/internal.h +32 -0
  82. data/ext/ffi_c/libffi/src/aarch64/sysv.S +134 -42
  83. data/ext/ffi_c/libffi/src/arc/arcompact.S +169 -94
  84. data/ext/ffi_c/libffi/src/arc/ffi.c +325 -148
  85. data/ext/ffi_c/libffi/src/arc/ffitarget.h +14 -0
  86. data/ext/ffi_c/libffi/src/arm/ffi.c +62 -17
  87. data/ext/ffi_c/libffi/src/arm/ffitarget.h +3 -3
  88. data/ext/ffi_c/libffi/src/arm/internal.h +10 -0
  89. data/ext/ffi_c/libffi/src/arm/sysv.S +113 -42
  90. data/ext/ffi_c/libffi/src/closures.c +133 -47
  91. data/ext/ffi_c/libffi/src/dlmalloc.c +5 -0
  92. data/ext/ffi_c/libffi/src/ia64/ffi.c +12 -0
  93. data/ext/ffi_c/libffi/src/ia64/unix.S +20 -2
  94. data/ext/ffi_c/libffi/src/loongarch64/ffi.c +621 -0
  95. data/ext/ffi_c/libffi/src/loongarch64/ffitarget.h +82 -0
  96. data/ext/ffi_c/libffi/src/loongarch64/sysv.S +327 -0
  97. data/ext/ffi_c/libffi/src/m32r/ffi.c +31 -14
  98. data/ext/ffi_c/libffi/src/mips/ffi.c +240 -65
  99. data/ext/ffi_c/libffi/src/mips/ffitarget.h +7 -0
  100. data/ext/ffi_c/libffi/src/mips/n32.S +137 -28
  101. data/ext/ffi_c/libffi/src/mips/o32.S +61 -4
  102. data/ext/ffi_c/libffi/src/moxie/ffi.c +47 -22
  103. data/ext/ffi_c/libffi/src/or1k/ffi.c +25 -12
  104. data/ext/ffi_c/libffi/src/pa/ffi.c +32 -33
  105. data/ext/ffi_c/libffi/src/pa/ffi64.c +614 -0
  106. data/ext/ffi_c/libffi/src/pa/ffitarget.h +22 -8
  107. data/ext/ffi_c/libffi/src/pa/hpux32.S +83 -36
  108. data/ext/ffi_c/libffi/src/pa/hpux64.S +681 -0
  109. data/ext/ffi_c/libffi/src/pa/linux.S +82 -35
  110. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1 -1
  111. data/ext/ffi_c/libffi/src/powerpc/linux64.S +2 -0
  112. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +2 -0
  113. data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
  114. data/ext/ffi_c/libffi/src/prep_cif.c +22 -2
  115. data/ext/ffi_c/libffi/src/riscv/ffi.c +37 -4
  116. data/ext/ffi_c/libffi/src/sparc/ffi64.c +16 -0
  117. data/ext/ffi_c/libffi/src/tramp.c +716 -0
  118. data/ext/ffi_c/libffi/src/wasm32/ffi.c +934 -0
  119. data/ext/ffi_c/libffi/src/wasm32/ffitarget.h +62 -0
  120. data/ext/ffi_c/libffi/src/x86/ffi.c +99 -37
  121. data/ext/ffi_c/libffi/src/x86/ffi64.c +67 -12
  122. data/ext/ffi_c/libffi/src/x86/ffitarget.h +9 -5
  123. data/ext/ffi_c/libffi/src/x86/ffiw64.c +43 -0
  124. data/ext/ffi_c/libffi/src/x86/internal.h +14 -0
  125. data/ext/ffi_c/libffi/src/x86/internal64.h +14 -0
  126. data/ext/ffi_c/libffi/src/x86/sysv.S +172 -38
  127. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +91 -88
  128. data/ext/ffi_c/libffi/src/x86/unix64.S +96 -6
  129. data/ext/ffi_c/libffi/src/x86/win64.S +20 -7
  130. data/ext/ffi_c/libffi/src/xtensa/ffi.c +16 -8
  131. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +4 -0
  132. data/ext/ffi_c/libffi/src/xtensa/sysv.S +26 -16
  133. data/ext/ffi_c/libffi/testsuite/Makefile.am +127 -114
  134. data/ext/ffi_c/libffi/testsuite/Makefile.in +136 -120
  135. data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +54 -0
  136. data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +63 -0
  137. data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +80 -0
  138. data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +48 -0
  139. data/ext/ffi_c/libffi/testsuite/emscripten/test.html +7 -0
  140. data/ext/ffi_c/libffi/testsuite/emscripten/test_libffi.py +51 -0
  141. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +43 -21
  142. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +2 -2
  143. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1 -0
  144. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +5 -1
  145. data/ext/ffi_c/libffi/testsuite/libffi.call/bpo_38748.c +41 -0
  146. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +28 -3
  147. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +3 -0
  148. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +5 -0
  149. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +4 -0
  150. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +4 -0
  151. data/ext/ffi_c/libffi/testsuite/libffi.call/s55.c +60 -0
  152. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +8 -9
  153. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +2 -2
  154. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +2 -2
  155. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +2 -2
  156. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +1 -1
  157. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_2.c +63 -0
  158. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3.c +65 -0
  159. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3f.c +65 -0
  160. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4.c +67 -0
  161. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4f.c +67 -0
  162. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_big.c +93 -0
  163. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_small.c +61 -0
  164. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_2H.c +63 -0
  165. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_8H.c +90 -0
  166. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -119
  167. data/ext/ffi_c/libffi/testsuite/libffi.call/va_2.c +220 -0
  168. data/ext/ffi_c/libffi/testsuite/libffi.call/va_3.c +154 -0
  169. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +13 -0
  170. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +11 -0
  171. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +15 -0
  172. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn0.c +3 -2
  173. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn1.c +2 -0
  174. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn2.c +2 -0
  175. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn3.c +21 -1
  176. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn4.c +2 -0
  177. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn5.c +2 -0
  178. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn6.c +2 -0
  179. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_loc_fn0.c +7 -6
  180. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_simple.c +6 -0
  181. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_12byte.c +18 -0
  182. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_16byte.c +22 -0
  183. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_18byte.c +24 -0
  184. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_19byte.c +29 -0
  185. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_1_1byte.c +4 -0
  186. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte.c +19 -1
  187. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte1.c +21 -1
  188. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_24byte.c +35 -3
  189. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_2byte.c +13 -0
  190. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3_1byte.c +19 -0
  191. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte1.c +13 -0
  192. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte2.c +13 -0
  193. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +18 -0
  194. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4_1byte.c +22 -0
  195. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4byte.c +13 -0
  196. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5_1_byte.c +29 -1
  197. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5byte.c +19 -1
  198. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_64byte.c +24 -0
  199. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6_1_byte.c +28 -1
  200. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6byte.c +24 -2
  201. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7_1_byte.c +39 -1
  202. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7byte.c +25 -1
  203. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_8byte.c +14 -0
  204. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte1.c +14 -1
  205. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte2.c +14 -2
  206. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_double.c +19 -1
  207. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_float.c +19 -1
  208. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble.c +20 -1
  209. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split.c +40 -25
  210. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split2.c +40 -3
  211. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_pointer.c +19 -1
  212. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint16.c +18 -1
  213. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint32.c +18 -3
  214. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint64.c +18 -1
  215. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint16.c +18 -1
  216. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint32.c +19 -1
  217. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint64.c +19 -1
  218. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_dbls_struct.c +3 -1
  219. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_double_va.c +9 -1
  220. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_float.c +4 -0
  221. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble.c +11 -1
  222. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble_va.c +22 -3
  223. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_schar.c +5 -1
  224. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshort.c +6 -1
  225. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshortchar.c +9 -1
  226. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_uchar.c +9 -1
  227. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushort.c +6 -2
  228. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushortchar.c +9 -1
  229. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer.c +5 -0
  230. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer_stack.c +10 -0
  231. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_schar.c +3 -0
  232. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sint.c +2 -0
  233. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sshort.c +3 -0
  234. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +11 -0
  235. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar.c +3 -0
  236. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint.c +4 -0
  237. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +4 -0
  238. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +4 -0
  239. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulonglong.c +2 -0
  240. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort.c +3 -0
  241. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +1 -138
  242. data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +21 -21
  243. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct.c +32 -9
  244. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct1.c +1 -1
  245. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct10.c +12 -0
  246. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +21 -5
  247. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct12.c +86 -0
  248. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct13.c +115 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct2.c +10 -1
  250. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct3.c +10 -1
  251. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct4.c +9 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct5.c +9 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct6.c +11 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct7.c +9 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct8.c +11 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct9.c +11 -0
  257. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs1.c +86 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs2.c +102 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs3.c +101 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium.c +1 -1
  261. data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium2.c +1 -1
  262. data/ext/ffi_c/libffi/testsuite/libffi.closures/testclosure.c +6 -1
  263. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest.cc +2 -1
  264. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest_ffi_call.cc +1 -0
  265. data/ext/ffi_c/libffi.bsd.mk +2 -2
  266. data/ext/ffi_c/libffi.gnu.mk +2 -2
  267. data/ext/ffi_c/rbffi.h +1 -1
  268. data/ffi.gemspec +3 -3
  269. data/lib/ffi/autopointer.rb +7 -22
  270. data/lib/ffi/compat.rb +43 -0
  271. data/lib/ffi/data_converter.rb +2 -2
  272. data/lib/ffi/dynamic_library.rb +89 -0
  273. data/lib/ffi/enum.rb +18 -11
  274. data/lib/ffi/ffi.rb +3 -0
  275. data/lib/ffi/function.rb +71 -0
  276. data/lib/ffi/library.rb +55 -71
  277. data/lib/ffi/library_path.rb +109 -0
  278. data/lib/ffi/managedstruct.rb +1 -1
  279. data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
  280. data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
  281. data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
  282. data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
  283. data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
  284. data/lib/ffi/platform.rb +15 -13
  285. data/lib/ffi/struct.rb +2 -1
  286. data/lib/ffi/struct_layout.rb +1 -1
  287. data/lib/ffi/struct_layout_builder.rb +1 -1
  288. data/lib/ffi/tools/const_generator.rb +5 -4
  289. data/lib/ffi/types.rb +32 -6
  290. data/lib/ffi/variadic.rb +19 -8
  291. data/lib/ffi/version.rb +1 -1
  292. data/rakelib/ffi_gem_helper.rb +1 -1
  293. data/samples/hello_ractor.rb +11 -0
  294. data/samples/qsort_ractor.rb +28 -0
  295. data.tar.gz.sig +0 -0
  296. metadata +103 -28
  297. metadata.gz.sig +0 -0
  298. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +0 -14
  299. data/ext/ffi_c/libffi/.travis/build.sh +0 -142
  300. data/ext/ffi_c/libffi/.travis.yml +0 -83
  301. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +0 -44
  302. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +0 -44
  303. /data/ext/ffi_c/libffi/{.travis → .ci}/ar-lib +0 -0
  304. /data/ext/ffi_c/libffi/{.travis → .ci}/bfin-sim.exp +0 -0
  305. /data/ext/ffi_c/libffi/{.travis → .ci}/compile +0 -0
  306. /data/ext/ffi_c/libffi/{.travis → .ci}/m32r-sim.exp +0 -0
  307. /data/ext/ffi_c/libffi/{.travis → .ci}/moxie-sim.exp +0 -0
  308. /data/ext/ffi_c/libffi/{.travis → .ci}/or1k-sim.exp +0 -0
  309. /data/ext/ffi_c/libffi/{.travis → .ci}/powerpc-eabisim.exp +0 -0
  310. /data/ext/ffi_c/libffi/{.travis → .ci}/wine-sim.exp +0 -0
  311. /data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
  312. /data/lib/ffi/platform/{sparc64-linux → sparcv9-linux}/types.conf +0 -0
data/ext/ffi_c/Type.c CHANGED
@@ -14,7 +14,7 @@
14
14
  * * Neither the name of the Ruby FFI project nor the
15
15
  * names of its contributors may be used to endorse or promote products
16
16
  * derived from this software without specific prior written permission.
17
- *
17
+ *
18
18
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
19
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
20
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -33,36 +33,74 @@
33
33
 
34
34
  #include <sys/types.h>
35
35
  #include <ruby.h>
36
+ #if HAVE_RB_EXT_RACTOR_SAFE
37
+ #include <ruby/ractor.h>
38
+ #endif
36
39
  #include <ffi.h>
37
40
  #include "rbffi.h"
38
41
  #include "compat.h"
39
42
  #include "Types.h"
40
43
  #include "Type.h"
41
44
 
45
+ static size_t type_memsize(const void *);
42
46
 
43
47
  typedef struct BuiltinType_ {
44
48
  Type type;
45
- char* name;
49
+ const char* name;
46
50
  } BuiltinType;
47
51
 
48
- static void builtin_type_free(BuiltinType *);
52
+ static size_t builtin_type_memsize(const void *);
49
53
 
50
54
  VALUE rbffi_TypeClass = Qnil;
51
55
 
52
56
  static VALUE classBuiltinType = Qnil;
53
57
  static VALUE moduleNativeType = Qnil;
54
- static VALUE typeMap = Qnil, sizeMap = Qnil;
55
- static ID id_find_type = 0, id_type_size = 0, id_size = 0;
58
+ static VALUE typeMap = Qnil;
59
+ static ID id_type_size = 0, id_size = 0;
60
+ #if HAVE_RB_EXT_RACTOR_SAFE
61
+ static rb_ractor_local_key_t custom_typedefs_key;
62
+ #endif
63
+
64
+ const rb_data_type_t rbffi_type_data_type = { /* extern */
65
+ .wrap_struct_name = "FFI::Type",
66
+ .function = {
67
+ .dmark = NULL,
68
+ .dfree = RUBY_TYPED_DEFAULT_FREE,
69
+ .dsize = type_memsize,
70
+ },
71
+ // IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
72
+ // macro to update VALUE references, as to trigger write barriers.
73
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
74
+ };
75
+
76
+ static const rb_data_type_t builtin_type_data_type = {
77
+ .wrap_struct_name = "FFI::Type::Builtin",
78
+ .function = {
79
+ .dmark = NULL,
80
+ .dfree = RUBY_TYPED_DEFAULT_FREE,
81
+ .dsize = builtin_type_memsize,
82
+ },
83
+ .parent = &rbffi_type_data_type,
84
+ // IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
85
+ // macro to update VALUE references, as to trigger write barriers.
86
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
87
+ };
88
+
89
+ static size_t
90
+ type_memsize(const void *data)
91
+ {
92
+ return sizeof(Type);
93
+ }
56
94
 
57
95
  static VALUE
58
96
  type_allocate(VALUE klass)
59
97
  {
60
98
  Type* type;
61
- VALUE obj = Data_Make_Struct(klass, Type, NULL, -1, type);
99
+ VALUE obj = TypedData_Make_Struct(klass, Type, &rbffi_type_data_type, type);
62
100
 
63
101
  type->nativeType = -1;
64
102
  type->ffiType = &ffi_type_void;
65
-
103
+
66
104
  return obj;
67
105
  }
68
106
 
@@ -78,18 +116,20 @@ type_initialize(VALUE self, VALUE value)
78
116
  Type* type;
79
117
  Type* other;
80
118
 
81
- Data_Get_Struct(self, Type, type);
119
+ TypedData_Get_Struct(self, Type, &rbffi_type_data_type, type);
82
120
 
83
121
  if (FIXNUM_P(value)) {
84
122
  type->nativeType = FIX2INT(value);
85
123
  } else if (rb_obj_is_kind_of(value, rbffi_TypeClass)) {
86
- Data_Get_Struct(value, Type, other);
124
+ TypedData_Get_Struct(value, Type, &rbffi_type_data_type, other);
87
125
  type->nativeType = other->nativeType;
88
126
  type->ffiType = other->ffiType;
89
127
  } else {
90
128
  rb_raise(rb_eArgError, "wrong type");
91
129
  }
92
-
130
+
131
+ rb_obj_freeze(self);
132
+
93
133
  return self;
94
134
  }
95
135
 
@@ -103,7 +143,7 @@ type_size(VALUE self)
103
143
  {
104
144
  Type *type;
105
145
 
106
- Data_Get_Struct(self, Type, type);
146
+ TypedData_Get_Struct(self, Type, &rbffi_type_data_type, type);
107
147
 
108
148
  return INT2FIX(type->ffiType->size);
109
149
  }
@@ -118,7 +158,7 @@ type_alignment(VALUE self)
118
158
  {
119
159
  Type *type;
120
160
 
121
- Data_Get_Struct(self, Type, type);
161
+ TypedData_Get_Struct(self, Type, &rbffi_type_data_type, type);
122
162
 
123
163
  return INT2FIX(type->ffiType->alignment);
124
164
  }
@@ -134,9 +174,9 @@ type_inspect(VALUE self)
134
174
  char buf[100];
135
175
  Type *type;
136
176
 
137
- Data_Get_Struct(self, Type, type);
177
+ TypedData_Get_Struct(self, Type, &rbffi_type_data_type, type);
138
178
 
139
- snprintf(buf, sizeof(buf), "#<%s:%p size=%d alignment=%d>",
179
+ snprintf(buf, sizeof(buf), "#<%s::%p size=%d alignment=%d>",
140
180
  rb_obj_classname(self), type, (int) type->ffiType->size, (int) type->ffiType->alignment);
141
181
 
142
182
  return rb_str_new2(buf);
@@ -148,20 +188,21 @@ builtin_type_new(VALUE klass, int nativeType, ffi_type* ffiType, const char* nam
148
188
  BuiltinType* type;
149
189
  VALUE obj = Qnil;
150
190
 
151
- obj = Data_Make_Struct(klass, BuiltinType, NULL, builtin_type_free, type);
152
-
153
- type->name = strdup(name);
191
+ obj = TypedData_Make_Struct(klass, BuiltinType, &builtin_type_data_type, type);
192
+
193
+ type->name = name;
154
194
  type->type.nativeType = nativeType;
155
195
  type->type.ffiType = ffiType;
156
196
 
197
+ rb_obj_freeze(obj);
198
+
157
199
  return obj;
158
200
  }
159
201
 
160
- static void
161
- builtin_type_free(BuiltinType *type)
202
+ static size_t
203
+ builtin_type_memsize(const void *data)
162
204
  {
163
- free(type->name);
164
- xfree(type);
205
+ return sizeof(BuiltinType) + sizeof(ffi_type);
165
206
  }
166
207
 
167
208
  /*
@@ -175,8 +216,8 @@ builtin_type_inspect(VALUE self)
175
216
  char buf[100];
176
217
  BuiltinType *type;
177
218
 
178
- Data_Get_Struct(self, BuiltinType, type);
179
- snprintf(buf, sizeof(buf), "#<%s:%s size=%d alignment=%d>",
219
+ TypedData_Get_Struct(self, BuiltinType, &builtin_type_data_type, type);
220
+ snprintf(buf, sizeof(buf), "#<%s::%s size=%d alignment=%d>",
180
221
  rb_obj_classname(self), type->name, (int) type->type.ffiType->size, type->type.ffiType->alignment);
181
222
 
182
223
  return rb_str_new2(buf);
@@ -186,21 +227,21 @@ int
186
227
  rbffi_type_size(VALUE type)
187
228
  {
188
229
  int t = TYPE(type);
189
-
230
+
190
231
  if (t == T_FIXNUM || t == T_BIGNUM) {
191
232
  return NUM2INT(type);
192
-
233
+
193
234
  } else if (t == T_SYMBOL) {
194
235
  /*
195
- * Try looking up directly in the type and size maps
236
+ * Try looking up directly in the type map
196
237
  */
197
238
  VALUE nType;
198
239
  if ((nType = rb_hash_lookup(typeMap, type)) != Qnil) {
199
240
  if (rb_obj_is_kind_of(nType, rbffi_TypeClass)) {
200
241
  Type* type;
201
- Data_Get_Struct(nType, Type, type);
242
+ TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
202
243
  return (int) type->ffiType->size;
203
-
244
+
204
245
  } else if (rb_respond_to(nType, id_size)) {
205
246
  return NUM2INT(rb_funcall2(nType, id_size, 0, NULL));
206
247
  }
@@ -208,26 +249,51 @@ rbffi_type_size(VALUE type)
208
249
 
209
250
  /* Not found - call up to the ruby version to resolve */
210
251
  return NUM2INT(rb_funcall2(rbffi_FFIModule, id_type_size, 1, &type));
211
-
252
+
212
253
  } else {
213
254
  return NUM2INT(rb_funcall2(type, id_size, 0, NULL));
214
255
  }
215
256
  }
216
257
 
258
+ static VALUE
259
+ custom_typedefs(VALUE self)
260
+ {
261
+ #if HAVE_RB_EXT_RACTOR_SAFE
262
+ VALUE hash = rb_ractor_local_storage_value(custom_typedefs_key);
263
+ if (hash == Qnil) {
264
+ hash = rb_hash_new();
265
+ rb_ractor_local_storage_value_set(custom_typedefs_key, hash);
266
+ }
267
+ #else
268
+ static VALUE hash = Qundef;
269
+ if (hash == Qundef) {
270
+ rb_global_variable(&hash);
271
+ hash = rb_hash_new();
272
+ }
273
+ #endif
274
+ return hash;
275
+ }
276
+
217
277
  VALUE
218
278
  rbffi_Type_Lookup(VALUE name)
219
279
  {
220
280
  int t = TYPE(name);
221
281
  if (t == T_SYMBOL || t == T_STRING) {
222
282
  /*
223
- * Try looking up directly in the type Map
283
+ * Try looking up directly in the type map
224
284
  */
225
285
  VALUE nType;
286
+ VALUE cust = custom_typedefs(Qnil);
287
+
288
+ if ((nType = rb_hash_lookup(cust, name)) != Qnil && rb_obj_is_kind_of(nType, rbffi_TypeClass)) {
289
+ return nType;
290
+ }
291
+
226
292
  if ((nType = rb_hash_lookup(typeMap, name)) != Qnil && rb_obj_is_kind_of(nType, rbffi_TypeClass)) {
227
293
  return nType;
228
294
  }
229
295
  } else if (rb_obj_is_kind_of(name, rbffi_TypeClass)) {
230
-
296
+
231
297
  return name;
232
298
  }
233
299
 
@@ -251,13 +317,15 @@ rbffi_Type_Init(VALUE moduleFFI)
251
317
  * Document-constant: FFI::TypeDefs
252
318
  */
253
319
  rb_define_const(moduleFFI, "TypeDefs", typeMap = rb_hash_new());
254
- rb_define_const(moduleFFI, "SizeTypes", sizeMap = rb_hash_new());
255
320
  rb_global_variable(&typeMap);
256
- rb_global_variable(&sizeMap);
257
- id_find_type = rb_intern("find_type");
258
321
  id_type_size = rb_intern("type_size");
259
322
  id_size = rb_intern("size");
260
323
 
324
+ #if HAVE_RB_EXT_RACTOR_SAFE
325
+ custom_typedefs_key = rb_ractor_local_storage_value_newkey();
326
+ #endif
327
+ rb_define_module_function(moduleFFI, "custom_typedefs", custom_typedefs, 0);
328
+
261
329
  /*
262
330
  * Document-class: FFI::Type::Builtin
263
331
  * Class for Built-in types.
@@ -297,7 +365,7 @@ rbffi_Type_Init(VALUE moduleFFI)
297
365
  * * BUFFER_OUT
298
366
  * * VARARGS (function takes a variable number of arguments)
299
367
  *
300
- * All these constants are exported to {FFI} module prefixed with "TYPE_".
368
+ * All these constants are exported to {FFI} module prefixed with "TYPE_".
301
369
  * They are objets from {FFI::Type::Builtin} class.
302
370
  */
303
371
  moduleNativeType = rb_define_module_under(moduleFFI, "NativeType");
@@ -318,7 +386,7 @@ rbffi_Type_Init(VALUE moduleFFI)
318
386
  /* Make Type::Builtin non-allocatable */
319
387
  rb_undef_method(CLASS_OF(classBuiltinType), "new");
320
388
  rb_define_method(classBuiltinType, "inspect", builtin_type_inspect, 0);
321
-
389
+
322
390
  rb_global_variable(&rbffi_TypeClass);
323
391
  rb_global_variable(&classBuiltinType);
324
392
 
data/ext/ffi_c/Type.h CHANGED
@@ -44,7 +44,7 @@ extern "C" {
44
44
  typedef struct Type_ Type;
45
45
 
46
46
  #include "Types.h"
47
-
47
+
48
48
  struct Type_ {
49
49
  NativeType nativeType;
50
50
  ffi_type* ffiType;
@@ -53,6 +53,8 @@ struct Type_ {
53
53
  extern VALUE rbffi_TypeClass;
54
54
  extern VALUE rbffi_Type_Lookup(VALUE type);
55
55
 
56
+ extern const rb_data_type_t rbffi_type_data_type;
57
+
56
58
  #ifdef __cplusplus
57
59
  }
58
60
  #endif
data/ext/ffi_c/Types.c CHANGED
@@ -97,7 +97,7 @@ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr)
97
97
  AbstractMemory* mem;
98
98
  VALUE rbMemory = rbffi_MemoryPointer_NewInstance(1, sbv->base.ffiType->size, false);
99
99
 
100
- Data_Get_Struct(rbMemory, AbstractMemory, mem);
100
+ TypedData_Get_Struct(rbMemory, AbstractMemory, &rbffi_abstract_memory_data_type, mem);
101
101
  memcpy(mem->address, ptr, sbv->base.ffiType->size);
102
102
  RB_GC_GUARD(rbMemory);
103
103
  RB_GC_GUARD(rbType);
data/ext/ffi_c/Variadic.c CHANGED
@@ -36,6 +36,9 @@
36
36
  #include <stdint.h>
37
37
  #include <stdbool.h>
38
38
  #include <ruby.h>
39
+ #if HAVE_RB_EXT_RACTOR_SAFE
40
+ #include <ruby/ractor.h>
41
+ #endif
39
42
 
40
43
  #include <ffi.h>
41
44
  #include "rbffi.h"
@@ -62,35 +65,65 @@ typedef struct VariadicInvoker_ {
62
65
  bool blocking;
63
66
  } VariadicInvoker;
64
67
 
65
-
66
68
  static VALUE variadic_allocate(VALUE klass);
67
69
  static VALUE variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes,
68
70
  VALUE rbReturnType, VALUE options);
69
- static void variadic_mark(VariadicInvoker *);
71
+ static void variadic_mark(void *);
72
+ static void variadic_compact(void *);
73
+ static size_t variadic_memsize(const void *);
70
74
 
71
75
  static VALUE classVariadicInvoker = Qnil;
72
76
 
77
+ static const rb_data_type_t variadic_data_type = {
78
+ .wrap_struct_name = "FFI::VariadicInvoker",
79
+ .function = {
80
+ .dmark = variadic_mark,
81
+ .dfree = RUBY_TYPED_DEFAULT_FREE,
82
+ .dsize = variadic_memsize,
83
+ ffi_compact_callback( variadic_compact )
84
+ },
85
+ // IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
86
+ // macro to update VALUE references, as to trigger write barriers.
87
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
88
+ };
89
+
73
90
 
74
91
  static VALUE
75
92
  variadic_allocate(VALUE klass)
76
93
  {
77
94
  VariadicInvoker *invoker;
78
- VALUE obj = Data_Make_Struct(klass, VariadicInvoker, variadic_mark, -1, invoker);
95
+ VALUE obj = TypedData_Make_Struct(klass, VariadicInvoker, &variadic_data_type, invoker);
79
96
 
80
- invoker->rbAddress = Qnil;
81
- invoker->rbEnums = Qnil;
82
- invoker->rbReturnType = Qnil;
97
+ RB_OBJ_WRITE(obj, &invoker->rbAddress, Qnil);
98
+ RB_OBJ_WRITE(obj, &invoker->rbEnums, Qnil);
99
+ RB_OBJ_WRITE(obj, &invoker->rbReturnType, Qnil);
83
100
  invoker->blocking = false;
84
101
 
85
102
  return obj;
86
103
  }
87
104
 
88
105
  static void
89
- variadic_mark(VariadicInvoker *invoker)
106
+ variadic_mark(void *data)
107
+ {
108
+ VariadicInvoker *invoker = (VariadicInvoker *)data;
109
+ rb_gc_mark_movable(invoker->rbEnums);
110
+ rb_gc_mark_movable(invoker->rbAddress);
111
+ rb_gc_mark_movable(invoker->rbReturnType);
112
+ }
113
+
114
+ static void
115
+ variadic_compact(void *data)
90
116
  {
91
- rb_gc_mark(invoker->rbEnums);
92
- rb_gc_mark(invoker->rbAddress);
93
- rb_gc_mark(invoker->rbReturnType);
117
+ VariadicInvoker *invoker = (VariadicInvoker *)data;
118
+ ffi_gc_location(invoker->rbEnums);
119
+ ffi_gc_location(invoker->rbAddress);
120
+ ffi_gc_location(invoker->rbReturnType);
121
+ }
122
+
123
+ static size_t
124
+ variadic_memsize(const void *data)
125
+ {
126
+ return sizeof(VariadicInvoker);
94
127
  }
95
128
 
96
129
  static VALUE
@@ -108,10 +141,10 @@ variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE
108
141
  Check_Type(options, T_HASH);
109
142
  convention = rb_hash_aref(options, ID2SYM(rb_intern("convention")));
110
143
 
111
- Data_Get_Struct(self, VariadicInvoker, invoker);
112
- invoker->rbEnums = rb_hash_aref(options, ID2SYM(rb_intern("enums")));
113
- invoker->rbAddress = rbFunction;
114
- invoker->function = rbffi_AbstractMemory_Cast(rbFunction, rbffi_PointerClass)->address;
144
+ TypedData_Get_Struct(self, VariadicInvoker, &variadic_data_type, invoker);
145
+ RB_OBJ_WRITE(self, &invoker->rbEnums, rb_hash_aref(options, ID2SYM(rb_intern("enums"))));
146
+ RB_OBJ_WRITE(self, &invoker->rbAddress, rbFunction);
147
+ invoker->function = rbffi_AbstractMemory_Cast(rbFunction, &rbffi_pointer_data_type)->address;
115
148
  invoker->blocking = RTEST(rb_hash_aref(options, ID2SYM(rb_intern("blocking"))));
116
149
 
117
150
  #if defined(X86_WIN32)
@@ -122,13 +155,13 @@ variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE
122
155
  invoker->abi = FFI_DEFAULT_ABI;
123
156
  #endif
124
157
 
125
- invoker->rbReturnType = rbffi_Type_Lookup(rbReturnType);
158
+ RB_OBJ_WRITE(self, &invoker->rbReturnType, rbffi_Type_Lookup(rbReturnType));
126
159
  if (!RTEST(invoker->rbReturnType)) {
127
160
  VALUE typeName = rb_funcall2(rbReturnType, rb_intern("inspect"), 0, NULL);
128
161
  rb_raise(rb_eTypeError, "Invalid return type (%s)", RSTRING_PTR(typeName));
129
162
  }
130
163
 
131
- Data_Get_Struct(rbReturnType, Type, invoker->returnType);
164
+ TypedData_Get_Struct(rbReturnType, Type, &rbffi_type_data_type, invoker->returnType);
132
165
 
133
166
  invoker->paramCount = -1;
134
167
 
@@ -142,7 +175,7 @@ variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE
142
175
  VALUE typeName = rb_funcall2(entry, rb_intern("inspect"), 0, NULL);
143
176
  rb_raise(rb_eTypeError, "Invalid parameter type (%s)", RSTRING_PTR(typeName));
144
177
  }
145
- Data_Get_Struct(rbType, Type, type);
178
+ TypedData_Get_Struct(rbType, Type, &rbffi_type_data_type, type);
146
179
  if (type->nativeType != NATIVE_VARARGS) {
147
180
  rb_ary_push(fixed, entry);
148
181
  }
@@ -150,7 +183,7 @@ variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE
150
183
  /*
151
184
  * @fixed and @type_map are used by the parameter mangling ruby code
152
185
  */
153
- rb_iv_set(self, "@fixed", fixed);
186
+ rb_iv_set(self, "@fixed", rb_obj_freeze(fixed));
154
187
  rb_iv_set(self, "@type_map", rb_hash_aref(options, ID2SYM(rb_intern("type_map"))));
155
188
 
156
189
  return retval;
@@ -176,7 +209,7 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
176
209
  Check_Type(parameterTypes, T_ARRAY);
177
210
  Check_Type(parameterValues, T_ARRAY);
178
211
 
179
- Data_Get_Struct(self, VariadicInvoker, invoker);
212
+ TypedData_Get_Struct(self, VariadicInvoker, &variadic_data_type, invoker);
180
213
  paramCount = (int) RARRAY_LEN(parameterTypes);
181
214
  paramTypes = ALLOCA_N(Type *, paramCount);
182
215
  ffiParamTypes = ALLOCA_N(ffi_type *, paramCount);
@@ -192,25 +225,25 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
192
225
  if (!rb_obj_is_kind_of(rbType, rbffi_TypeClass)) {
193
226
  rb_raise(rb_eTypeError, "wrong type. Expected (FFI::Type)");
194
227
  }
195
- Data_Get_Struct(rbType, Type, paramTypes[i]);
228
+ TypedData_Get_Struct(rbType, Type, &rbffi_type_data_type, paramTypes[i]);
196
229
 
197
230
  switch (paramTypes[i]->nativeType) {
198
231
  case NATIVE_INT8:
199
232
  case NATIVE_INT16:
200
233
  case NATIVE_INT32:
201
234
  rbType = rb_const_get(rbffi_TypeClass, rb_intern("INT32"));
202
- Data_Get_Struct(rbType, Type, paramTypes[i]);
235
+ TypedData_Get_Struct(rbType, Type, &rbffi_type_data_type, paramTypes[i]);
203
236
  break;
204
237
  case NATIVE_UINT8:
205
238
  case NATIVE_UINT16:
206
239
  case NATIVE_UINT32:
207
240
  rbType = rb_const_get(rbffi_TypeClass, rb_intern("UINT32"));
208
- Data_Get_Struct(rbType, Type, paramTypes[i]);
241
+ TypedData_Get_Struct(rbType, Type, &rbffi_type_data_type, paramTypes[i]);
209
242
  break;
210
243
 
211
244
  case NATIVE_FLOAT32:
212
245
  rbType = rb_const_get(rbffi_TypeClass, rb_intern("DOUBLE"));
213
- Data_Get_Struct(rbType, Type, paramTypes[i]);
246
+ TypedData_Get_Struct(rbType, Type, &rbffi_type_data_type, paramTypes[i]);
214
247
  break;
215
248
 
216
249
  case NATIVE_FUNCTION:
@@ -288,6 +321,14 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
288
321
  return rbffi_NativeValue_ToRuby(invoker->returnType, invoker->rbReturnType, retval);
289
322
  }
290
323
 
324
+ static VALUE
325
+ variadic_return_type(VALUE self)
326
+ {
327
+ VariadicInvoker* invoker;
328
+
329
+ TypedData_Get_Struct(self, VariadicInvoker, &variadic_data_type, invoker);
330
+ return invoker->rbReturnType;
331
+ }
291
332
 
292
333
  void
293
334
  rbffi_Variadic_Init(VALUE moduleFFI)
@@ -299,5 +340,6 @@ rbffi_Variadic_Init(VALUE moduleFFI)
299
340
 
300
341
  rb_define_method(classVariadicInvoker, "initialize", variadic_initialize, 4);
301
342
  rb_define_method(classVariadicInvoker, "invoke", variadic_invoke, 2);
343
+ rb_define_method(classVariadicInvoker, "return_type", variadic_return_type, 0);
302
344
  }
303
345
 
data/ext/ffi_c/compat.h CHANGED
@@ -32,26 +32,6 @@
32
32
 
33
33
  #include <ruby.h>
34
34
 
35
- #ifndef RARRAY_LEN
36
- # define RARRAY_LEN(ary) RARRAY(ary)->len
37
- #endif
38
-
39
- #ifndef RARRAY_PTR
40
- # define RARRAY_PTR(ary) RARRAY(ary)->ptr
41
- #endif
42
-
43
- #ifndef RSTRING_LEN
44
- # define RSTRING_LEN(s) RSTRING(s)->len
45
- #endif
46
-
47
- #ifndef RSTRING_PTR
48
- # define RSTRING_PTR(s) RSTRING(s)->ptr
49
- #endif
50
-
51
- #ifndef NUM2ULL
52
- # define NUM2ULL(x) rb_num2ull((VALUE)x)
53
- #endif
54
-
55
35
  #ifndef roundup
56
36
  # define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
57
37
  #endif
@@ -75,8 +55,28 @@
75
55
  # define MIN(a, b) ((a) < (b) ? (a) : (b))
76
56
  #endif
77
57
 
78
- #ifndef RB_GC_GUARD
79
- # define RB_GC_GUARD(x) (x)
58
+
59
+
60
+ /* For compatibility with ruby < 2.7 */
61
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
62
+ #define ffi_compact_callback(x) .dcompact = (x),
63
+ #define ffi_gc_location(x) x = rb_gc_location(x)
64
+ #else
65
+ #define rb_gc_mark_movable(x) rb_gc_mark(x)
66
+ #define ffi_compact_callback(x)
67
+ #define ffi_gc_location(x)
68
+ #endif
69
+
70
+
71
+ /* For compatibility with ruby < 3.0 */
72
+ #ifndef RUBY_TYPED_FROZEN_SHAREABLE
73
+ #define FFI_RUBY_TYPED_FROZEN_SHAREABLE 0
74
+ #else
75
+ #define FFI_RUBY_TYPED_FROZEN_SHAREABLE RUBY_TYPED_FROZEN_SHAREABLE
76
+ #endif
77
+
78
+ #ifndef HAVE_RB_EXT_RACTOR_SAFE
79
+ #define rb_ractor_make_shareable(self) rb_obj_freeze(self);
80
80
  #endif
81
81
 
82
82
  #endif /* RBFFI_COMPAT_H */
data/ext/ffi_c/extconf.rb CHANGED
@@ -33,7 +33,11 @@ if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
33
33
  $CFLAGS.gsub!(/[\s+]-ansi/, '')
34
34
  $CFLAGS.gsub!(/[\s+]-std=[^\s]+/, '')
35
35
  # solaris 10 needs -c99 for <stdbool.h>
36
- $CFLAGS << " -std=c99" if RbConfig::CONFIG['host_os'] =~ /solaris(!?2\.11)/
36
+ $CFLAGS << " -g -std=c99" if RbConfig::CONFIG['host_os'] =~ /solaris(!?2\.11)/
37
+ if enable_config("debug")
38
+ $CPPFLAGS += " #{RbConfig::CONFIG["debugflags"]}"
39
+ $LDFLAGS += " #{RbConfig::CONFIG["debugflags"]}"
40
+ end
37
41
 
38
42
  # Check whether we use system libffi
39
43
  system_libffi = enable_config('system-libffi', :try)
@@ -57,10 +61,13 @@ if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
57
61
  append_ldflags "-Wl,--exclude-libs,ALL"
58
62
  end
59
63
 
64
+ have_func 'rb_gc_mark_movable' # since ruby-2.7
65
+
60
66
  # Some linux archs need explicit linking to pthread, see https://github.com/ffi/ffi/issues/893
61
67
  append_ldflags "-pthread"
62
68
 
63
69
  ffi_alloc_default = RbConfig::CONFIG['host_os'] =~ /darwin/i && RbConfig::CONFIG['host'] =~ /arm|aarch64/i
70
+ ffi_alloc_default = ffi_alloc_default || RbConfig::CONFIG['host'] =~ /hppa/i
64
71
  if enable_config('libffi-alloc', ffi_alloc_default)
65
72
  $defs << "-DUSE_FFI_ALLOC"
66
73
  end
@@ -72,7 +79,17 @@ if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
72
79
 
73
80
  unless system_libffi
74
81
  File.open("Makefile", "a") do |mf|
75
- mf.puts "LIBFFI_HOST=--host=#{RbConfig::CONFIG['host_alias']}" if RbConfig::CONFIG.has_key?("host_alias")
82
+ if enable_config("debug")
83
+ mf.puts "LIBFFI_DEBUG=--enable-debug CPPFLAGS='#{RbConfig::CONFIG["debugflags"]}' LDFLAGS='#{RbConfig::CONFIG["debugflags"]}'"
84
+ end
85
+
86
+ if RbConfig::CONFIG['host_alias'] == "i386-w64-mingw32"
87
+ host = "i686-w64-mingw32" # Work around host name without matching compiler name in rake-compiler-dock-1.3.0 on platform x86-mingw32
88
+ elsif RbConfig::CONFIG.has_key?("host_alias")
89
+ host = RbConfig::CONFIG['host_alias']
90
+ end
91
+ mf.puts "LIBFFI_HOST=--host=#{host}" if host
92
+
76
93
  if RbConfig::CONFIG['host_os'] =~ /darwin/i
77
94
  if RbConfig::CONFIG['host'] =~ /arm|aarch64/i
78
95
  mf.puts "LIBFFI_HOST=--host=aarch64-apple-#{RbConfig::CONFIG['host_os']}"
data/ext/ffi_c/ffi.c CHANGED
@@ -60,6 +60,10 @@ static VALUE moduleFFI = Qnil;
60
60
  void
61
61
  Init_ffi_c(void)
62
62
  {
63
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
64
+ rb_ext_ractor_safe(1);
65
+ #endif
66
+
63
67
  /*
64
68
  * Document-module: FFI
65
69
  *
@@ -0,0 +1,16 @@
1
+ # Copyright (C) 2021 Anthony Green
2
+
3
+ lappend boards_dir $::env(SITEDIR)
4
+
5
+ verbose "Global Config File: target_triplet is $target_triplet" 1
6
+ global target_list
7
+
8
+ case "$target_triplet" in {
9
+ { "aarch*cygwin*" } {
10
+ set target_list "unix-noexec"
11
+ }
12
+ { "arm*cygwin*" } {
13
+ set target_list "unix-noexec"
14
+ }
15
+ }
16
+
@@ -0,0 +1,7 @@
1
+ load_generic_config "remote"
2
+
3
+ proc noexec_load { dest prog args } {
4
+ return "unsupported"
5
+ }
6
+
7
+ set_board_info protocol "noexec"