ffi 1.15.5 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (308) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +54 -0
  4. data/Gemfile +1 -1
  5. data/README.md +3 -2
  6. data/Rakefile +10 -7
  7. data/ext/ffi_c/AbstractMemory.c +56 -34
  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 +13 -5
  13. data/ext/ffi_c/DynamicLibrary.c +89 -26
  14. data/ext/ffi_c/Function.c +238 -98
  15. data/ext/ffi_c/Function.h +1 -0
  16. data/ext/ffi_c/FunctionInfo.c +78 -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 +151 -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 +118 -51
  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/config.guess +623 -556
  54. data/ext/ffi_c/libffi/config.sub +75 -34
  55. data/ext/ffi_c/libffi/configure +4571 -3830
  56. data/ext/ffi_c/libffi/configure.ac +64 -28
  57. data/ext/ffi_c/libffi/configure.host +25 -6
  58. data/ext/ffi_c/libffi/doc/Makefile.in +9 -6
  59. data/ext/ffi_c/libffi/doc/libffi.texi +82 -33
  60. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  61. data/ext/ffi_c/libffi/fficonfig.h.in +12 -47
  62. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +163 -52
  63. data/ext/ffi_c/libffi/include/Makefile.am +1 -1
  64. data/ext/ffi_c/libffi/include/Makefile.in +10 -9
  65. data/ext/ffi_c/libffi/include/ffi.h.in +54 -50
  66. data/ext/ffi_c/libffi/include/ffi_cfi.h +21 -0
  67. data/ext/ffi_c/libffi/include/ffi_common.h +29 -0
  68. data/ext/ffi_c/libffi/include/tramp.h +45 -0
  69. data/ext/ffi_c/libffi/install-sh +92 -69
  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 +137 -121
  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 +2 -2
  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/types.rb +30 -5
  289. data/lib/ffi/variadic.rb +19 -8
  290. data/lib/ffi/version.rb +1 -1
  291. data.tar.gz.sig +0 -0
  292. metadata +97 -25
  293. metadata.gz.sig +1 -0
  294. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +0 -14
  295. data/ext/ffi_c/libffi/.travis/build.sh +0 -142
  296. data/ext/ffi_c/libffi/.travis.yml +0 -83
  297. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +0 -44
  298. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +0 -44
  299. /data/ext/ffi_c/libffi/{.travis → .ci}/ar-lib +0 -0
  300. /data/ext/ffi_c/libffi/{.travis → .ci}/bfin-sim.exp +0 -0
  301. /data/ext/ffi_c/libffi/{.travis → .ci}/compile +0 -0
  302. /data/ext/ffi_c/libffi/{.travis → .ci}/m32r-sim.exp +0 -0
  303. /data/ext/ffi_c/libffi/{.travis → .ci}/moxie-sim.exp +0 -0
  304. /data/ext/ffi_c/libffi/{.travis → .ci}/or1k-sim.exp +0 -0
  305. /data/ext/ffi_c/libffi/{.travis → .ci}/powerpc-eabisim.exp +0 -0
  306. /data/ext/ffi_c/libffi/{.travis → .ci}/wine-sim.exp +0 -0
  307. /data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
  308. /data/lib/ffi/platform/{sparc64-linux → sparcv9-linux}/types.conf +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6f15f4e38ad34949be88341216eed2ea132c4e5763d333c20c240491b033ff6
4
- data.tar.gz: deefb7285ccae7d7248ee2697709e859d4c0017e3aab7e183ce7fc2a824bd395
3
+ metadata.gz: ee7a1ffc0f567cd7ef2162af6e49488a4a5164aabb3baa24c652a22917e4eadc
4
+ data.tar.gz: 59f023b4798897616ae96d407193138b428e172e934faa54450e6e66821f4769
5
5
  SHA512:
6
- metadata.gz: 7b2c32adb0af3689632c9b6113389245dba13d5f9e622efd2f322b0226933185ae0fbc128cb33c278dd2ef7fddda106fe8158904e95d1fa7d53b14ff72722ff6
7
- data.tar.gz: 60ca6ad01c3d977b8b6efe0329683d4105cae8147848c9fcb0cabe643f5957e7a6ab6a06716e1f579ada6e0c3795f4fd4c0f16bda783342310a305423a5d7a60
6
+ metadata.gz: bf3a43c4637d326b2adfa063132baf5d157311ef372087e4c1c74c80f9fe7e04090b01f58da2b8d6f5043d019d0ed84b55831a56fa3a1689bce9ec10b92a5c3e
7
+ data.tar.gz: 7d3a0ec5e19c2e27faf0e99a95991c37b2db5cbdc2ebea84f2c983b988349baecaf50494f3e662883a1ecfad3c6e91b35a17ea0e49960a3a8db193525d5194ff
checksums.yaml.gz.sig ADDED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,3 +1,57 @@
1
+ 1.16.0 / 2023-09-23
2
+ -------------------
3
+
4
+ Fixed:
5
+ * Fix an issue with signed bitmasks when using flags on the most significant bit. #949
6
+ * Fix FFI::Pointer#initialize using NUM2LL instead of NUM2ULL.
7
+ * Fix FFI::Type#inspect to properly display the constant name. #1002
8
+ * Use libffi closure allocations on hppa-Linux. #1017
9
+ Previously they would segfault.
10
+ * Fix class name of Symbol#inspect.
11
+ * Fix MSVC support of libtest. #1028
12
+ * Fix attach_function of functions ending in ? or ! #971
13
+
14
+ Added:
15
+ * Convert all C-based classes to TypedData and use write barriers. #994, #995, #996, #997, #998, #999, #1000, #1001, #1003, #1004, #1005, #1006, #1007, #1008, #1009, #1010, #1011, #1012
16
+ This results in less pressure on the garbage collector, since the objects can be promoted to the old generation, which means they only get marked on major GC.
17
+ * Implement `ObjectSpace.memsize_of()` of all C-based classes.
18
+ * Make FFI Ractor compatible. #1023
19
+ Modules extended per `extend FFI::Library` need to be frozen in order to be used by non-main Ractors.
20
+ This can be done by calling `freeze` below of all C interface definitions.
21
+ * In a Ractor it's possible to:
22
+ * load DLLs and call its functions, access its global variables
23
+ * use builtin typedefs
24
+ * use and modify ractor local typedefs
25
+ * define callbacks
26
+ * receive async callbacks from non-ruby threads
27
+ * use frozen FFI::Library based modules with all attributes (enums, structs, typedefs, functions, callbacks)
28
+ * invoke frozen functions and callbacks defined in the main Ractor
29
+ * use FFI::Struct definitions from the main Ractor
30
+ * In a Ractor it's impossible to:
31
+ * create new FFI::Library based modules
32
+ * create new FFI::Struct definitions
33
+ * use custom global typedefs
34
+ * use non-frozen FFI::Library based modules
35
+ * Allow type retrieval of attached functions+variables. #1023
36
+ * Make FFI classes `GC.compact` friendly. #1021
37
+ * Update libffi and disable custom trampoline when using libffi closure allocation. #1020
38
+ This is because libffi changed the way how closures are allocated to static trampolines.
39
+ * Add types.conf for loongarch64-linux. #943
40
+ * Add types.conf for sw_64-linux (Shen Wei 64-bit, based on Alpha). #1018
41
+ * Add support for aarch64-windows. #1035
42
+ * Windows: Update LoadLibrary error message to include error code. #1026
43
+ * Allow private release method for FFI::ManagedStruct and FFI::AutoPointer. #1029
44
+ * Add support for passing ABI version to FFI.map_library_name. #963
45
+ This adds the new class FFI::LibraryPath .
46
+ * Add support for ruby-3.2 to windows binary gem. #1047
47
+ * Enable debug symbols for `rake compile` builds to ease debugging. #1048
48
+
49
+ Removed:
50
+ * Remove allocator of AbstractMemory. #1013
51
+ This disables AbstractMemory.new, which has no practical use.
52
+ * Remove unused FFI::SizeTypes. #1022
53
+
54
+
1
55
  1.15.5 / 2022-01-10
2
56
  -------------------
3
57
 
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  group :development do
4
4
  gem 'rake', '~> 13.0'
5
- gem 'rake-compiler', '~> 1.0.3'
5
+ gem 'rake-compiler', '~> 1.1'
6
6
  gem 'rake-compiler-dock', '~> 1.0'
7
7
  gem 'rspec', '~> 3.0'
8
8
  gem 'bundler', '>= 1.16', '< 3'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ruby-FFI https://github.com/ffi/ffi/wiki [![Build Status](https://travis-ci.com/ffi/ffi.svg?branch=master)](https://travis-ci.com/ffi/ffi) [![Build status Windows](https://ci.appveyor.com/api/projects/status/r8wxn1sd4s794gg1/branch/master?svg=true)](https://ci.appveyor.com/project/larskanis/ffi-aofqa/branch/master)
1
+ # Ruby-FFI https://github.com/ffi/ffi/wiki
2
2
 
3
3
  ## Description
4
4
 
@@ -15,6 +15,7 @@ using Ruby-FFI](https://github.com/ffi/ffi/wiki/why-use-ffi).
15
15
  * C structs (also nested), enums and global variables
16
16
  * Callbacks from C to Ruby
17
17
  * Automatic garbage collection of native memory
18
+ * Usable in Ractor
18
19
 
19
20
  ## Synopsis
20
21
 
@@ -62,7 +63,7 @@ On JRuby and TruffleRuby, there are no requirements to install the FFI gem, and
62
63
  From rubygems:
63
64
 
64
65
  [sudo] gem install ffi
65
-
66
+
66
67
  From a Gemfile using git or GitHub
67
68
 
68
69
  gem 'ffi', github: 'ffi/ffi', submodules: true
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rbconfig'
2
2
  require 'date'
3
3
  require 'fileutils'
4
- require 'rbconfig'
4
+ require 'yaml'
5
5
  require 'rspec/core/rake_task'
6
6
  require 'rubygems/package_task'
7
7
  require 'rake/extensiontask'
@@ -30,9 +30,8 @@ CLEAN.include 'spec/ffi/fixtures/libtest.{dylib,so,dll}'
30
30
  CLEAN.include 'spec/ffi/fixtures/*.o'
31
31
  CLEAN.include 'spec/ffi/embed-test/ext/*.{o,def}'
32
32
  CLEAN.include 'spec/ffi/embed-test/ext/Makefile'
33
- CLEAN.include "pkg/ffi-*-{mingw32,java}"
34
- CLEAN.include 'lib/1.*'
35
- CLEAN.include 'lib/2.*'
33
+ CLEAN.include "pkg/ffi-*-*/"
34
+ CLEAN.include 'lib/{2,3}.*'
36
35
 
37
36
  # clean all shipped files, that are not in git
38
37
  CLEAN.include(
@@ -87,6 +86,8 @@ task 'gem:java' => 'java:gem'
87
86
  FfiGemHelper.install_tasks
88
87
  # Register windows gems to be pushed to rubygems.org
89
88
  Bundler::GemHelper.instance.cross_platforms = %w[x86-mingw32 x64-mingw-ucrt x64-mingw32]
89
+ # These platforms are not yet enabled, since there are issues on musl-based distors (alpine-linux):
90
+ # + %w[x86-linux x86_64-linux arm-linux aarch64-linux x86_64-darwin arm64-darwin]
90
91
 
91
92
  if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
92
93
  require 'rake/extensiontask'
@@ -99,6 +100,8 @@ if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
99
100
  ext.cross_compiling do |spec|
100
101
  spec.files.reject! { |path| File.fnmatch?('ext/*', path) }
101
102
  end
103
+ # Enable debug info for 'rake compile' but not for 'gem install'
104
+ ext.config_options << "--enable-debug"
102
105
 
103
106
  end
104
107
  else
@@ -121,9 +124,9 @@ namespace "gem" do
121
124
  desc "Build the native gem for #{plat}"
122
125
  task plat => ['prepare', 'build'] do
123
126
  RakeCompilerDock.sh <<-EOT, platform: plat
124
- sudo apt-get update &&
125
- sudo apt-get install -y libltdl-dev && bundle --local &&
126
- rake cross native gem MAKE='nice make -j`nproc`' RUBY_CC_VERSION=${RUBY_CC_VERSION/:2.2.2/}
127
+ #{ "sudo apt-get update && sudo apt-get install -y libltdl-dev &&" if plat !~ /linux/ }
128
+ bundle --local &&
129
+ rake native:#{plat} pkg/#{gem_spec.full_name}-#{plat}.gem MAKE='nice make -j`nproc`' RUBY_CC_VERSION=${RUBY_CC_VERSION/:2.4.0/}
127
130
  EOT
128
131
  end
129
132
  end
@@ -55,21 +55,30 @@
55
55
  # define RB_OBJ_STRING(obj) StringValueCStr(obj)
56
56
  #endif
57
57
 
58
+ static size_t memsize(const void *data);
58
59
  static inline char* memory_address(VALUE self);
59
60
  VALUE rbffi_AbstractMemoryClass = Qnil;
60
61
  static VALUE NullPointerErrorClass = Qnil;
61
62
  static ID id_to_ptr = 0, id_plus = 0, id_call = 0;
62
63
 
63
- static VALUE
64
- memory_allocate(VALUE klass)
65
- {
66
- AbstractMemory* memory;
67
- VALUE obj;
68
- obj = Data_Make_Struct(klass, AbstractMemory, NULL, -1, memory);
69
- memory->flags = MEM_RD | MEM_WR;
64
+ const rb_data_type_t rbffi_abstract_memory_data_type = { /* extern */
65
+ .wrap_struct_name = "FFI::AbstractMemory",
66
+ .function = {
67
+ .dmark = NULL,
68
+ .dfree = RUBY_TYPED_DEFAULT_FREE,
69
+ .dsize = 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
+ };
70
75
 
71
- return obj;
76
+ static size_t
77
+ memsize(const void *data)
78
+ {
79
+ return sizeof(AbstractMemory);
72
80
  }
81
+
73
82
  #define VAL(x, swap) (unlikely(((memory->flags & MEM_SWAP) != 0)) ? swap((x)) : (x))
74
83
 
75
84
  #define NUM_OP(name, type, toNative, fromNative, swap) \
@@ -87,7 +96,7 @@ static VALUE \
87
96
  memory_put_##name(VALUE self, VALUE offset, VALUE value) \
88
97
  { \
89
98
  AbstractMemory* memory; \
90
- Data_Get_Struct(self, AbstractMemory, memory); \
99
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, memory); \
91
100
  memory_op_put_##name(memory, NUM2LONG(offset), value); \
92
101
  return self; \
93
102
  } \
@@ -96,7 +105,7 @@ static VALUE \
96
105
  memory_write_##name(VALUE self, VALUE value) \
97
106
  { \
98
107
  AbstractMemory* memory; \
99
- Data_Get_Struct(self, AbstractMemory, memory); \
108
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, memory); \
100
109
  memory_op_put_##name(memory, 0, value); \
101
110
  return self; \
102
111
  } \
@@ -115,7 +124,7 @@ static VALUE \
115
124
  memory_get_##name(VALUE self, VALUE offset) \
116
125
  { \
117
126
  AbstractMemory* memory; \
118
- Data_Get_Struct(self, AbstractMemory, memory); \
127
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, memory); \
119
128
  return memory_op_get_##name(memory, NUM2LONG(offset)); \
120
129
  } \
121
130
  static VALUE memory_read_##name(VALUE self); \
@@ -123,7 +132,7 @@ static VALUE \
123
132
  memory_read_##name(VALUE self) \
124
133
  { \
125
134
  AbstractMemory* memory; \
126
- Data_Get_Struct(self, AbstractMemory, memory); \
135
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, memory); \
127
136
  return memory_op_get_##name(memory, 0); \
128
137
  } \
129
138
  static MemoryOp memory_op_##name = { memory_op_get_##name, memory_op_put_##name }; \
@@ -141,7 +150,7 @@ memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \
141
150
  if (likely(count > 0)) checkWrite(memory); \
142
151
  checkBounds(memory, off, count * sizeof(type)); \
143
152
  for (i = 0; i < count; i++) { \
144
- type tmp = (type) VAL(toNative(RARRAY_PTR(ary)[i]), swap); \
153
+ type tmp = (type) VAL(toNative(RARRAY_AREF(ary, i)), swap); \
145
154
  memcpy(memory->address + off + (i * sizeof(type)), &tmp, sizeof(tmp)); \
146
155
  } \
147
156
  return self; \
@@ -307,6 +316,7 @@ static VALUE
307
316
  memory_clear(VALUE self)
308
317
  {
309
318
  AbstractMemory* ptr = MEMORY(self);
319
+ checkWrite(ptr);
310
320
  memset(ptr->address, 0, ptr->size);
311
321
  return self;
312
322
  }
@@ -321,7 +331,7 @@ memory_size(VALUE self)
321
331
  {
322
332
  AbstractMemory* ptr;
323
333
 
324
- Data_Get_Struct(self, AbstractMemory, ptr);
334
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
325
335
 
326
336
  return LONG2NUM(ptr->size);
327
337
  }
@@ -344,8 +354,8 @@ memory_get(VALUE self, VALUE type_name, VALUE offset)
344
354
  nType = rbffi_Type_Lookup(type_name);
345
355
  if(NIL_P(nType)) goto undefined_type;
346
356
 
347
- Data_Get_Struct(self, AbstractMemory, ptr);
348
- Data_Get_Struct(nType, Type, type);
357
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
358
+ TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
349
359
 
350
360
  MemoryOp *op = get_memory_op(type);
351
361
  if(op == NULL) goto undefined_type;
@@ -376,8 +386,8 @@ memory_put(VALUE self, VALUE type_name, VALUE offset, VALUE value)
376
386
  nType = rbffi_Type_Lookup(type_name);
377
387
  if(NIL_P(nType)) goto undefined_type;
378
388
 
379
- Data_Get_Struct(self, AbstractMemory, ptr);
380
- Data_Get_Struct(nType, Type, type);
389
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
390
+ TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
381
391
 
382
392
  MemoryOp *op = get_memory_op(type);
383
393
  if(op == NULL) goto undefined_type;
@@ -442,7 +452,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
442
452
  count = (countnum == Qnil ? 0 : NUM2INT(countnum));
443
453
  retVal = rb_ary_new2(count);
444
454
 
445
- Data_Get_Struct(self, AbstractMemory, ptr);
455
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
446
456
  checkRead(ptr);
447
457
 
448
458
  if (countnum != Qnil) {
@@ -633,7 +643,7 @@ memory_type_size(VALUE self)
633
643
  {
634
644
  AbstractMemory* ptr;
635
645
 
636
- Data_Get_Struct(self, AbstractMemory, ptr);
646
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
637
647
 
638
648
  return INT2NUM(ptr->typeSize);
639
649
  }
@@ -651,7 +661,7 @@ memory_aref(VALUE self, VALUE idx)
651
661
  AbstractMemory* ptr;
652
662
  VALUE rbOffset = Qnil;
653
663
 
654
- Data_Get_Struct(self, AbstractMemory, ptr);
664
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
655
665
 
656
666
  rbOffset = ULONG2NUM(NUM2ULONG(idx) * ptr->typeSize);
657
667
 
@@ -661,7 +671,9 @@ memory_aref(VALUE self, VALUE idx)
661
671
  static inline char*
662
672
  memory_address(VALUE obj)
663
673
  {
664
- return ((AbstractMemory *) DATA_PTR(obj))->address;
674
+ AbstractMemory *mem;
675
+ TypedData_Get_Struct(obj, AbstractMemory, &rbffi_abstract_memory_data_type, mem);
676
+ return mem->address;
665
677
  }
666
678
 
667
679
  static VALUE
@@ -669,24 +681,33 @@ memory_copy_from(VALUE self, VALUE rbsrc, VALUE rblen)
669
681
  {
670
682
  AbstractMemory* dst;
671
683
 
672
- Data_Get_Struct(self, AbstractMemory, dst);
684
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, dst);
673
685
 
674
- memcpy(dst->address, rbffi_AbstractMemory_Cast(rbsrc, rbffi_AbstractMemoryClass)->address, NUM2INT(rblen));
686
+ memcpy(dst->address, rbffi_AbstractMemory_Cast(rbsrc, &rbffi_abstract_memory_data_type)->address, NUM2INT(rblen));
675
687
 
676
688
  return self;
677
689
  }
678
690
 
679
- AbstractMemory*
680
- rbffi_AbstractMemory_Cast(VALUE obj, VALUE klass)
691
+ /*
692
+ * call-seq:
693
+ * res.freeze
694
+ *
695
+ * Freeze the AbstractMemory object and unset the writable flag.
696
+ */
697
+ static VALUE
698
+ memory_freeze(VALUE self)
681
699
  {
682
- if (rb_obj_is_kind_of(obj, klass)) {
683
- AbstractMemory* memory;
684
- Data_Get_Struct(obj, AbstractMemory, memory);
685
- return memory;
686
- }
700
+ AbstractMemory* ptr = MEMORY(self);
701
+ ptr->flags &= ~MEM_WR;
702
+ return rb_call_super(0, NULL);
703
+ }
687
704
 
688
- rb_raise(rb_eArgError, "Invalid Memory object");
689
- return NULL;
705
+ AbstractMemory*
706
+ rbffi_AbstractMemory_Cast(VALUE obj, const rb_data_type_t *data_type)
707
+ {
708
+ AbstractMemory* memory;
709
+ TypedData_Get_Struct(obj, AbstractMemory, data_type, memory);
710
+ return memory;
690
711
  }
691
712
 
692
713
  void
@@ -781,7 +802,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
781
802
  * Document-variable: FFI::AbstractMemory
782
803
  */
783
804
  rb_global_variable(&rbffi_AbstractMemoryClass);
784
- rb_define_alloc_func(classMemory, memory_allocate);
805
+ rb_undef_alloc_func(classMemory);
785
806
 
786
807
  NullPointerErrorClass = rb_define_class_under(moduleFFI, "NullPointerError", rb_eRuntimeError);
787
808
  /* Document-variable: NullPointerError */
@@ -1096,6 +1117,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
1096
1117
  rb_define_method(classMemory, "type_size", memory_type_size, 0);
1097
1118
  rb_define_method(classMemory, "[]", memory_aref, 1);
1098
1119
  rb_define_method(classMemory, "__copy_from__", memory_copy_from, 2);
1120
+ rb_define_method(classMemory, "freeze", memory_freeze, 0 );
1099
1121
 
1100
1122
  id_to_ptr = rb_intern("to_ptr");
1101
1123
  id_call = rb_intern("call");
@@ -86,12 +86,13 @@ struct AbstractMemory_ {
86
86
  };
87
87
 
88
88
 
89
+ extern const rb_data_type_t rbffi_abstract_memory_data_type;
89
90
  extern VALUE rbffi_AbstractMemoryClass;
90
91
  extern MemoryOps rbffi_AbstractMemoryOps;
91
92
 
92
93
  extern void rbffi_AbstractMemory_Init(VALUE ffiModule);
93
94
 
94
- extern AbstractMemory* rbffi_AbstractMemory_Cast(VALUE obj, VALUE klass);
95
+ extern AbstractMemory* rbffi_AbstractMemory_Cast(VALUE obj, const rb_data_type_t *data_type);
95
96
 
96
97
  extern void rbffi_AbstractMemory_Error(AbstractMemory *, int op);
97
98
 
@@ -161,7 +162,7 @@ get_memory_op(Type* type)
161
162
  }
162
163
  }
163
164
 
164
- #define MEMORY(obj) rbffi_AbstractMemory_Cast((obj), rbffi_AbstractMemoryClass)
165
+ #define MEMORY(obj) rbffi_AbstractMemory_Cast((obj), &rbffi_abstract_memory_data_type)
165
166
  #define MEMORY_PTR(obj) MEMORY((obj))->address
166
167
  #define MEMORY_LEN(obj) MEMORY((obj))->size
167
168
 
@@ -29,12 +29,30 @@
29
29
 
30
30
  #include <ruby.h>
31
31
  #include <ffi.h>
32
+ #include "compat.h"
32
33
  #include "ArrayType.h"
33
34
 
34
35
  static VALUE array_type_s_allocate(VALUE klass);
35
36
  static VALUE array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength);
36
- static void array_type_mark(ArrayType *);
37
- static void array_type_free(ArrayType *);
37
+ static void array_type_mark(void *);
38
+ static void array_type_compact(void *);
39
+ static void array_type_free(void *);
40
+ static size_t array_type_memsize(const void *);
41
+
42
+ const rb_data_type_t rbffi_array_type_data_type = { /* extern */
43
+ .wrap_struct_name = "FFI::ArrayType",
44
+ .function = {
45
+ .dmark = array_type_mark,
46
+ .dfree = array_type_free,
47
+ .dsize = array_type_memsize,
48
+ ffi_compact_callback( array_type_compact )
49
+ },
50
+ .parent = &rbffi_type_data_type,
51
+ // IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
52
+ // macro to update VALUE references, as to trigger write barriers.
53
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
54
+ };
55
+
38
56
 
39
57
  VALUE rbffi_ArrayTypeClass = Qnil;
40
58
 
@@ -44,32 +62,50 @@ array_type_s_allocate(VALUE klass)
44
62
  ArrayType* array;
45
63
  VALUE obj;
46
64
 
47
- obj = Data_Make_Struct(klass, ArrayType, array_type_mark, array_type_free, array);
65
+ obj = TypedData_Make_Struct(klass, ArrayType, &rbffi_array_type_data_type, array);
48
66
 
49
67
  array->base.nativeType = NATIVE_ARRAY;
50
68
  array->base.ffiType = xcalloc(1, sizeof(*array->base.ffiType));
51
69
  array->base.ffiType->type = FFI_TYPE_STRUCT;
52
70
  array->base.ffiType->size = 0;
53
71
  array->base.ffiType->alignment = 0;
54
- array->rbComponentType = Qnil;
72
+ RB_OBJ_WRITE(obj, &array->rbComponentType, Qnil);
55
73
 
56
74
  return obj;
57
75
  }
58
76
 
59
77
  static void
60
- array_type_mark(ArrayType *array)
78
+ array_type_mark(void *data)
79
+ {
80
+ ArrayType *array = (ArrayType *)data;
81
+ rb_gc_mark_movable(array->rbComponentType);
82
+ }
83
+
84
+ static void
85
+ array_type_compact(void *data)
61
86
  {
62
- rb_gc_mark(array->rbComponentType);
87
+ ArrayType *array = (ArrayType *)data;
88
+ ffi_gc_location(array->rbComponentType);
63
89
  }
64
90
 
65
91
  static void
66
- array_type_free(ArrayType *array)
92
+ array_type_free(void *data)
67
93
  {
94
+ ArrayType *array = (ArrayType *)data;
68
95
  xfree(array->base.ffiType);
69
96
  xfree(array->ffiTypes);
70
97
  xfree(array);
71
98
  }
72
99
 
100
+ static size_t
101
+ array_type_memsize(const void *data)
102
+ {
103
+ const ArrayType *array = (const ArrayType *)data;
104
+ size_t memsize = sizeof(ArrayType);
105
+ memsize += array->length * sizeof(*array->ffiTypes);
106
+ memsize += sizeof(*array->base.ffiType);
107
+ return memsize;
108
+ }
73
109
 
74
110
  /*
75
111
  * call-seq: initialize(component_type, length)
@@ -84,12 +120,12 @@ array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength)
84
120
  ArrayType* array;
85
121
  int i;
86
122
 
87
- Data_Get_Struct(self, ArrayType, array);
123
+ TypedData_Get_Struct(self, ArrayType, &rbffi_array_type_data_type, array);
88
124
 
89
125
  array->length = NUM2UINT(rbLength);
90
- array->rbComponentType = rbComponentType;
91
- Data_Get_Struct(rbComponentType, Type, array->componentType);
92
-
126
+ RB_OBJ_WRITE(self, &array->rbComponentType, rbComponentType);
127
+ TypedData_Get_Struct(rbComponentType, Type, &rbffi_type_data_type, array->componentType);
128
+
93
129
  array->ffiTypes = xcalloc(array->length + 1, sizeof(*array->ffiTypes));
94
130
  array->base.ffiType->elements = array->ffiTypes;
95
131
  array->base.ffiType->size = array->componentType->ffiType->size * array->length;
@@ -112,7 +148,7 @@ array_type_length(VALUE self)
112
148
  {
113
149
  ArrayType* array;
114
150
 
115
- Data_Get_Struct(self, ArrayType, array);
151
+ TypedData_Get_Struct(self, ArrayType, &rbffi_array_type_data_type, array);
116
152
 
117
153
  return UINT2NUM(array->length);
118
154
  }
@@ -127,7 +163,7 @@ array_type_element_type(VALUE self)
127
163
  {
128
164
  ArrayType* array;
129
165
 
130
- Data_Get_Struct(self, ArrayType, array);
166
+ TypedData_Get_Struct(self, ArrayType, &rbffi_array_type_data_type, array);
131
167
 
132
168
  return array->rbComponentType;
133
169
  }
@@ -48,6 +48,7 @@ typedef struct ArrayType_ {
48
48
  } ArrayType;
49
49
 
50
50
  extern void rbffi_ArrayType_Init(VALUE moduleFFI);
51
+ extern const rb_data_type_t rbffi_array_type_data_type;
51
52
  extern VALUE rbffi_ArrayTypeClass;
52
53
 
53
54