ffi 1.15.4 → 1.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (312) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +90 -0
  4. data/Gemfile +1 -1
  5. data/README.md +3 -2
  6. data/Rakefile +28 -11
  7. data/ext/ffi_c/AbstractMemory.c +60 -36
  8. data/ext/ffi_c/AbstractMemory.h +3 -2
  9. data/ext/ffi_c/ArrayType.c +49 -13
  10. data/ext/ffi_c/ArrayType.h +1 -0
  11. data/ext/ffi_c/Buffer.c +86 -29
  12. data/ext/ffi_c/Call.c +18 -7
  13. data/ext/ffi_c/DynamicLibrary.c +89 -26
  14. data/ext/ffi_c/Function.c +244 -98
  15. data/ext/ffi_c/Function.h +1 -0
  16. data/ext/ffi_c/FunctionInfo.c +80 -24
  17. data/ext/ffi_c/LastError.c +25 -7
  18. data/ext/ffi_c/MappedType.c +66 -23
  19. data/ext/ffi_c/MappedType.h +0 -2
  20. data/ext/ffi_c/MemoryPointer.c +34 -7
  21. data/ext/ffi_c/MethodHandle.c +3 -1
  22. data/ext/ffi_c/Pointer.c +68 -29
  23. data/ext/ffi_c/Pointer.h +1 -0
  24. data/ext/ffi_c/Struct.c +155 -80
  25. data/ext/ffi_c/Struct.h +7 -4
  26. data/ext/ffi_c/StructByValue.c +48 -16
  27. data/ext/ffi_c/StructLayout.c +117 -48
  28. data/ext/ffi_c/Type.c +104 -36
  29. data/ext/ffi_c/Type.h +3 -1
  30. data/ext/ffi_c/Types.c +1 -1
  31. data/ext/ffi_c/Variadic.c +65 -23
  32. data/ext/ffi_c/compat.h +22 -22
  33. data/ext/ffi_c/extconf.rb +19 -2
  34. data/ext/ffi_c/ffi.c +4 -0
  35. data/ext/ffi_c/libffi/.appveyor/site.exp +16 -0
  36. data/ext/ffi_c/libffi/.appveyor/unix-noexec.exp +7 -0
  37. data/ext/ffi_c/libffi/.appveyor.yml +27 -9
  38. data/ext/ffi_c/libffi/.ci/build-cross-in-container.sh +18 -0
  39. data/ext/ffi_c/libffi/{.travis → .ci}/build-in-container.sh +4 -6
  40. data/ext/ffi_c/libffi/.ci/build.sh +124 -0
  41. data/ext/ffi_c/libffi/{.travis → .ci}/install.sh +14 -7
  42. data/ext/ffi_c/libffi/.ci/msvs-detect +1103 -0
  43. data/ext/ffi_c/libffi/{.travis → .ci}/site.exp +5 -3
  44. data/ext/ffi_c/libffi/.circleci/config.yml +156 -0
  45. data/ext/ffi_c/libffi/.github/workflows/build.yml +460 -0
  46. data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +171 -0
  47. data/ext/ffi_c/libffi/.gitignore +10 -2
  48. data/ext/ffi_c/libffi/LICENSE +1 -1
  49. data/ext/ffi_c/libffi/Makefile.am +12 -5
  50. data/ext/ffi_c/libffi/Makefile.in +92 -34
  51. data/ext/ffi_c/libffi/README.md +144 -104
  52. data/ext/ffi_c/libffi/acinclude.m4 +10 -112
  53. data/ext/ffi_c/libffi/compile +348 -0
  54. data/ext/ffi_c/libffi/config.guess +623 -556
  55. data/ext/ffi_c/libffi/config.sub +75 -34
  56. data/ext/ffi_c/libffi/configure +4567 -3822
  57. data/ext/ffi_c/libffi/configure.ac +64 -28
  58. data/ext/ffi_c/libffi/configure.host +25 -6
  59. data/ext/ffi_c/libffi/doc/Makefile.in +9 -6
  60. data/ext/ffi_c/libffi/doc/libffi.texi +82 -33
  61. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  62. data/ext/ffi_c/libffi/fficonfig.h.in +12 -47
  63. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +163 -52
  64. data/ext/ffi_c/libffi/include/Makefile.am +1 -1
  65. data/ext/ffi_c/libffi/include/Makefile.in +10 -9
  66. data/ext/ffi_c/libffi/include/ffi.h.in +54 -50
  67. data/ext/ffi_c/libffi/include/ffi_cfi.h +21 -0
  68. data/ext/ffi_c/libffi/include/ffi_common.h +29 -0
  69. data/ext/ffi_c/libffi/include/tramp.h +45 -0
  70. data/ext/ffi_c/libffi/libtool-version +2 -2
  71. data/ext/ffi_c/libffi/ltmain.sh +512 -315
  72. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +18 -14
  73. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +108 -72
  74. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +76 -45
  75. data/ext/ffi_c/libffi/m4/ax_prepend_flag.m4 +51 -0
  76. data/ext/ffi_c/libffi/man/Makefile.in +9 -6
  77. data/ext/ffi_c/libffi/missing +1 -1
  78. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +1 -1
  79. data/ext/ffi_c/libffi/msvcc.sh +1 -1
  80. data/ext/ffi_c/libffi/src/aarch64/ffi.c +146 -42
  81. data/ext/ffi_c/libffi/src/aarch64/internal.h +32 -0
  82. data/ext/ffi_c/libffi/src/aarch64/sysv.S +134 -42
  83. data/ext/ffi_c/libffi/src/arc/arcompact.S +169 -94
  84. data/ext/ffi_c/libffi/src/arc/ffi.c +325 -148
  85. data/ext/ffi_c/libffi/src/arc/ffitarget.h +14 -0
  86. data/ext/ffi_c/libffi/src/arm/ffi.c +62 -17
  87. data/ext/ffi_c/libffi/src/arm/ffitarget.h +3 -3
  88. data/ext/ffi_c/libffi/src/arm/internal.h +10 -0
  89. data/ext/ffi_c/libffi/src/arm/sysv.S +113 -42
  90. data/ext/ffi_c/libffi/src/closures.c +133 -47
  91. data/ext/ffi_c/libffi/src/dlmalloc.c +5 -0
  92. data/ext/ffi_c/libffi/src/ia64/ffi.c +12 -0
  93. data/ext/ffi_c/libffi/src/ia64/unix.S +20 -2
  94. data/ext/ffi_c/libffi/src/loongarch64/ffi.c +621 -0
  95. data/ext/ffi_c/libffi/src/loongarch64/ffitarget.h +82 -0
  96. data/ext/ffi_c/libffi/src/loongarch64/sysv.S +327 -0
  97. data/ext/ffi_c/libffi/src/m32r/ffi.c +31 -14
  98. data/ext/ffi_c/libffi/src/mips/ffi.c +240 -65
  99. data/ext/ffi_c/libffi/src/mips/ffitarget.h +7 -0
  100. data/ext/ffi_c/libffi/src/mips/n32.S +137 -28
  101. data/ext/ffi_c/libffi/src/mips/o32.S +61 -4
  102. data/ext/ffi_c/libffi/src/moxie/ffi.c +47 -22
  103. data/ext/ffi_c/libffi/src/or1k/ffi.c +25 -12
  104. data/ext/ffi_c/libffi/src/pa/ffi.c +32 -33
  105. data/ext/ffi_c/libffi/src/pa/ffi64.c +614 -0
  106. data/ext/ffi_c/libffi/src/pa/ffitarget.h +22 -8
  107. data/ext/ffi_c/libffi/src/pa/hpux32.S +83 -36
  108. data/ext/ffi_c/libffi/src/pa/hpux64.S +681 -0
  109. data/ext/ffi_c/libffi/src/pa/linux.S +82 -35
  110. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1 -1
  111. data/ext/ffi_c/libffi/src/powerpc/linux64.S +2 -0
  112. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +2 -0
  113. data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
  114. data/ext/ffi_c/libffi/src/prep_cif.c +22 -2
  115. data/ext/ffi_c/libffi/src/riscv/ffi.c +37 -4
  116. data/ext/ffi_c/libffi/src/sparc/ffi64.c +16 -0
  117. data/ext/ffi_c/libffi/src/tramp.c +716 -0
  118. data/ext/ffi_c/libffi/src/wasm32/ffi.c +934 -0
  119. data/ext/ffi_c/libffi/src/wasm32/ffitarget.h +62 -0
  120. data/ext/ffi_c/libffi/src/x86/ffi.c +99 -37
  121. data/ext/ffi_c/libffi/src/x86/ffi64.c +67 -12
  122. data/ext/ffi_c/libffi/src/x86/ffitarget.h +9 -5
  123. data/ext/ffi_c/libffi/src/x86/ffiw64.c +43 -0
  124. data/ext/ffi_c/libffi/src/x86/internal.h +14 -0
  125. data/ext/ffi_c/libffi/src/x86/internal64.h +14 -0
  126. data/ext/ffi_c/libffi/src/x86/sysv.S +172 -38
  127. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +91 -88
  128. data/ext/ffi_c/libffi/src/x86/unix64.S +96 -6
  129. data/ext/ffi_c/libffi/src/x86/win64.S +20 -7
  130. data/ext/ffi_c/libffi/src/xtensa/ffi.c +16 -8
  131. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +4 -0
  132. data/ext/ffi_c/libffi/src/xtensa/sysv.S +26 -16
  133. data/ext/ffi_c/libffi/testsuite/Makefile.am +127 -114
  134. data/ext/ffi_c/libffi/testsuite/Makefile.in +136 -120
  135. data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +54 -0
  136. data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +63 -0
  137. data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +80 -0
  138. data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +48 -0
  139. data/ext/ffi_c/libffi/testsuite/emscripten/test.html +7 -0
  140. data/ext/ffi_c/libffi/testsuite/emscripten/test_libffi.py +51 -0
  141. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +43 -21
  142. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +2 -2
  143. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1 -0
  144. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +5 -1
  145. data/ext/ffi_c/libffi/testsuite/libffi.call/bpo_38748.c +41 -0
  146. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +28 -3
  147. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +3 -0
  148. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +5 -0
  149. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +4 -0
  150. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +4 -0
  151. data/ext/ffi_c/libffi/testsuite/libffi.call/s55.c +60 -0
  152. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +8 -9
  153. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +2 -2
  154. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +2 -2
  155. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +2 -2
  156. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +1 -1
  157. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_2.c +63 -0
  158. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3.c +65 -0
  159. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3f.c +65 -0
  160. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4.c +67 -0
  161. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4f.c +67 -0
  162. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_big.c +93 -0
  163. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_small.c +61 -0
  164. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_2H.c +63 -0
  165. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_8H.c +90 -0
  166. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -119
  167. data/ext/ffi_c/libffi/testsuite/libffi.call/va_2.c +220 -0
  168. data/ext/ffi_c/libffi/testsuite/libffi.call/va_3.c +154 -0
  169. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +13 -0
  170. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +11 -0
  171. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +15 -0
  172. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn0.c +3 -2
  173. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn1.c +2 -0
  174. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn2.c +2 -0
  175. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn3.c +21 -1
  176. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn4.c +2 -0
  177. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn5.c +2 -0
  178. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn6.c +2 -0
  179. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_loc_fn0.c +7 -6
  180. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_simple.c +6 -0
  181. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_12byte.c +18 -0
  182. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_16byte.c +22 -0
  183. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_18byte.c +24 -0
  184. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_19byte.c +29 -0
  185. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_1_1byte.c +4 -0
  186. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte.c +19 -1
  187. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte1.c +21 -1
  188. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_24byte.c +35 -3
  189. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_2byte.c +13 -0
  190. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3_1byte.c +19 -0
  191. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte1.c +13 -0
  192. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte2.c +13 -0
  193. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +18 -0
  194. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4_1byte.c +22 -0
  195. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4byte.c +13 -0
  196. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5_1_byte.c +29 -1
  197. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5byte.c +19 -1
  198. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_64byte.c +24 -0
  199. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6_1_byte.c +28 -1
  200. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6byte.c +24 -2
  201. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7_1_byte.c +39 -1
  202. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7byte.c +25 -1
  203. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_8byte.c +14 -0
  204. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte1.c +14 -1
  205. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte2.c +14 -2
  206. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_double.c +19 -1
  207. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_float.c +19 -1
  208. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble.c +20 -1
  209. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split.c +40 -25
  210. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split2.c +40 -3
  211. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_pointer.c +19 -1
  212. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint16.c +18 -1
  213. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint32.c +18 -3
  214. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint64.c +18 -1
  215. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint16.c +18 -1
  216. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint32.c +19 -1
  217. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint64.c +19 -1
  218. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_dbls_struct.c +3 -1
  219. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_double_va.c +9 -1
  220. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_float.c +4 -0
  221. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble.c +11 -1
  222. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble_va.c +22 -3
  223. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_schar.c +5 -1
  224. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshort.c +6 -1
  225. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshortchar.c +9 -1
  226. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_uchar.c +9 -1
  227. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushort.c +6 -2
  228. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushortchar.c +9 -1
  229. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer.c +5 -0
  230. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer_stack.c +10 -0
  231. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_schar.c +3 -0
  232. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sint.c +2 -0
  233. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sshort.c +3 -0
  234. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +11 -0
  235. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar.c +3 -0
  236. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint.c +4 -0
  237. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +4 -0
  238. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +4 -0
  239. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulonglong.c +2 -0
  240. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort.c +3 -0
  241. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +1 -138
  242. data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +21 -21
  243. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct.c +32 -9
  244. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct1.c +1 -1
  245. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct10.c +12 -0
  246. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +21 -5
  247. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct12.c +86 -0
  248. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct13.c +115 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct2.c +10 -1
  250. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct3.c +10 -1
  251. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct4.c +9 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct5.c +9 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct6.c +11 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct7.c +9 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct8.c +11 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct9.c +11 -0
  257. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs1.c +86 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs2.c +102 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs3.c +101 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium.c +1 -1
  261. data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium2.c +1 -1
  262. data/ext/ffi_c/libffi/testsuite/libffi.closures/testclosure.c +6 -1
  263. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest.cc +2 -1
  264. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest_ffi_call.cc +1 -0
  265. data/ext/ffi_c/libffi.bsd.mk +2 -2
  266. data/ext/ffi_c/libffi.gnu.mk +2 -2
  267. data/ext/ffi_c/rbffi.h +1 -1
  268. data/ffi.gemspec +3 -3
  269. data/lib/ffi/autopointer.rb +7 -22
  270. data/lib/ffi/compat.rb +43 -0
  271. data/lib/ffi/data_converter.rb +2 -2
  272. data/lib/ffi/dynamic_library.rb +89 -0
  273. data/lib/ffi/enum.rb +18 -11
  274. data/lib/ffi/ffi.rb +3 -0
  275. data/lib/ffi/function.rb +71 -0
  276. data/lib/ffi/library.rb +55 -71
  277. data/lib/ffi/library_path.rb +109 -0
  278. data/lib/ffi/managedstruct.rb +1 -1
  279. data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
  280. data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
  281. data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
  282. data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
  283. data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
  284. data/lib/ffi/platform.rb +15 -13
  285. data/lib/ffi/struct.rb +2 -1
  286. data/lib/ffi/struct_layout.rb +1 -1
  287. data/lib/ffi/struct_layout_builder.rb +1 -1
  288. data/lib/ffi/tools/const_generator.rb +5 -4
  289. data/lib/ffi/types.rb +32 -6
  290. data/lib/ffi/variadic.rb +19 -8
  291. data/lib/ffi/version.rb +1 -1
  292. data/rakelib/ffi_gem_helper.rb +1 -1
  293. data/samples/hello_ractor.rb +11 -0
  294. data/samples/qsort_ractor.rb +28 -0
  295. data.tar.gz.sig +0 -0
  296. metadata +103 -28
  297. metadata.gz.sig +0 -0
  298. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +0 -14
  299. data/ext/ffi_c/libffi/.travis/build.sh +0 -142
  300. data/ext/ffi_c/libffi/.travis.yml +0 -83
  301. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +0 -44
  302. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +0 -44
  303. /data/ext/ffi_c/libffi/{.travis → .ci}/ar-lib +0 -0
  304. /data/ext/ffi_c/libffi/{.travis → .ci}/bfin-sim.exp +0 -0
  305. /data/ext/ffi_c/libffi/{.travis → .ci}/compile +0 -0
  306. /data/ext/ffi_c/libffi/{.travis → .ci}/m32r-sim.exp +0 -0
  307. /data/ext/ffi_c/libffi/{.travis → .ci}/moxie-sim.exp +0 -0
  308. /data/ext/ffi_c/libffi/{.travis → .ci}/or1k-sim.exp +0 -0
  309. /data/ext/ffi_c/libffi/{.travis → .ci}/powerpc-eabisim.exp +0 -0
  310. /data/ext/ffi_c/libffi/{.travis → .ci}/wine-sim.exp +0 -0
  311. /data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
  312. /data/lib/ffi/platform/{sparc64-linux → sparcv9-linux}/types.conf +0 -0
data/ext/ffi_c/Struct.c CHANGED
@@ -61,13 +61,29 @@ typedef struct InlineArray_ {
61
61
  } InlineArray;
62
62
 
63
63
 
64
- static void struct_mark(Struct *);
65
- static void struct_free(Struct *);
64
+ static void struct_mark(void *data);
65
+ static void struct_compact(void *data);
66
+ static void struct_free(void *data);
67
+ static size_t struct_memsize(const void *);
66
68
  static VALUE struct_class_layout(VALUE klass);
67
- static void struct_malloc(Struct* s);
68
- static void inline_array_mark(InlineArray *);
69
- static void store_reference_value(StructField* f, Struct* s, VALUE value);
70
-
69
+ static void struct_malloc(VALUE self, Struct* s);
70
+ static void inline_array_mark(void *);
71
+ static void inline_array_compact(void *);
72
+ static size_t inline_array_memsize(const void *);
73
+ static void store_reference_value(VALUE self, StructField* f, Struct* s, VALUE value);
74
+
75
+ const rb_data_type_t rbffi_struct_data_type = { /* extern */
76
+ .wrap_struct_name = "FFI::Struct",
77
+ .function = {
78
+ .dmark = struct_mark,
79
+ .dfree = struct_free,
80
+ .dsize = struct_memsize,
81
+ ffi_compact_callback( struct_compact )
82
+ },
83
+ // IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
84
+ // macro to update VALUE references, as to trigger write barriers.
85
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
86
+ };
71
87
  VALUE rbffi_StructClass = Qnil;
72
88
 
73
89
  VALUE rbffi_StructInlineArrayClass = Qnil;
@@ -79,17 +95,19 @@ static ID id_get = 0, id_put = 0, id_to_ptr = 0, id_to_s = 0, id_layout = 0;
79
95
  static inline char*
80
96
  memory_address(VALUE self)
81
97
  {
82
- return ((AbstractMemory *)DATA_PTR((self)))->address;
98
+ AbstractMemory *mem;
99
+ TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, mem);
100
+ return mem->address;
83
101
  }
84
102
 
85
103
  static VALUE
86
104
  struct_allocate(VALUE klass)
87
105
  {
88
106
  Struct* s;
89
- VALUE obj = Data_Make_Struct(klass, Struct, struct_mark, struct_free, s);
107
+ VALUE obj = TypedData_Make_Struct(klass, Struct, &rbffi_struct_data_type, s);
90
108
 
91
- s->rbPointer = Qnil;
92
- s->rbLayout = Qnil;
109
+ RB_OBJ_WRITE(obj, &s->rbPointer, Qnil);
110
+ RB_OBJ_WRITE(obj, &s->rbLayout, Qnil);
93
111
 
94
112
  return obj;
95
113
  }
@@ -108,28 +126,29 @@ struct_initialize(int argc, VALUE* argv, VALUE self)
108
126
  VALUE rbPointer = Qnil, rest = Qnil, klass = CLASS_OF(self);
109
127
  int nargs;
110
128
 
111
- Data_Get_Struct(self, Struct, s);
129
+ TypedData_Get_Struct(self, Struct, &rbffi_struct_data_type, s);
112
130
 
113
131
  nargs = rb_scan_args(argc, argv, "01*", &rbPointer, &rest);
114
132
 
115
133
  /* Call up into ruby code to adjust the layout */
116
134
  if (nargs > 1) {
117
- s->rbLayout = rb_funcall2(CLASS_OF(self), id_layout, (int) RARRAY_LEN(rest), RARRAY_PTR(rest));
135
+ VALUE rbLayout = rb_apply(CLASS_OF(self), id_layout, rest);
136
+ RB_OBJ_WRITE(self, &s->rbLayout, rbLayout);
118
137
  } else {
119
- s->rbLayout = struct_class_layout(klass);
138
+ RB_OBJ_WRITE(self, &s->rbLayout, struct_class_layout(klass));
120
139
  }
121
140
 
122
141
  if (!rb_obj_is_kind_of(s->rbLayout, rbffi_StructLayoutClass)) {
123
142
  rb_raise(rb_eRuntimeError, "Invalid Struct layout");
124
143
  }
125
144
 
126
- Data_Get_Struct(s->rbLayout, StructLayout, s->layout);
145
+ TypedData_Get_Struct(s->rbLayout, StructLayout, &rbffi_struct_layout_data_type, s->layout);
127
146
 
128
147
  if (rbPointer != Qnil) {
129
148
  s->pointer = MEMORY(rbPointer);
130
- s->rbPointer = rbPointer;
149
+ RB_OBJ_WRITE(self, &s->rbPointer, rbPointer);
131
150
  } else {
132
- struct_malloc(s);
151
+ struct_malloc(self, s);
133
152
  }
134
153
 
135
154
  return self;
@@ -146,13 +165,13 @@ struct_initialize_copy(VALUE self, VALUE other)
146
165
  Struct* src;
147
166
  Struct* dst;
148
167
 
149
- Data_Get_Struct(self, Struct, dst);
150
- Data_Get_Struct(other, Struct, src);
168
+ TypedData_Get_Struct(self, Struct, &rbffi_struct_data_type, dst);
169
+ TypedData_Get_Struct(other, Struct, &rbffi_struct_data_type, src);
151
170
  if (dst == src) {
152
171
  return self;
153
172
  }
154
173
 
155
- dst->rbLayout = src->rbLayout;
174
+ RB_OBJ_WRITE(self, &dst->rbLayout, src->rbLayout);
156
175
  dst->layout = src->layout;
157
176
 
158
177
  /*
@@ -161,17 +180,22 @@ struct_initialize_copy(VALUE self, VALUE other)
161
180
  * be longer than just this struct.
162
181
  */
163
182
  if (src->pointer->address != NULL) {
164
- dst->rbPointer = rbffi_MemoryPointer_NewInstance(1, src->layout->size, false);
183
+ RB_OBJ_WRITE(self, &dst->rbPointer, rbffi_MemoryPointer_NewInstance(1, src->layout->size, false));
165
184
  dst->pointer = MEMORY(dst->rbPointer);
166
185
  memcpy(dst->pointer->address, src->pointer->address, src->layout->size);
167
186
  } else {
168
- dst->rbPointer = src->rbPointer;
187
+ RB_OBJ_WRITE(self, &dst->rbPointer, src->rbPointer);
169
188
  dst->pointer = src->pointer;
170
189
  }
171
190
 
172
191
  if (src->layout->referenceFieldCount > 0) {
192
+ size_t index;
193
+
173
194
  dst->rbReferences = ALLOC_N(VALUE, dst->layout->referenceFieldCount);
174
195
  memcpy(dst->rbReferences, src->rbReferences, dst->layout->referenceFieldCount * sizeof(VALUE));
196
+ for ( index = 0; index < dst->layout->referenceFieldCount; index++) {
197
+ RB_OBJ_WRITTEN(self, Qundef, &dst->rbReferences[index]);
198
+ }
175
199
  }
176
200
 
177
201
  return self;
@@ -196,14 +220,15 @@ struct_class_layout(VALUE klass)
196
220
  static StructLayout*
197
221
  struct_layout(VALUE self)
198
222
  {
199
- Struct* s = (Struct *) DATA_PTR(self);
223
+ Struct* s;
224
+ TypedData_Get_Struct(self, Struct, &rbffi_struct_data_type, s);
200
225
  if (s->layout != NULL) {
201
226
  return s->layout;
202
227
  }
203
228
 
204
229
  if (s->layout == NULL) {
205
- s->rbLayout = struct_class_layout(CLASS_OF(self));
206
- Data_Get_Struct(s->rbLayout, StructLayout, s->layout);
230
+ RB_OBJ_WRITE(self, &s->rbLayout, struct_class_layout(CLASS_OF(self)));
231
+ TypedData_Get_Struct(s->rbLayout, StructLayout, &rbffi_struct_layout_data_type, s->layout);
207
232
  }
208
233
 
209
234
  return s->layout;
@@ -213,52 +238,76 @@ static Struct*
213
238
  struct_validate(VALUE self)
214
239
  {
215
240
  Struct* s;
216
- Data_Get_Struct(self, Struct, s);
241
+ TypedData_Get_Struct(self, Struct, &rbffi_struct_data_type, s);
217
242
 
218
243
  if (struct_layout(self) == NULL) {
219
244
  rb_raise(rb_eRuntimeError, "struct layout == null");
220
245
  }
221
246
 
222
247
  if (s->pointer == NULL) {
223
- struct_malloc(s);
248
+ struct_malloc(self, s);
224
249
  }
225
250
 
226
251
  return s;
227
252
  }
228
253
 
229
254
  static void
230
- struct_malloc(Struct* s)
255
+ struct_malloc(VALUE self, Struct* s)
231
256
  {
232
257
  if (s->rbPointer == Qnil) {
233
- s->rbPointer = rbffi_MemoryPointer_NewInstance(s->layout->size, 1, true);
234
-
258
+ RB_OBJ_WRITE(self, &s->rbPointer, rbffi_MemoryPointer_NewInstance(s->layout->size, 1, true));
235
259
  } else if (!rb_obj_is_kind_of(s->rbPointer, rbffi_AbstractMemoryClass)) {
236
260
  rb_raise(rb_eRuntimeError, "invalid pointer in struct");
237
261
  }
238
262
 
239
- s->pointer = (AbstractMemory *) DATA_PTR(s->rbPointer);
263
+ TypedData_Get_Struct(s->rbPointer, AbstractMemory, &rbffi_abstract_memory_data_type, s->pointer);
240
264
  }
241
265
 
242
266
  static void
243
- struct_mark(Struct *s)
267
+ struct_mark(void *data)
244
268
  {
245
- rb_gc_mark(s->rbPointer);
246
- rb_gc_mark(s->rbLayout);
269
+ Struct *s = (Struct *)data;
270
+ rb_gc_mark_movable(s->rbPointer);
271
+ rb_gc_mark_movable(s->rbLayout);
247
272
  if (s->rbReferences != NULL) {
248
- rb_gc_mark_locations(&s->rbReferences[0], &s->rbReferences[s->layout->referenceFieldCount]);
273
+ size_t index;
274
+ for (index = 0; index < s->layout->referenceFieldCount; index++) {
275
+ rb_gc_mark_movable(s->rbReferences[index]);
276
+ }
277
+ }
278
+ }
279
+
280
+ static void
281
+ struct_compact(void *data)
282
+ {
283
+ Struct *s = (Struct *)data;
284
+ ffi_gc_location(s->rbPointer);
285
+ ffi_gc_location(s->rbLayout);
286
+ if (s->rbReferences != NULL) {
287
+ size_t index;
288
+ for (index = 0; index < s->layout->referenceFieldCount; index++) {
289
+ ffi_gc_location(s->rbReferences[index]);
290
+ }
249
291
  }
250
292
  }
251
293
 
252
294
  static void
253
- struct_free(Struct* s)
295
+ struct_free(void *data)
254
296
  {
297
+ Struct *s = (Struct *)data;
255
298
  xfree(s->rbReferences);
256
299
  xfree(s);
257
300
  }
258
301
 
302
+ static size_t
303
+ struct_memsize(const void *data)
304
+ {
305
+ const Struct *s = (const Struct *)data;
306
+ return sizeof(Struct) + (s->layout->referenceFieldCount * sizeof(VALUE));
307
+ }
259
308
 
260
309
  static void
261
- store_reference_value(StructField* f, Struct* s, VALUE value)
310
+ store_reference_value(VALUE self, StructField* f, Struct* s, VALUE value)
262
311
  {
263
312
  if (unlikely(f->referenceIndex == -1)) {
264
313
  rb_raise(rb_eRuntimeError, "put_reference_value called for non-reference type");
@@ -268,11 +317,11 @@ store_reference_value(StructField* f, Struct* s, VALUE value)
268
317
  int i;
269
318
  s->rbReferences = ALLOC_N(VALUE, s->layout->referenceFieldCount);
270
319
  for (i = 0; i < s->layout->referenceFieldCount; ++i) {
271
- s->rbReferences[i] = Qnil;
320
+ RB_OBJ_WRITE(self, &s->rbReferences[i], Qnil);
272
321
  }
273
322
  }
274
323
 
275
- s->rbReferences[f->referenceIndex] = value;
324
+ RB_OBJ_WRITE(self, &s->rbReferences[f->referenceIndex], value);
276
325
  }
277
326
 
278
327
 
@@ -290,8 +339,8 @@ struct_field(Struct* s, VALUE fieldName)
290
339
  rb_raise(rb_eArgError, "No such field '%s'", StringValueCStr(str));
291
340
  }
292
341
  /* Write the retrieved coder to the cache */
293
- p_ce->fieldName = fieldName;
294
- p_ce->field = (StructField *) DATA_PTR(rbField);
342
+ RB_OBJ_WRITE(s->rbLayout, &p_ce->fieldName, fieldName);
343
+ TypedData_Get_Struct(rbField, StructField, &rbffi_struct_field_data_type, p_ce->field);
295
344
  }
296
345
 
297
346
  return p_ce->field;
@@ -311,10 +360,7 @@ struct_aref(VALUE self, VALUE fieldName)
311
360
  s = struct_validate(self);
312
361
 
313
362
  f = struct_field(s, fieldName);
314
- if (f->get != NULL) {
315
- return (*f->get)(f, s);
316
-
317
- } else if (f->memoryOp != NULL) {
363
+ if (f->memoryOp != NULL) {
318
364
  return (*f->memoryOp->get)(s->pointer, f->offset);
319
365
 
320
366
  } else {
@@ -337,13 +383,11 @@ struct_aset(VALUE self, VALUE fieldName, VALUE value)
337
383
  Struct* s;
338
384
  StructField* f;
339
385
 
386
+ rb_check_frozen(self);
340
387
  s = struct_validate(self);
341
388
 
342
389
  f = struct_field(s, fieldName);
343
- if (f->put != NULL) {
344
- (*f->put)(f, s, value);
345
-
346
- } else if (f->memoryOp != NULL) {
390
+ if (f->memoryOp != NULL) {
347
391
 
348
392
  (*f->memoryOp->put)(s->pointer, f->offset, value);
349
393
 
@@ -357,7 +401,7 @@ struct_aset(VALUE self, VALUE fieldName, VALUE value)
357
401
  }
358
402
 
359
403
  if (f->referenceRequired) {
360
- store_reference_value(f, s, value);
404
+ store_reference_value(self, f, s, value);
361
405
  }
362
406
 
363
407
  return value;
@@ -376,6 +420,7 @@ struct_set_pointer(VALUE self, VALUE pointer)
376
420
  StructLayout* layout;
377
421
  AbstractMemory* memory;
378
422
 
423
+ rb_check_frozen(self);
379
424
  if (!rb_obj_is_kind_of(pointer, rbffi_AbstractMemoryClass)) {
380
425
  rb_raise(rb_eTypeError, "wrong argument type %s (expected Pointer or Buffer)",
381
426
  rb_obj_classname(pointer));
@@ -383,8 +428,8 @@ struct_set_pointer(VALUE self, VALUE pointer)
383
428
  }
384
429
 
385
430
 
386
- Data_Get_Struct(self, Struct, s);
387
- Data_Get_Struct(pointer, AbstractMemory, memory);
431
+ TypedData_Get_Struct(self, Struct, &rbffi_struct_data_type, s);
432
+ TypedData_Get_Struct(pointer, AbstractMemory, &rbffi_abstract_memory_data_type, memory);
388
433
  layout = struct_layout(self);
389
434
 
390
435
  if ((int) layout->base.ffiType->size > memory->size) {
@@ -393,7 +438,7 @@ struct_set_pointer(VALUE self, VALUE pointer)
393
438
  }
394
439
 
395
440
  s->pointer = MEMORY(pointer);
396
- s->rbPointer = pointer;
441
+ RB_OBJ_WRITE(self, &s->rbPointer, pointer);
397
442
  rb_ivar_set(self, id_pointer_ivar, pointer);
398
443
 
399
444
  return self;
@@ -409,7 +454,7 @@ struct_get_pointer(VALUE self)
409
454
  {
410
455
  Struct* s;
411
456
 
412
- Data_Get_Struct(self, Struct, s);
457
+ TypedData_Get_Struct(self, Struct, &rbffi_struct_data_type, s);
413
458
 
414
459
  return s->rbPointer;
415
460
  }
@@ -424,15 +469,16 @@ static VALUE
424
469
  struct_set_layout(VALUE self, VALUE layout)
425
470
  {
426
471
  Struct* s;
427
- Data_Get_Struct(self, Struct, s);
472
+ TypedData_Get_Struct(self, Struct, &rbffi_struct_data_type, s);
428
473
 
474
+ rb_check_frozen(self);
429
475
  if (!rb_obj_is_kind_of(layout, rbffi_StructLayoutClass)) {
430
476
  rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
431
477
  rb_obj_classname(layout), rb_class2name(rbffi_StructLayoutClass));
432
478
  return Qnil;
433
479
  }
434
480
 
435
- Data_Get_Struct(layout, StructLayout, s->layout);
481
+ TypedData_Get_Struct(layout, StructLayout, &rbffi_struct_layout_data_type, s->layout);
436
482
  rb_ivar_set(self, id_layout_ivar, layout);
437
483
 
438
484
  return self;
@@ -448,7 +494,7 @@ struct_get_layout(VALUE self)
448
494
  {
449
495
  Struct* s;
450
496
 
451
- Data_Get_Struct(self, Struct, s);
497
+ TypedData_Get_Struct(self, Struct, &rbffi_struct_data_type, s);
452
498
 
453
499
  return s->rbLayout;
454
500
  }
@@ -463,7 +509,7 @@ struct_null_p(VALUE self)
463
509
  {
464
510
  Struct* s;
465
511
 
466
- Data_Get_Struct(self, Struct, s);
512
+ TypedData_Get_Struct(self, Struct, &rbffi_struct_data_type, s);
467
513
 
468
514
  return s->pointer->address == NULL ? Qtrue : Qfalse;
469
515
  }
@@ -476,7 +522,7 @@ struct_order(int argc, VALUE* argv, VALUE self)
476
522
  {
477
523
  Struct* s;
478
524
 
479
- Data_Get_Struct(self, Struct, s);
525
+ TypedData_Get_Struct(self, Struct, &rbffi_struct_data_type, s);
480
526
  if (argc == 0) {
481
527
  return rb_funcall(s->rbPointer, rb_intern("order"), 0);
482
528
 
@@ -489,24 +535,52 @@ struct_order(int argc, VALUE* argv, VALUE self)
489
535
  }
490
536
  }
491
537
 
538
+ static const rb_data_type_t inline_array_data_type = {
539
+ .wrap_struct_name = "FFI::Struct::InlineArray",
540
+ .function = {
541
+ .dmark = inline_array_mark,
542
+ .dfree = RUBY_TYPED_DEFAULT_FREE,
543
+ .dsize = inline_array_memsize,
544
+ ffi_compact_callback( inline_array_compact )
545
+ },
546
+ // IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
547
+ // macro to update VALUE references, as to trigger write barriers.
548
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
549
+ };
550
+
492
551
  static VALUE
493
552
  inline_array_allocate(VALUE klass)
494
553
  {
495
554
  InlineArray* array;
496
555
  VALUE obj;
497
556
 
498
- obj = Data_Make_Struct(klass, InlineArray, inline_array_mark, -1, array);
499
- array->rbField = Qnil;
500
- array->rbMemory = Qnil;
557
+ obj = TypedData_Make_Struct(klass, InlineArray, &inline_array_data_type, array);
558
+ RB_OBJ_WRITE(obj, &array->rbMemory, Qnil);
559
+ RB_OBJ_WRITE(obj, &array->rbField, Qnil);
501
560
 
502
561
  return obj;
503
562
  }
504
563
 
505
564
  static void
506
- inline_array_mark(InlineArray* array)
565
+ inline_array_mark(void *data)
566
+ {
567
+ InlineArray *array = (InlineArray *)data;
568
+ rb_gc_mark_movable(array->rbField);
569
+ rb_gc_mark_movable(array->rbMemory);
570
+ }
571
+
572
+ static void
573
+ inline_array_compact(void *data)
574
+ {
575
+ InlineArray *array = (InlineArray *)data;
576
+ ffi_gc_location(array->rbField);
577
+ ffi_gc_location(array->rbMemory);
578
+ }
579
+
580
+ static size_t
581
+ inline_array_memsize(const void *data)
507
582
  {
508
- rb_gc_mark(array->rbField);
509
- rb_gc_mark(array->rbMemory);
583
+ return sizeof(InlineArray);
510
584
  }
511
585
 
512
586
  /*
@@ -521,14 +595,14 @@ inline_array_initialize(VALUE self, VALUE rbMemory, VALUE rbField)
521
595
  {
522
596
  InlineArray* array;
523
597
 
524
- Data_Get_Struct(self, InlineArray, array);
525
- array->rbMemory = rbMemory;
526
- array->rbField = rbField;
598
+ TypedData_Get_Struct(self, InlineArray, &inline_array_data_type, array);
599
+ RB_OBJ_WRITE(self, &array->rbMemory, rbMemory);
600
+ RB_OBJ_WRITE(self, &array->rbField, rbField);
527
601
 
528
- Data_Get_Struct(rbMemory, AbstractMemory, array->memory);
529
- Data_Get_Struct(rbField, StructField, array->field);
530
- Data_Get_Struct(array->field->rbType, ArrayType, array->arrayType);
531
- Data_Get_Struct(array->arrayType->rbComponentType, Type, array->componentType);
602
+ TypedData_Get_Struct(rbMemory, AbstractMemory, &rbffi_abstract_memory_data_type, array->memory);
603
+ TypedData_Get_Struct(rbField, StructField, &rbffi_struct_field_data_type, array->field);
604
+ TypedData_Get_Struct(array->field->rbType, ArrayType, &rbffi_array_type_data_type, array->arrayType);
605
+ TypedData_Get_Struct(array->arrayType->rbComponentType, Type, &rbffi_type_data_type, array->componentType);
532
606
 
533
607
  array->op = get_memory_op(array->componentType);
534
608
  if (array->op == NULL && array->componentType->nativeType == NATIVE_MAPPED) {
@@ -550,7 +624,7 @@ inline_array_size(VALUE self)
550
624
  {
551
625
  InlineArray* array;
552
626
 
553
- Data_Get_Struct(self, InlineArray, array);
627
+ TypedData_Get_Struct(self, InlineArray, &inline_array_data_type, array);
554
628
 
555
629
  return UINT2NUM(((ArrayType *) array->field->type)->length);
556
630
  }
@@ -575,7 +649,7 @@ inline_array_aref(VALUE self, VALUE rbIndex)
575
649
  {
576
650
  InlineArray* array;
577
651
 
578
- Data_Get_Struct(self, InlineArray, array);
652
+ TypedData_Get_Struct(self, InlineArray, &inline_array_data_type, array);
579
653
 
580
654
  if (array->op != NULL) {
581
655
  VALUE rbNativeValue = array->op->get(array->memory,
@@ -611,7 +685,8 @@ inline_array_aset(VALUE self, VALUE rbIndex, VALUE rbValue)
611
685
  {
612
686
  InlineArray* array;
613
687
 
614
- Data_Get_Struct(self, InlineArray, array);
688
+ rb_check_frozen(self);
689
+ TypedData_Get_Struct(self, InlineArray, &inline_array_data_type, array);
615
690
 
616
691
  if (array->op != NULL) {
617
692
  if (unlikely(array->componentType->nativeType == NATIVE_MAPPED)) {
@@ -633,7 +708,7 @@ inline_array_aset(VALUE self, VALUE rbIndex, VALUE rbValue)
633
708
  checkWrite(array->memory);
634
709
  checkBounds(array->memory, offset, array->componentType->ffiType->size);
635
710
 
636
- Data_Get_Struct(rbValue, Struct, s);
711
+ TypedData_Get_Struct(rbValue, Struct, &rbffi_struct_data_type, s);
637
712
  checkRead(s->pointer);
638
713
  checkBounds(s->pointer, 0, array->componentType->ffiType->size);
639
714
 
@@ -641,7 +716,7 @@ inline_array_aset(VALUE self, VALUE rbIndex, VALUE rbValue)
641
716
 
642
717
  } else {
643
718
  ArrayType* arrayType;
644
- Data_Get_Struct(array->field->rbType, ArrayType, arrayType);
719
+ TypedData_Get_Struct(array->field->rbType, ArrayType, &rbffi_array_type_data_type, arrayType);
645
720
 
646
721
  rb_raise(rb_eArgError, "set not supported for %s", rb_obj_classname(arrayType->rbComponentType));
647
722
  return Qnil;
@@ -661,7 +736,7 @@ inline_array_each(VALUE self)
661
736
 
662
737
  int i;
663
738
 
664
- Data_Get_Struct(self, InlineArray, array);
739
+ TypedData_Get_Struct(self, InlineArray, &inline_array_data_type, array);
665
740
 
666
741
  for (i = 0; i < array->length; ++i) {
667
742
  rb_yield(inline_array_aref(self, INT2FIX(i)));
@@ -682,7 +757,7 @@ inline_array_to_a(VALUE self)
682
757
  VALUE obj;
683
758
  int i;
684
759
 
685
- Data_Get_Struct(self, InlineArray, array);
760
+ TypedData_Get_Struct(self, InlineArray, &inline_array_data_type, array);
686
761
  obj = rb_ary_new2(array->length);
687
762
 
688
763
 
@@ -705,7 +780,7 @@ inline_array_to_s(VALUE self)
705
780
  InlineArray* array;
706
781
  VALUE argv[2];
707
782
 
708
- Data_Get_Struct(self, InlineArray, array);
783
+ TypedData_Get_Struct(self, InlineArray, &inline_array_data_type, array);
709
784
 
710
785
  if (array->componentType->nativeType != NATIVE_INT8 && array->componentType->nativeType != NATIVE_UINT8) {
711
786
  VALUE dummy = Qnil;
@@ -728,7 +803,7 @@ inline_array_to_ptr(VALUE self)
728
803
  {
729
804
  InlineArray* array;
730
805
 
731
- Data_Get_Struct(self, InlineArray, array);
806
+ TypedData_Get_Struct(self, InlineArray, &inline_array_data_type, array);
732
807
 
733
808
  return rb_funcall(array->rbMemory, rb_intern("slice"), 2,
734
809
  UINT2NUM(array->field->offset), UINT2NUM(array->arrayType->base.ffiType->size));
data/ext/ffi_c/Struct.h CHANGED
@@ -42,6 +42,9 @@ extern "C" {
42
42
 
43
43
  extern void rbffi_Struct_Init(VALUE ffiModule);
44
44
  extern void rbffi_StructLayout_Init(VALUE ffiModule);
45
+ extern const rb_data_type_t rbffi_struct_layout_data_type;
46
+ extern const rb_data_type_t rbffi_struct_field_data_type;
47
+
45
48
  typedef struct StructField_ StructField;
46
49
  typedef struct StructLayout_ StructLayout;
47
50
  typedef struct Struct_ Struct;
@@ -56,9 +59,6 @@ extern "C" {
56
59
  VALUE rbType;
57
60
  VALUE rbName;
58
61
 
59
- VALUE (*get)(StructField* field, Struct* s);
60
- void (*put)(StructField* field, Struct* s, VALUE value);
61
-
62
62
  MemoryOp* memoryOp;
63
63
  };
64
64
 
@@ -75,11 +75,12 @@ extern "C" {
75
75
  * This avoids full ruby hash lookups for repeated lookups.
76
76
  */
77
77
  #define FIELD_CACHE_LOOKUP(this, sym) ( &(this)->cache_row[((sym) >> 8) & 0xff] )
78
+ #define FIELD_CACHE_ROWS 0x100
78
79
 
79
80
  struct field_cache_entry {
80
81
  VALUE fieldName;
81
82
  StructField *field;
82
- } cache_row[0x100];
83
+ } cache_row[FIELD_CACHE_ROWS];
83
84
 
84
85
  /** The number of reference tracking fields in this struct */
85
86
  int referenceFieldCount;
@@ -98,6 +99,8 @@ extern "C" {
98
99
  VALUE rbPointer;
99
100
  };
100
101
 
102
+ extern const rb_data_type_t rbffi_struct_data_type;
103
+ extern const rb_data_type_t rbffi_struct_field_data_type;
101
104
  extern VALUE rbffi_StructClass, rbffi_StructLayoutClass;
102
105
  extern VALUE rbffi_StructLayoutFieldClass, rbffi_StructLayoutFunctionFieldClass;
103
106
  extern VALUE rbffi_StructLayoutArrayFieldClass;