ffi 1.15.5 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (343) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +118 -0
  4. data/Gemfile +10 -3
  5. data/README.md +4 -3
  6. data/Rakefile +25 -10
  7. data/ext/ffi_c/AbstractMemory.c +99 -74
  8. data/ext/ffi_c/AbstractMemory.h +3 -2
  9. data/ext/ffi_c/ArrayType.c +51 -15
  10. data/ext/ffi_c/ArrayType.h +1 -0
  11. data/ext/ffi_c/Buffer.c +90 -33
  12. data/ext/ffi_c/Call.c +29 -12
  13. data/ext/ffi_c/Call.h +3 -2
  14. data/ext/ffi_c/DynamicLibrary.c +90 -27
  15. data/ext/ffi_c/Function.c +244 -98
  16. data/ext/ffi_c/Function.h +1 -0
  17. data/ext/ffi_c/FunctionInfo.c +81 -25
  18. data/ext/ffi_c/LastError.c +29 -11
  19. data/ext/ffi_c/MappedType.c +66 -23
  20. data/ext/ffi_c/MappedType.h +0 -2
  21. data/ext/ffi_c/MemoryPointer.c +36 -9
  22. data/ext/ffi_c/MethodHandle.c +3 -1
  23. data/ext/ffi_c/Pointer.c +82 -40
  24. data/ext/ffi_c/Pointer.h +1 -0
  25. data/ext/ffi_c/Struct.c +166 -84
  26. data/ext/ffi_c/Struct.h +7 -4
  27. data/ext/ffi_c/StructByValue.c +48 -16
  28. data/ext/ffi_c/StructLayout.c +130 -61
  29. data/ext/ffi_c/Type.c +120 -51
  30. data/ext/ffi_c/Type.h +3 -1
  31. data/ext/ffi_c/Types.c +8 -2
  32. data/ext/ffi_c/Types.h +0 -1
  33. data/ext/ffi_c/Variadic.c +71 -26
  34. data/ext/ffi_c/compat.h +22 -22
  35. data/ext/ffi_c/extconf.rb +19 -2
  36. data/ext/ffi_c/ffi.c +4 -0
  37. data/ext/ffi_c/libffi/.allow-ai-service +0 -0
  38. data/ext/ffi_c/libffi/.appveyor/site.exp +16 -0
  39. data/ext/ffi_c/libffi/.appveyor/unix-noexec.exp +7 -0
  40. data/ext/ffi_c/libffi/.appveyor.yml +27 -9
  41. data/ext/ffi_c/libffi/.ci/build-cross-in-container.sh +18 -0
  42. data/ext/ffi_c/libffi/{.travis → .ci}/build-in-container.sh +4 -6
  43. data/ext/ffi_c/libffi/.ci/build.sh +124 -0
  44. data/ext/ffi_c/libffi/{.travis → .ci}/install.sh +14 -7
  45. data/ext/ffi_c/libffi/.ci/msvs-detect +1103 -0
  46. data/ext/ffi_c/libffi/{.travis → .ci}/site.exp +5 -3
  47. data/ext/ffi_c/libffi/.circleci/config.yml +156 -0
  48. data/ext/ffi_c/libffi/.github/workflows/build.yml +479 -0
  49. data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +172 -0
  50. data/ext/ffi_c/libffi/.gitignore +10 -2
  51. data/ext/ffi_c/libffi/LICENSE +1 -1
  52. data/ext/ffi_c/libffi/Makefile.am +12 -5
  53. data/ext/ffi_c/libffi/Makefile.in +118 -51
  54. data/ext/ffi_c/libffi/README.md +150 -105
  55. data/ext/ffi_c/libffi/acinclude.m4 +10 -112
  56. data/ext/ffi_c/libffi/compile +348 -0
  57. data/ext/ffi_c/libffi/config.guess +623 -556
  58. data/ext/ffi_c/libffi/config.sub +75 -34
  59. data/ext/ffi_c/libffi/configure +4571 -3830
  60. data/ext/ffi_c/libffi/configure.ac +64 -28
  61. data/ext/ffi_c/libffi/configure.host +26 -7
  62. data/ext/ffi_c/libffi/doc/Makefile.in +9 -6
  63. data/ext/ffi_c/libffi/doc/libffi.texi +82 -33
  64. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  65. data/ext/ffi_c/libffi/fficonfig.h.in +12 -47
  66. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +163 -52
  67. data/ext/ffi_c/libffi/include/Makefile.am +1 -1
  68. data/ext/ffi_c/libffi/include/Makefile.in +10 -9
  69. data/ext/ffi_c/libffi/include/ffi.h.in +55 -60
  70. data/ext/ffi_c/libffi/include/ffi_cfi.h +21 -0
  71. data/ext/ffi_c/libffi/include/ffi_common.h +33 -2
  72. data/ext/ffi_c/libffi/include/tramp.h +45 -0
  73. data/ext/ffi_c/libffi/install-sh +92 -69
  74. data/ext/ffi_c/libffi/libffi.map.in +5 -0
  75. data/ext/ffi_c/libffi/libtool-version +2 -2
  76. data/ext/ffi_c/libffi/ltmain.sh +518 -333
  77. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +18 -14
  78. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +108 -72
  79. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +76 -45
  80. data/ext/ffi_c/libffi/m4/ax_prepend_flag.m4 +51 -0
  81. data/ext/ffi_c/libffi/man/Makefile.in +9 -6
  82. data/ext/ffi_c/libffi/missing +1 -1
  83. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +2 -2
  84. data/ext/ffi_c/libffi/msvcc.sh +1 -1
  85. data/ext/ffi_c/libffi/src/aarch64/ffi.c +172 -55
  86. data/ext/ffi_c/libffi/src/aarch64/internal.h +32 -0
  87. data/ext/ffi_c/libffi/src/aarch64/sysv.S +331 -87
  88. data/ext/ffi_c/libffi/src/arc/arcompact.S +169 -94
  89. data/ext/ffi_c/libffi/src/arc/ffi.c +325 -148
  90. data/ext/ffi_c/libffi/src/arc/ffitarget.h +14 -0
  91. data/ext/ffi_c/libffi/src/arm/ffi.c +62 -17
  92. data/ext/ffi_c/libffi/src/arm/ffitarget.h +3 -3
  93. data/ext/ffi_c/libffi/src/arm/internal.h +10 -0
  94. data/ext/ffi_c/libffi/src/arm/sysv.S +113 -42
  95. data/ext/ffi_c/libffi/src/closures.c +136 -50
  96. data/ext/ffi_c/libffi/src/debug.c +2 -2
  97. data/ext/ffi_c/libffi/src/dlmalloc.c +6 -1
  98. data/ext/ffi_c/libffi/src/ia64/ffi.c +12 -0
  99. data/ext/ffi_c/libffi/src/ia64/unix.S +20 -2
  100. data/ext/ffi_c/libffi/src/loongarch64/ffi.c +624 -0
  101. data/ext/ffi_c/libffi/src/loongarch64/ffitarget.h +82 -0
  102. data/ext/ffi_c/libffi/src/loongarch64/sysv.S +327 -0
  103. data/ext/ffi_c/libffi/src/m32r/ffi.c +31 -14
  104. data/ext/ffi_c/libffi/src/mips/ffi.c +250 -67
  105. data/ext/ffi_c/libffi/src/mips/ffitarget.h +7 -0
  106. data/ext/ffi_c/libffi/src/mips/n32.S +193 -33
  107. data/ext/ffi_c/libffi/src/mips/o32.S +61 -4
  108. data/ext/ffi_c/libffi/src/moxie/ffi.c +47 -22
  109. data/ext/ffi_c/libffi/src/or1k/ffi.c +25 -12
  110. data/ext/ffi_c/libffi/src/pa/ffi.c +32 -33
  111. data/ext/ffi_c/libffi/src/pa/ffi64.c +614 -0
  112. data/ext/ffi_c/libffi/src/pa/ffitarget.h +22 -8
  113. data/ext/ffi_c/libffi/src/pa/hpux32.S +83 -36
  114. data/ext/ffi_c/libffi/src/pa/hpux64.S +681 -0
  115. data/ext/ffi_c/libffi/src/pa/linux.S +82 -35
  116. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +36 -24
  117. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1 -1
  118. data/ext/ffi_c/libffi/src/powerpc/linux64.S +2 -0
  119. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +2 -0
  120. data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
  121. data/ext/ffi_c/libffi/src/prep_cif.c +22 -2
  122. data/ext/ffi_c/libffi/src/riscv/ffi.c +37 -4
  123. data/ext/ffi_c/libffi/src/sparc/ffi64.c +23 -1
  124. data/ext/ffi_c/libffi/src/tramp.c +716 -0
  125. data/ext/ffi_c/libffi/src/types.c +4 -6
  126. data/ext/ffi_c/libffi/src/wasm32/ffi.c +947 -0
  127. data/ext/ffi_c/libffi/src/wasm32/ffitarget.h +62 -0
  128. data/ext/ffi_c/libffi/src/x86/ffi.c +99 -37
  129. data/ext/ffi_c/libffi/src/x86/ffi64.c +67 -12
  130. data/ext/ffi_c/libffi/src/x86/ffitarget.h +9 -5
  131. data/ext/ffi_c/libffi/src/x86/ffiw64.c +44 -1
  132. data/ext/ffi_c/libffi/src/x86/internal.h +14 -0
  133. data/ext/ffi_c/libffi/src/x86/internal64.h +14 -0
  134. data/ext/ffi_c/libffi/src/x86/sysv.S +172 -38
  135. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +91 -88
  136. data/ext/ffi_c/libffi/src/x86/unix64.S +96 -6
  137. data/ext/ffi_c/libffi/src/x86/win64.S +20 -7
  138. data/ext/ffi_c/libffi/src/xtensa/ffi.c +16 -8
  139. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +4 -0
  140. data/ext/ffi_c/libffi/src/xtensa/sysv.S +26 -16
  141. data/ext/ffi_c/libffi/testsuite/Makefile.am +79 -114
  142. data/ext/ffi_c/libffi/testsuite/Makefile.in +89 -121
  143. data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +54 -0
  144. data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +63 -0
  145. data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +86 -0
  146. data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +48 -0
  147. data/ext/ffi_c/libffi/testsuite/emscripten/test.html +7 -0
  148. data/ext/ffi_c/libffi/testsuite/emscripten/test_libffi.py +51 -0
  149. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +43 -21
  150. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +2 -2
  151. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1 -0
  152. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +5 -1
  153. data/ext/ffi_c/libffi/testsuite/libffi.call/bpo_38748.c +41 -0
  154. data/ext/ffi_c/libffi/testsuite/libffi.call/callback.c +99 -0
  155. data/ext/ffi_c/libffi/testsuite/libffi.call/callback2.c +108 -0
  156. data/ext/ffi_c/libffi/testsuite/libffi.call/callback3.c +114 -0
  157. data/ext/ffi_c/libffi/testsuite/libffi.call/callback4.c +119 -0
  158. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +28 -3
  159. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +3 -0
  160. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +5 -0
  161. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +4 -0
  162. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +4 -0
  163. data/ext/ffi_c/libffi/testsuite/libffi.call/s55.c +60 -0
  164. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +8 -9
  165. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +2 -2
  166. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +2 -2
  167. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +2 -2
  168. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +1 -1
  169. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_2.c +63 -0
  170. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3.c +65 -0
  171. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3f.c +65 -0
  172. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4.c +67 -0
  173. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4f.c +67 -0
  174. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_big.c +93 -0
  175. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_small.c +61 -0
  176. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_2H.c +63 -0
  177. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_8H.c +90 -0
  178. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -119
  179. data/ext/ffi_c/libffi/testsuite/libffi.call/va_2.c +220 -0
  180. data/ext/ffi_c/libffi/testsuite/libffi.call/va_3.c +154 -0
  181. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +13 -0
  182. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +11 -0
  183. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +15 -0
  184. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn0.c +3 -2
  185. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn1.c +2 -0
  186. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn2.c +2 -0
  187. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn3.c +21 -1
  188. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn4.c +2 -0
  189. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn5.c +2 -0
  190. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn6.c +2 -0
  191. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_loc_fn0.c +7 -6
  192. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_simple.c +6 -0
  193. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_12byte.c +18 -0
  194. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_16byte.c +22 -0
  195. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_18byte.c +24 -0
  196. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_19byte.c +29 -0
  197. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_1_1byte.c +4 -0
  198. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte.c +19 -1
  199. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte1.c +21 -1
  200. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_24byte.c +35 -3
  201. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_2byte.c +13 -0
  202. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3_1byte.c +19 -0
  203. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte1.c +13 -0
  204. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte2.c +13 -0
  205. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +18 -0
  206. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4_1byte.c +22 -0
  207. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4byte.c +13 -0
  208. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5_1_byte.c +29 -1
  209. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5byte.c +19 -1
  210. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_64byte.c +24 -0
  211. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6_1_byte.c +28 -1
  212. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6byte.c +24 -2
  213. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7_1_byte.c +39 -1
  214. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7byte.c +25 -1
  215. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_8byte.c +14 -0
  216. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte1.c +14 -1
  217. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte2.c +14 -2
  218. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_double.c +19 -1
  219. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_float.c +19 -1
  220. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble.c +20 -1
  221. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split.c +40 -25
  222. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split2.c +40 -3
  223. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_pointer.c +19 -1
  224. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint16.c +18 -1
  225. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint32.c +18 -3
  226. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint64.c +18 -1
  227. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint16.c +18 -1
  228. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint32.c +19 -1
  229. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint64.c +19 -1
  230. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_dbls_struct.c +3 -1
  231. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_double_va.c +9 -1
  232. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_float.c +4 -0
  233. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble.c +11 -1
  234. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble_va.c +22 -3
  235. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_schar.c +5 -1
  236. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshort.c +6 -1
  237. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshortchar.c +9 -1
  238. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_uchar.c +9 -1
  239. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushort.c +6 -2
  240. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushortchar.c +9 -1
  241. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer.c +5 -0
  242. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer_stack.c +10 -0
  243. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_schar.c +3 -0
  244. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sint.c +2 -0
  245. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sshort.c +3 -0
  246. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +11 -0
  247. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar.c +3 -0
  248. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint.c +4 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +4 -0
  250. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +4 -0
  251. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulonglong.c +2 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort.c +3 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +1 -138
  254. data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +21 -21
  255. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct.c +32 -9
  256. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct1.c +1 -1
  257. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct10.c +12 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +21 -5
  259. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct12.c +86 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct13.c +115 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct2.c +10 -1
  262. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct3.c +10 -1
  263. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct4.c +9 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct5.c +9 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct6.c +11 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct7.c +9 -0
  267. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct8.c +11 -0
  268. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct9.c +11 -0
  269. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs1.c +86 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs2.c +102 -0
  271. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs3.c +101 -0
  272. data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium.c +1 -1
  273. data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium2.c +1 -1
  274. data/ext/ffi_c/libffi/testsuite/libffi.closures/testclosure.c +6 -1
  275. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest.cc +2 -1
  276. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest_ffi_call.cc +1 -0
  277. data/ext/ffi_c/libffi.bsd.mk +2 -2
  278. data/ext/ffi_c/libffi.darwin.mk +2 -2
  279. data/ext/ffi_c/libffi.gnu.mk +2 -2
  280. data/ext/ffi_c/rbffi.h +1 -1
  281. data/ffi.gemspec +3 -3
  282. data/lib/ffi/autopointer.rb +8 -31
  283. data/lib/ffi/compat.rb +43 -0
  284. data/lib/ffi/data_converter.rb +2 -2
  285. data/lib/ffi/dynamic_library.rb +118 -0
  286. data/lib/ffi/enum.rb +18 -12
  287. data/lib/ffi/ffi.rb +3 -0
  288. data/lib/ffi/function.rb +71 -0
  289. data/lib/ffi/io.rb +2 -2
  290. data/lib/ffi/library.rb +72 -88
  291. data/lib/ffi/library_path.rb +109 -0
  292. data/lib/ffi/managedstruct.rb +1 -1
  293. data/lib/ffi/platform/aarch64-linux/types.conf +74 -3
  294. data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
  295. data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
  296. data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
  297. data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
  298. data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
  299. data/lib/ffi/platform.rb +15 -13
  300. data/lib/ffi/pointer.rb +6 -6
  301. data/lib/ffi/struct.rb +6 -5
  302. data/lib/ffi/struct_layout.rb +3 -3
  303. data/lib/ffi/struct_layout_builder.rb +9 -9
  304. data/lib/ffi/types.rb +65 -37
  305. data/lib/ffi/variadic.rb +19 -8
  306. data/lib/ffi/version.rb +1 -1
  307. data/samples/hello_ractor.rb +11 -0
  308. data/samples/qsort_ractor.rb +28 -0
  309. data/sig/ffi/abstract_memory.rbs +165 -0
  310. data/sig/ffi/auto_pointer.rbs +27 -0
  311. data/sig/ffi/buffer.rbs +18 -0
  312. data/sig/ffi/data_converter.rbs +10 -0
  313. data/sig/ffi/dynamic_library.rbs +9 -0
  314. data/sig/ffi/enum.rbs +38 -0
  315. data/sig/ffi/function.rbs +39 -0
  316. data/sig/ffi/library.rbs +42 -0
  317. data/sig/ffi/native_type.rbs +86 -0
  318. data/sig/ffi/pointer.rbs +42 -0
  319. data/sig/ffi/struct.rbs +76 -0
  320. data/sig/ffi/struct_by_reference.rbs +11 -0
  321. data/sig/ffi/struct_by_value.rbs +7 -0
  322. data/sig/ffi/struct_layout.rbs +9 -0
  323. data/sig/ffi/struct_layout_builder.rbs +5 -0
  324. data/sig/ffi/type.rbs +39 -0
  325. data/sig/ffi.rbs +26 -0
  326. data.tar.gz.sig +0 -0
  327. metadata +122 -28
  328. metadata.gz.sig +1 -0
  329. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +0 -14
  330. data/ext/ffi_c/libffi/.travis/build.sh +0 -142
  331. data/ext/ffi_c/libffi/.travis.yml +0 -83
  332. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +0 -44
  333. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +0 -44
  334. /data/ext/ffi_c/libffi/{.travis → .ci}/ar-lib +0 -0
  335. /data/ext/ffi_c/libffi/{.travis → .ci}/bfin-sim.exp +0 -0
  336. /data/ext/ffi_c/libffi/{.travis → .ci}/compile +0 -0
  337. /data/ext/ffi_c/libffi/{.travis → .ci}/m32r-sim.exp +0 -0
  338. /data/ext/ffi_c/libffi/{.travis → .ci}/moxie-sim.exp +0 -0
  339. /data/ext/ffi_c/libffi/{.travis → .ci}/or1k-sim.exp +0 -0
  340. /data/ext/ffi_c/libffi/{.travis → .ci}/powerpc-eabisim.exp +0 -0
  341. /data/ext/ffi_c/libffi/{.travis → .ci}/wine-sim.exp +0 -0
  342. /data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
  343. /data/lib/ffi/platform/{sparc64-linux → sparcv9-linux}/types.conf +0 -0
@@ -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
  }
@@ -314,14 +324,14 @@ memory_clear(VALUE self)
314
324
  /*
315
325
  * call-seq: memory.size
316
326
  * Return memory size in bytes (alias: #total)
317
- * @return [Numeric]
327
+ * @return [Integer]
318
328
  */
319
329
  static VALUE
320
330
  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
  }
@@ -330,7 +340,7 @@ memory_size(VALUE self)
330
340
  * call-seq: memory.get(type, offset)
331
341
  * Return data of given type contained in memory.
332
342
  * @param [Symbol, Type] type_name type of data to get
333
- * @param [Numeric] offset point in buffer to start from
343
+ * @param [Integer] offset point in buffer to start from
334
344
  * @return [Object]
335
345
  * @raise {ArgumentError} if type is not supported
336
346
  */
@@ -340,14 +350,15 @@ memory_get(VALUE self, VALUE type_name, VALUE offset)
340
350
  AbstractMemory* ptr;
341
351
  VALUE nType;
342
352
  Type *type;
353
+ MemoryOp *op;
343
354
 
344
355
  nType = rbffi_Type_Lookup(type_name);
345
356
  if(NIL_P(nType)) goto undefined_type;
346
357
 
347
- Data_Get_Struct(self, AbstractMemory, ptr);
348
- Data_Get_Struct(nType, Type, type);
358
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
359
+ TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
349
360
 
350
- MemoryOp *op = get_memory_op(type);
361
+ op = get_memory_op(type);
351
362
  if(op == NULL) goto undefined_type;
352
363
 
353
364
  return op->get(ptr, NUM2LONG(offset));
@@ -362,7 +373,7 @@ undefined_type: {
362
373
  /*
363
374
  * call-seq: memory.put(type, offset, value)
364
375
  * @param [Symbol, Type] type_name type of data to put
365
- * @param [Numeric] offset point in buffer to start from
376
+ * @param [Integer] offset point in buffer to start from
366
377
  * @return [nil]
367
378
  * @raise {ArgumentError} if type is not supported
368
379
  */
@@ -372,14 +383,15 @@ memory_put(VALUE self, VALUE type_name, VALUE offset, VALUE value)
372
383
  AbstractMemory* ptr;
373
384
  VALUE nType;
374
385
  Type *type;
386
+ MemoryOp *op;
375
387
 
376
388
  nType = rbffi_Type_Lookup(type_name);
377
389
  if(NIL_P(nType)) goto undefined_type;
378
390
 
379
- Data_Get_Struct(self, AbstractMemory, ptr);
380
- Data_Get_Struct(nType, Type, type);
391
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
392
+ TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
381
393
 
382
- MemoryOp *op = get_memory_op(type);
394
+ op = get_memory_op(type);
383
395
  if(op == NULL) goto undefined_type;
384
396
 
385
397
  op->put(ptr, NUM2LONG(offset), value);
@@ -395,8 +407,8 @@ undefined_type: {
395
407
  /*
396
408
  * call-seq: memory.get_string(offset, length=nil)
397
409
  * Return string contained in memory.
398
- * @param [Numeric] offset point in buffer to start from
399
- * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
410
+ * @param [Integer] offset point in buffer to start from
411
+ * @param [Integer] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
400
412
  * @return [String]
401
413
  * @raise {IndexError} if +length+ is too great
402
414
  * @raise {NullPointerError} if memory not initialized
@@ -423,8 +435,8 @@ memory_get_string(int argc, VALUE* argv, VALUE self)
423
435
  /*
424
436
  * call-seq: memory.get_array_of_string(offset, count=nil)
425
437
  * Return an array of strings contained in memory.
426
- * @param [Numeric] offset point in memory to start from
427
- * @param [Numeric] count number of strings to get. If nil, return all strings
438
+ * @param [Integer] offset point in memory to start from
439
+ * @param [Integer] count number of strings to get. If nil, return all strings
428
440
  * @return [Array<String>]
429
441
  * @raise {IndexError} if +offset+ is too great
430
442
  * @raise {NullPointerError} if memory not initialized
@@ -442,7 +454,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
442
454
  count = (countnum == Qnil ? 0 : NUM2INT(countnum));
443
455
  retVal = rb_ary_new2(count);
444
456
 
445
- Data_Get_Struct(self, AbstractMemory, ptr);
457
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
446
458
  checkRead(ptr);
447
459
 
448
460
  if (countnum != Qnil) {
@@ -473,7 +485,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
473
485
  * call-seq: memory.read_array_of_string(count=nil)
474
486
  * Return an array of strings contained in memory. Same as:
475
487
  * memory.get_array_of_string(0, count)
476
- * @param [Numeric] count number of strings to get. If nil, return all strings
488
+ * @param [Integer] count number of strings to get. If nil, return all strings
477
489
  * @return [Array<String>]
478
490
  */
479
491
  static VALUE
@@ -493,7 +505,7 @@ memory_read_array_of_string(int argc, VALUE* argv, VALUE self)
493
505
 
494
506
  /*
495
507
  * call-seq: memory.put_string(offset, str)
496
- * @param [Numeric] offset
508
+ * @param [Integer] offset
497
509
  * @param [String] str
498
510
  * @return [self]
499
511
  * @raise {SecurityError} when writing unsafe string to memory
@@ -523,8 +535,8 @@ memory_put_string(VALUE self, VALUE offset, VALUE str)
523
535
  /*
524
536
  * call-seq: memory.get_bytes(offset, length)
525
537
  * Return string contained in memory.
526
- * @param [Numeric] offset point in buffer to start from
527
- * @param [Numeric] length string's length in bytes.
538
+ * @param [Integer] offset point in buffer to start from
539
+ * @param [Integer] length string's length in bytes.
528
540
  * @return [String]
529
541
  * @raise {IndexError} if +length+ is too great
530
542
  * @raise {NullPointerError} if memory not initialized
@@ -547,10 +559,10 @@ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
547
559
  /*
548
560
  * call-seq: memory.put_bytes(offset, str, index=0, length=nil)
549
561
  * Put a string in memory.
550
- * @param [Numeric] offset point in buffer to start from
562
+ * @param [Integer] offset point in buffer to start from
551
563
  * @param [String] str string to put to memory
552
- * @param [Numeric] index
553
- * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
564
+ * @param [Integer] index
565
+ * @param [Integer] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
554
566
  * @return [self]
555
567
  * @raise {IndexError} if +length+ is too great
556
568
  * @raise {NullPointerError} if memory not initialized
@@ -589,7 +601,7 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
589
601
 
590
602
  /*
591
603
  * call-seq: memory.read_bytes(length)
592
- * @param [Numeric] length of string to return
604
+ * @param [Integer] length of string to return
593
605
  * @return [String]
594
606
  * equivalent to :
595
607
  * memory.get_bytes(0, length)
@@ -603,8 +615,8 @@ memory_read_bytes(VALUE self, VALUE length)
603
615
  /*
604
616
  * call-seq: memory.write_bytes(str, index=0, length=nil)
605
617
  * @param [String] str string to put to memory
606
- * @param [Numeric] index
607
- * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
618
+ * @param [Integer] index
619
+ * @param [Integer] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
608
620
  * @return [self]
609
621
  * equivalent to :
610
622
  * memory.put_bytes(0, str, index, length)
@@ -625,7 +637,7 @@ memory_write_bytes(int argc, VALUE* argv, VALUE self)
625
637
 
626
638
  /*
627
639
  * call-seq: memory.type_size
628
- * @return [Numeric] type size in bytes
640
+ * @return [Integer] type size in bytes
629
641
  * Get the memory's type size.
630
642
  */
631
643
  static VALUE
@@ -633,7 +645,7 @@ memory_type_size(VALUE self)
633
645
  {
634
646
  AbstractMemory* ptr;
635
647
 
636
- Data_Get_Struct(self, AbstractMemory, ptr);
648
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
637
649
 
638
650
  return INT2NUM(ptr->typeSize);
639
651
  }
@@ -641,7 +653,7 @@ memory_type_size(VALUE self)
641
653
  /*
642
654
  * Document-method: []
643
655
  * call-seq: memory[idx]
644
- * @param [Numeric] idx index to access in memory
656
+ * @param [Integer] idx index to access in memory
645
657
  * @return
646
658
  * Memory read accessor.
647
659
  */
@@ -651,7 +663,7 @@ memory_aref(VALUE self, VALUE idx)
651
663
  AbstractMemory* ptr;
652
664
  VALUE rbOffset = Qnil;
653
665
 
654
- Data_Get_Struct(self, AbstractMemory, ptr);
666
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
655
667
 
656
668
  rbOffset = ULONG2NUM(NUM2ULONG(idx) * ptr->typeSize);
657
669
 
@@ -661,7 +673,9 @@ memory_aref(VALUE self, VALUE idx)
661
673
  static inline char*
662
674
  memory_address(VALUE obj)
663
675
  {
664
- return ((AbstractMemory *) DATA_PTR(obj))->address;
676
+ AbstractMemory *mem;
677
+ TypedData_Get_Struct(obj, AbstractMemory, &rbffi_abstract_memory_data_type, mem);
678
+ return mem->address;
665
679
  }
666
680
 
667
681
  static VALUE
@@ -669,24 +683,33 @@ memory_copy_from(VALUE self, VALUE rbsrc, VALUE rblen)
669
683
  {
670
684
  AbstractMemory* dst;
671
685
 
672
- Data_Get_Struct(self, AbstractMemory, dst);
686
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, dst);
673
687
 
674
- memcpy(dst->address, rbffi_AbstractMemory_Cast(rbsrc, rbffi_AbstractMemoryClass)->address, NUM2INT(rblen));
688
+ memcpy(dst->address, rbffi_AbstractMemory_Cast(rbsrc, &rbffi_abstract_memory_data_type)->address, NUM2INT(rblen));
675
689
 
676
690
  return self;
677
691
  }
678
692
 
679
- AbstractMemory*
680
- rbffi_AbstractMemory_Cast(VALUE obj, VALUE klass)
693
+ /*
694
+ * call-seq:
695
+ * res.freeze
696
+ *
697
+ * Freeze the AbstractMemory object and unset the writable flag.
698
+ */
699
+ static VALUE
700
+ memory_freeze(VALUE self)
681
701
  {
682
- if (rb_obj_is_kind_of(obj, klass)) {
683
- AbstractMemory* memory;
684
- Data_Get_Struct(obj, AbstractMemory, memory);
685
- return memory;
686
- }
702
+ AbstractMemory* ptr = MEMORY(self);
703
+ ptr->flags &= ~MEM_WR;
704
+ return rb_call_super(0, NULL);
705
+ }
687
706
 
688
- rb_raise(rb_eArgError, "Invalid Memory object");
689
- return NULL;
707
+ AbstractMemory*
708
+ rbffi_AbstractMemory_Cast(VALUE obj, const rb_data_type_t *data_type)
709
+ {
710
+ AbstractMemory* memory;
711
+ TypedData_Get_Struct(obj, AbstractMemory, data_type, memory);
712
+ return memory;
690
713
  }
691
714
 
692
715
  void
@@ -781,7 +804,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
781
804
  * Document-variable: FFI::AbstractMemory
782
805
  */
783
806
  rb_global_variable(&rbffi_AbstractMemoryClass);
784
- rb_define_alloc_func(classMemory, memory_allocate);
807
+ rb_undef_alloc_func(classMemory);
785
808
 
786
809
  NullPointerErrorClass = rb_define_class_under(moduleFFI, "NullPointerError", rb_eRuntimeError);
787
810
  /* Document-variable: NullPointerError */
@@ -838,8 +861,8 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
838
861
 
839
862
  /*
840
863
  * Document-method: put_float32
841
- * call-seq: memory.put_float32offset, value)
842
- * @param [Numeric] offset
864
+ * call-seq: memory.put_float32(offset, value)
865
+ * @param [Integer] offset
843
866
  * @param [Numeric] value
844
867
  * @return [self]
845
868
  * Put +value+ as a 32-bit float in memory at offset +offset+ (alias: #put_float).
@@ -848,7 +871,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
848
871
  /*
849
872
  * Document-method: get_float32
850
873
  * call-seq: memory.get_float32(offset)
851
- * @param [Numeric] offset
874
+ * @param [Integer] offset
852
875
  * @return [Float]
853
876
  * Get a 32-bit float from memory at offset +offset+ (alias: #get_float).
854
877
  */
@@ -879,7 +902,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
879
902
  /*
880
903
  * Document-method: put_array_of_float32
881
904
  * call-seq: memory.put_array_of_float32(offset, ary)
882
- * @param [Numeric] offset
905
+ * @param [Integer] offset
883
906
  * @param [Array<Numeric>] ary
884
907
  * @return [self]
885
908
  * Put values from +ary+ as 32-bit floats in memory from offset +offset+ (alias: #put_array_of_float).
@@ -888,8 +911,8 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
888
911
  /*
889
912
  * Document-method: get_array_of_float32
890
913
  * call-seq: memory.get_array_of_float32(offset, length)
891
- * @param [Numeric] offset
892
- * @param [Numeric] length number of Float to get
914
+ * @param [Integer] offset
915
+ * @param [Integer] length number of Float to get
893
916
  * @return [Array<Float>]
894
917
  * Get 32-bit floats in memory from offset +offset+ (alias: #get_array_of_float).
895
918
  */
@@ -908,7 +931,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
908
931
  /*
909
932
  * Document-method: read_array_of_float
910
933
  * call-seq: memory.read_array_of_float(length)
911
- * @param [Numeric] length number of Float to read
934
+ * @param [Integer] length number of Float to read
912
935
  * @return [Array<Float>]
913
936
  * Read 32-bit floats from memory.
914
937
  *
@@ -921,7 +944,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
921
944
  /*
922
945
  * Document-method: put_float64
923
946
  * call-seq: memory.put_float64(offset, value)
924
- * @param [Numeric] offset
947
+ * @param [Integer] offset
925
948
  * @param [Numeric] value
926
949
  * @return [self]
927
950
  * Put +value+ as a 64-bit float (double) in memory at offset +offset+ (alias: #put_double).
@@ -930,7 +953,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
930
953
  /*
931
954
  * Document-method: get_float64
932
955
  * call-seq: memory.get_float64(offset)
933
- * @param [Numeric] offset
956
+ * @param [Integer] offset
934
957
  * @return [Float]
935
958
  * Get a 64-bit float (double) from memory at offset +offset+ (alias: #get_double).
936
959
  */
@@ -961,7 +984,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
961
984
  /*
962
985
  * Document-method: put_array_of_float64
963
986
  * call-seq: memory.put_array_of_float64(offset, ary)
964
- * @param [Numeric] offset
987
+ * @param [Integer] offset
965
988
  * @param [Array<Numeric>] ary
966
989
  * @return [self]
967
990
  * Put values from +ary+ as 64-bit floats (doubles) in memory from offset +offset+ (alias: #put_array_of_double).
@@ -970,8 +993,8 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
970
993
  /*
971
994
  * Document-method: get_array_of_float64
972
995
  * call-seq: memory.get_array_of_float64(offset, length)
973
- * @param [Numeric] offset
974
- * @param [Numeric] length number of Float to get
996
+ * @param [Integer] offset
997
+ * @param [Integer] length number of Float to get
975
998
  * @return [Array<Float>]
976
999
  * Get 64-bit floats (doubles) in memory from offset +offset+ (alias: #get_array_of_double).
977
1000
  */
@@ -990,7 +1013,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
990
1013
  /*
991
1014
  * Document-method: read_array_of_double
992
1015
  * call-seq: memory.read_array_of_double(length)
993
- * @param [Numeric] length number of Float to read
1016
+ * @param [Integer] length number of Float to read
994
1017
  * @return [Array<Float>]
995
1018
  * Read 64-bit floats (doubles) from memory.
996
1019
  *
@@ -1003,7 +1026,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
1003
1026
  /*
1004
1027
  * Document-method: put_pointer
1005
1028
  * call-seq: memory.put_pointer(offset, value)
1006
- * @param [Numeric] offset
1029
+ * @param [Integer] offset
1007
1030
  * @param [nil,Pointer, Integer, #to_ptr] value
1008
1031
  * @return [self]
1009
1032
  * Put +value+ in memory from +offset+..
@@ -1012,7 +1035,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
1012
1035
  /*
1013
1036
  * Document-method: get_pointer
1014
1037
  * call-seq: memory.get_pointer(offset)
1015
- * @param [Numeric] offset
1038
+ * @param [Integer] offset
1016
1039
  * @return [Pointer]
1017
1040
  * Get a {Pointer} to the memory from +offset+.
1018
1041
  */
@@ -1041,7 +1064,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
1041
1064
  /*
1042
1065
  * Document-method: put_array_of_pointer
1043
1066
  * call-seq: memory.put_array_of_pointer(offset, ary)
1044
- * @param [Numeric] offset
1067
+ * @param [Integer] offset
1045
1068
  * @param [Array<#to_ptr>] ary
1046
1069
  * @return [self]
1047
1070
  * Put an array of {Pointer} into memory from +offset+.
@@ -1050,8 +1073,8 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
1050
1073
  /*
1051
1074
  * Document-method: get_array_of_pointer
1052
1075
  * call-seq: memory.get_array_of_pointer(offset, length)
1053
- * @param [Numeric] offset
1054
- * @param [Numeric] length
1076
+ * @param [Integer] offset
1077
+ * @param [Integer] length
1055
1078
  * @return [Array<Pointer>]
1056
1079
  * Get an array of {Pointer} of length +length+ from +offset+.
1057
1080
  */
@@ -1070,7 +1093,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
1070
1093
  /*
1071
1094
  * Document-method: read_array_of_pointer
1072
1095
  * call-seq: memory.read_array_of_pointer(length)
1073
- * @param [Numeric] length
1096
+ * @param [Integer] length
1074
1097
  * @return [Array<Pointer>]
1075
1098
  * Read an array of {Pointer} of length +length+.
1076
1099
  *
@@ -1086,6 +1109,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
1086
1109
  rb_define_method(classMemory, "read_bytes", memory_read_bytes, 1);
1087
1110
  rb_define_method(classMemory, "write_bytes", memory_write_bytes, -1);
1088
1111
  rb_define_method(classMemory, "get_array_of_string", memory_get_array_of_string, -1);
1112
+ rb_define_method(classMemory, "read_array_of_string", memory_read_array_of_string, -1);
1089
1113
 
1090
1114
  rb_define_method(classMemory, "get", memory_get, 2);
1091
1115
  rb_define_method(classMemory, "put", memory_put, 3);
@@ -1096,6 +1120,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
1096
1120
  rb_define_method(classMemory, "type_size", memory_type_size, 0);
1097
1121
  rb_define_method(classMemory, "[]", memory_aref, 1);
1098
1122
  rb_define_method(classMemory, "__copy_from__", memory_copy_from, 2);
1123
+ rb_define_method(classMemory, "freeze", memory_freeze, 0 );
1099
1124
 
1100
1125
  id_to_ptr = rb_intern("to_ptr");
1101
1126
  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,37 +62,55 @@ 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)
76
112
  * @param [Type] component_type
77
- * @param [Numeric] length
113
+ * @param [Integer] length
78
114
  * @return [self]
79
115
  * A new instance of ArrayType.
80
116
  */
@@ -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;
@@ -104,7 +140,7 @@ array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength)
104
140
 
105
141
  /*
106
142
  * call-seq: length
107
- * @return [Numeric]
143
+ * @return [Integer]
108
144
  * Get array's length
109
145
  */
110
146
  static VALUE
@@ -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