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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bcc7a331092d1e4b89f817ea0aa8b3f13a9e58d68df67d9a04a825c16ae65a9
4
- data.tar.gz: 8d7e7bbb75e7f19235c7ef6b9e814b09141f8f46b15a248f86fbe95551f26e72
3
+ metadata.gz: 5920bab18c2bfca946febdf9d31aae894569dd1a293d816631a077696f7db8fa
4
+ data.tar.gz: 7aa17dd90399d15bd149573ab4b9857907028beae4f84409f76f50e9508aaba2
5
5
  SHA512:
6
- metadata.gz: 8bf963e42331b77650954eee5aca3c1b2a780bf27f31cf6d85ff048efac8f60b40e484a0883512df5f81c00ce04ba22382e813e71d074f35f9f539c6366b7aa9
7
- data.tar.gz: b36841f7eda33b367c877d8e8b3480096582abc73ddbac2a278e33943a9cb3afff1cbc323e0b0fceac3c8ef86f5b4e6d1cbede107f09e9444910dd56bcfa5444
6
+ metadata.gz: dd42730736988cac47f45485f4a8b200c26759066fe156a89ef7736cd6ac80f404e8aaced28a8f10f9b22b43436ed3e248cb191f1c457ccabc19299b91b49174
7
+ data.tar.gz: '0252969e7a324d530c1d704e2d408f1bd7283f320de90b4c98f20bb49f9d32733ac45609d78a40f821cd5335e102e80576fd446cd5de863babea041d0eb3c780'
checksums.yaml.gz.sig ADDED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,3 +1,93 @@
1
+ 1.16.3 / 2023-10-04
2
+ -------------------
3
+
4
+ Fixed:
5
+ * Fix gcc error when building on CentOS 7. #1052
6
+ * Avoid trying to store new DataConverter type in frozen TypeDefs hash. #1057
7
+
8
+
9
+ 1.16.2 / 2023-09-25
10
+ -------------------
11
+
12
+ Fixed:
13
+ * Handle null pointer crash after fork. #1051
14
+
15
+
16
+ 1.16.1 / 2023-09-24
17
+ -------------------
18
+
19
+ Fixed:
20
+ * Fix compiling the builtin libffi. #1049
21
+
22
+
23
+ 1.16.0 / 2023-09-23
24
+ -------------------
25
+
26
+ Fixed:
27
+ * Fix an issue with signed bitmasks when using flags on the most significant bit. #949
28
+ * Fix FFI::Pointer#initialize using NUM2LL instead of NUM2ULL.
29
+ * Fix FFI::Type#inspect to properly display the constant name. #1002
30
+ * Use libffi closure allocations on hppa-Linux. #1017
31
+ Previously they would segfault.
32
+ * Fix class name of Symbol#inspect.
33
+ * Fix MSVC support of libtest. #1028
34
+ * Fix attach_function of functions ending in ? or ! #971
35
+
36
+ Added:
37
+ * 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
38
+ 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.
39
+ * Implement `ObjectSpace.memsize_of()` of all C-based classes.
40
+ * Make FFI Ractor compatible. #1023
41
+ Modules extended per `extend FFI::Library` need to be frozen in order to be used by non-main Ractors.
42
+ This can be done by calling `freeze` below of all C interface definitions.
43
+ * In a Ractor it's possible to:
44
+ * load DLLs and call its functions, access its global variables
45
+ * use builtin typedefs
46
+ * use and modify ractor local typedefs
47
+ * define callbacks
48
+ * receive async callbacks from non-ruby threads
49
+ * use frozen FFI::Library based modules with all attributes (enums, structs, typedefs, functions, callbacks)
50
+ * invoke frozen functions and callbacks defined in the main Ractor
51
+ * use FFI::Struct definitions from the main Ractor
52
+ * In a Ractor it's impossible to:
53
+ * create new FFI::Library based modules
54
+ * create new FFI::Struct definitions
55
+ * use custom global typedefs
56
+ * use non-frozen FFI::Library based modules
57
+ * Allow type retrieval of attached functions+variables. #1023
58
+ * Make FFI classes `GC.compact` friendly. #1021
59
+ * Update libffi and disable custom trampoline when using libffi closure allocation. #1020
60
+ This is because libffi changed the way how closures are allocated to static trampolines.
61
+ * Add types.conf for loongarch64-linux. #943
62
+ * Add types.conf for sw_64-linux (Shen Wei 64-bit, based on Alpha). #1018
63
+ * Add support for aarch64-windows. #1035
64
+ * Windows: Update LoadLibrary error message to include error code. #1026
65
+ * Allow private release method for FFI::ManagedStruct and FFI::AutoPointer. #1029
66
+ * Add support for passing ABI version to FFI.map_library_name. #963
67
+ This adds the new class FFI::LibraryPath .
68
+ * Add support for ruby-3.2 to windows binary gem. #1047
69
+ * Enable debug symbols for `rake compile` builds to ease debugging. #1048
70
+
71
+ Removed:
72
+ * Remove allocator of AbstractMemory. #1013
73
+ This disables AbstractMemory.new, which has no practical use.
74
+ * Remove unused FFI::SizeTypes. #1022
75
+
76
+
77
+ 1.15.5 / 2022-01-10
78
+ -------------------
79
+
80
+ Fixed:
81
+ * Fix long double argument or return values on 32bit i686. #849
82
+ * FFI::ConstGenerator: avoid usage of the same binary file simultaneously. #929
83
+
84
+ Added:
85
+ * Add Windows fat binary gem for Ruby-3.1
86
+
87
+ Removed:
88
+ * Remove Windows fat binary gem for Ruby < 2.4
89
+
90
+
1
91
  1.15.4 / 2021-09-01
2
92
  -------------------
3
93
 
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: [How-to-use-FFI-in-Ruby-Ractors](https://github.com/ffi/ffi/wiki/Ractors)
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'
@@ -18,7 +18,7 @@ RSpec::Core::RakeTask.new(:spec => :compile) do |config|
18
18
  end
19
19
 
20
20
  desc "Build all packages"
21
- task :package => %w[ gem:java gem:windows ]
21
+ task :package => %w[ gem:java gem:native ]
22
22
 
23
23
  CLOBBER.include 'lib/ffi/types.conf'
24
24
  CLOBBER.include 'pkg'
@@ -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(
@@ -86,7 +85,9 @@ task 'gem:java' => 'java:gem'
86
85
 
87
86
  FfiGemHelper.install_tasks
88
87
  # Register windows gems to be pushed to rubygems.org
89
- Bundler::GemHelper.instance.cross_platforms = %w[x86-mingw32 x64-mingw32]
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
@@ -108,11 +111,25 @@ else
108
111
  end
109
112
 
110
113
 
111
- desc "build a windows gem without all the ceremony"
112
- task "gem:windows" do
113
- require "rake_compiler_dock"
114
- sh "bundle package"
115
- RakeCompilerDock.sh "sudo apt-get update && sudo apt-get install -y libltdl-dev && bundle --local && rake cross native gem MAKE='nice make -j`nproc`' RUBY_CC_VERSION=${RUBY_CC_VERSION/:2.2.2/}"
114
+ namespace "gem" do
115
+ task 'prepare' do
116
+ require 'rake_compiler_dock'
117
+ sh "bundle package --all"
118
+ end
119
+
120
+ Bundler::GemHelper.instance.cross_platforms.each do |plat|
121
+ desc "Build all native binary gems in parallel"
122
+ multitask 'native' => plat
123
+
124
+ desc "Build the native gem for #{plat}"
125
+ task plat => ['prepare', 'build'] do
126
+ RakeCompilerDock.sh <<-EOT, platform: plat
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/}
130
+ EOT
131
+ end
132
+ end
116
133
  end
117
134
 
118
135
  directory "ext/ffi_c/libffi"
@@ -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
  }
@@ -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));
@@ -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);
@@ -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) {
@@ -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
  }
@@ -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 */
@@ -1096,6 +1119,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
1096
1119
  rb_define_method(classMemory, "type_size", memory_type_size, 0);
1097
1120
  rb_define_method(classMemory, "[]", memory_aref, 1);
1098
1121
  rb_define_method(classMemory, "__copy_from__", memory_copy_from, 2);
1122
+ rb_define_method(classMemory, "freeze", memory_freeze, 0 );
1099
1123
 
1100
1124
  id_to_ptr = rb_intern("to_ptr");
1101
1125
  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