ffi 1.10.0 → 1.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (299) hide show
  1. checksums.yaml +4 -4
  2. data/{appveyor.yml → .appveyor.yml} +9 -1
  3. data/.github/workflows/ci.yml +64 -0
  4. data/.gitignore +3 -0
  5. data/.gitmodules +1 -0
  6. data/.travis.yml +35 -20
  7. data/CHANGELOG.md +124 -0
  8. data/Gemfile +6 -4
  9. data/README.md +29 -17
  10. data/Rakefile +29 -120
  11. data/ext/ffi_c/AbstractMemory.c +5 -9
  12. data/ext/ffi_c/Buffer.c +2 -2
  13. data/ext/ffi_c/Call.c +14 -41
  14. data/ext/ffi_c/Call.h +4 -7
  15. data/ext/ffi_c/ClosurePool.c +11 -14
  16. data/ext/ffi_c/DynamicLibrary.c +1 -1
  17. data/ext/ffi_c/Function.c +18 -117
  18. data/ext/ffi_c/FunctionInfo.c +1 -2
  19. data/ext/ffi_c/LongDouble.c +12 -10
  20. data/ext/ffi_c/LongDouble.h +0 -4
  21. data/ext/ffi_c/MemoryPointer.c +1 -1
  22. data/ext/ffi_c/MethodHandle.c +18 -24
  23. data/ext/ffi_c/MethodHandle.h +3 -2
  24. data/ext/ffi_c/Platform.c +1 -47
  25. data/ext/ffi_c/Pointer.c +1 -1
  26. data/ext/ffi_c/Struct.c +47 -51
  27. data/ext/ffi_c/Struct.h +12 -6
  28. data/ext/ffi_c/StructLayout.c +20 -14
  29. data/ext/ffi_c/Thread.c +4 -223
  30. data/ext/ffi_c/Thread.h +0 -14
  31. data/ext/ffi_c/Type.c +0 -18
  32. data/ext/ffi_c/Type.h +0 -1
  33. data/ext/ffi_c/Types.c +1 -1
  34. data/ext/ffi_c/Variadic.c +9 -15
  35. data/ext/ffi_c/compat.h +4 -0
  36. data/ext/ffi_c/extconf.rb +36 -26
  37. data/ext/ffi_c/ffi.c +3 -8
  38. data/ext/ffi_c/libffi.darwin.mk +1 -1
  39. data/ext/ffi_c/libffi/.appveyor.yml +29 -13
  40. data/ext/ffi_c/libffi/.gitattributes +4 -0
  41. data/ext/ffi_c/libffi/.travis.yml +51 -2
  42. data/ext/ffi_c/libffi/.travis/bfin-sim.exp +58 -0
  43. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +14 -0
  44. data/ext/ffi_c/libffi/.travis/build-in-container.sh +12 -0
  45. data/ext/ffi_c/libffi/.travis/build.sh +116 -8
  46. data/ext/ffi_c/libffi/.travis/install.sh +65 -16
  47. data/ext/ffi_c/libffi/.travis/m32r-sim.exp +58 -0
  48. data/ext/ffi_c/libffi/.travis/or1k-sim.exp +58 -0
  49. data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +58 -0
  50. data/ext/ffi_c/libffi/.travis/site.exp +10 -1
  51. data/ext/ffi_c/libffi/.travis/wine-sim.exp +55 -0
  52. data/ext/ffi_c/libffi/{ChangeLog.libffi-3.1 → ChangeLog.old} +1407 -0
  53. data/ext/ffi_c/libffi/LICENSE +1 -1
  54. data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +5 -4
  55. data/ext/ffi_c/libffi/Makefile.am +35 -41
  56. data/ext/ffi_c/libffi/README.md +29 -8
  57. data/ext/ffi_c/libffi/configure.ac +31 -11
  58. data/ext/ffi_c/libffi/configure.host +26 -9
  59. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +1 -3
  60. data/ext/ffi_c/libffi/include/ffi.h.in +19 -7
  61. data/ext/ffi_c/libffi/include/ffi_common.h +5 -1
  62. data/ext/ffi_c/libffi/libffi.map.in +8 -12
  63. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +2 -48
  64. data/ext/ffi_c/libffi/libtool-version +1 -1
  65. data/ext/ffi_c/libffi/m4/asmcfi.m4 +1 -1
  66. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +5 -26
  67. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +5 -26
  68. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +2 -1
  69. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +5 -26
  70. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +7 -3
  71. data/ext/ffi_c/libffi/make_sunver.pl +333 -0
  72. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.sln +33 -0
  73. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj +130 -0
  74. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.filters +57 -0
  75. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user +4 -0
  76. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +511 -0
  77. data/ext/ffi_c/libffi/msvcc.sh +27 -2
  78. data/ext/ffi_c/libffi/src/aarch64/ffi.c +132 -58
  79. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +13 -2
  80. data/ext/ffi_c/libffi/src/aarch64/sysv.S +21 -8
  81. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
  82. data/ext/ffi_c/libffi/src/arm/ffi.c +40 -5
  83. data/ext/ffi_c/libffi/src/arm/ffitarget.h +8 -1
  84. data/ext/ffi_c/libffi/src/arm/sysv.S +2 -0
  85. data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
  86. data/ext/ffi_c/libffi/src/closures.c +51 -13
  87. data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
  88. data/ext/ffi_c/libffi/src/metag/ffi.c +1 -1
  89. data/ext/ffi_c/libffi/src/mips/o32.S +2 -0
  90. data/ext/ffi_c/libffi/src/moxie/ffi.c +1 -1
  91. data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
  92. data/ext/ffi_c/libffi/src/pa/ffitarget.h +1 -6
  93. data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
  94. data/ext/ffi_c/libffi/src/pa/linux.S +27 -4
  95. data/ext/ffi_c/libffi/src/powerpc/ffi.c +6 -4
  96. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +211 -32
  97. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +18 -7
  98. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +10 -4
  99. data/ext/ffi_c/libffi/src/powerpc/linux64.S +83 -28
  100. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +68 -4
  101. data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
  102. data/ext/ffi_c/libffi/src/prep_cif.c +4 -2
  103. data/ext/ffi_c/libffi/src/riscv/ffi.c +42 -6
  104. data/ext/ffi_c/libffi/src/riscv/ffitarget.h +1 -0
  105. data/ext/ffi_c/libffi/src/riscv/sysv.S +86 -7
  106. data/ext/ffi_c/libffi/src/x86/ffi.c +21 -10
  107. data/ext/ffi_c/libffi/src/x86/ffi64.c +15 -11
  108. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
  109. data/ext/ffi_c/libffi/src/x86/ffiw64.c +15 -10
  110. data/ext/ffi_c/libffi/src/x86/sysv.S +103 -8
  111. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +995 -0
  112. data/ext/ffi_c/libffi/src/x86/unix64.S +99 -2
  113. data/ext/ffi_c/libffi/src/x86/win64.S +9 -1
  114. data/ext/ffi_c/libffi/testsuite/Makefile.am +114 -109
  115. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +26 -22
  116. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +7 -2
  117. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1 -1
  118. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +1 -1
  119. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +12 -1
  120. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +9 -8
  121. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -1
  122. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure.exp +67 -0
  123. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn0.c +0 -0
  124. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn1.c +0 -0
  125. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn2.c +0 -0
  126. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn3.c +0 -0
  127. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn4.c +0 -0
  128. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn5.c +0 -0
  129. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn6.c +0 -0
  130. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_loc_fn0.c +0 -0
  131. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_simple.c +0 -0
  132. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_12byte.c +0 -0
  133. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_16byte.c +0 -0
  134. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_18byte.c +0 -0
  135. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_19byte.c +0 -0
  136. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_1_1byte.c +0 -0
  137. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte.c +0 -0
  138. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte1.c +0 -0
  139. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_24byte.c +0 -0
  140. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_2byte.c +0 -0
  141. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3_1byte.c +0 -0
  142. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte1.c +0 -0
  143. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte2.c +0 -0
  144. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3float.c +0 -0
  145. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4_1byte.c +0 -0
  146. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4byte.c +0 -0
  147. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5_1_byte.c +0 -0
  148. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5byte.c +0 -0
  149. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_64byte.c +0 -0
  150. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6_1_byte.c +0 -0
  151. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6byte.c +0 -0
  152. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7_1_byte.c +0 -0
  153. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7byte.c +0 -0
  154. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_8byte.c +0 -0
  155. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte1.c +0 -0
  156. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte2.c +0 -0
  157. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_double.c +0 -0
  158. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_float.c +0 -0
  159. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble.c +0 -0
  160. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split.c +0 -0
  161. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split2.c +0 -0
  162. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_pointer.c +0 -0
  163. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint16.c +0 -0
  164. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint32.c +0 -0
  165. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint64.c +0 -0
  166. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint16.c +0 -0
  167. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint32.c +0 -0
  168. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint64.c +0 -0
  169. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_dbls_struct.c +0 -0
  170. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double.c +0 -0
  171. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double_va.c +0 -0
  172. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_float.c +0 -0
  173. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble.c +0 -0
  174. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble_va.c +0 -0
  175. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_args.c +0 -0
  176. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_float_double.c +0 -0
  177. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_schar.c +0 -0
  178. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshort.c +0 -0
  179. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshortchar.c +0 -0
  180. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_uchar.c +0 -0
  181. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushort.c +0 -0
  182. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushortchar.c +0 -0
  183. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer.c +0 -0
  184. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer_stack.c +0 -0
  185. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_schar.c +0 -0
  186. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sint.c +0 -0
  187. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sshort.c +0 -0
  188. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_struct_va1.c +0 -0
  189. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar.c +0 -0
  190. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar_va.c +0 -0
  191. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint.c +0 -0
  192. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint_va.c +0 -0
  193. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulong_va.c +0 -0
  194. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulonglong.c +0 -0
  195. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort.c +0 -0
  196. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort_va.c +0 -0
  197. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/err_bad_abi.c +0 -0
  198. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +138 -0
  199. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/huge_struct.c +1 -1
  200. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct.c +0 -0
  201. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct1.c +0 -0
  202. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct10.c +0 -0
  203. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct11.c +0 -0
  204. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct2.c +0 -0
  205. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct3.c +0 -0
  206. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct4.c +0 -0
  207. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct5.c +0 -0
  208. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct6.c +0 -0
  209. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct7.c +0 -0
  210. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct8.c +0 -0
  211. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct9.c +0 -0
  212. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/problem1.c +0 -0
  213. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large.c +0 -0
  214. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large2.c +0 -0
  215. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium.c +0 -0
  216. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium2.c +0 -0
  217. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/testclosure.c +0 -0
  218. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest.cc +0 -0
  219. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest_ffi_call.cc +0 -0
  220. data/ext/ffi_c/rbffi.h +0 -2
  221. data/ffi.gemspec +12 -5
  222. data/lib/ffi.rb +10 -2
  223. data/lib/ffi/data_converter.rb +67 -0
  224. data/lib/ffi/ffi.rb +2 -0
  225. data/lib/ffi/library.rb +10 -6
  226. data/lib/ffi/platform.rb +12 -3
  227. data/lib/ffi/platform/aarch64-freebsd/types.conf +89 -89
  228. data/lib/ffi/platform/aarch64-freebsd12/types.conf +89 -89
  229. data/lib/ffi/platform/aarch64-linux/types.conf +81 -81
  230. data/lib/ffi/platform/arm-freebsd/types.conf +87 -87
  231. data/lib/ffi/platform/arm-freebsd12/types.conf +87 -87
  232. data/lib/ffi/platform/arm-linux/types.conf +110 -82
  233. data/lib/ffi/platform/i386-cygwin/types.conf +1 -1
  234. data/lib/ffi/platform/i386-darwin/types.conf +63 -63
  235. data/lib/ffi/platform/i386-freebsd/types.conf +87 -87
  236. data/lib/ffi/platform/i386-freebsd12/types.conf +87 -87
  237. data/lib/ffi/platform/i386-gnu/types.conf +84 -84
  238. data/lib/ffi/platform/i386-linux/types.conf +77 -77
  239. data/lib/ffi/platform/i386-netbsd/types.conf +87 -87
  240. data/lib/ffi/platform/i386-openbsd/types.conf +89 -89
  241. data/lib/ffi/platform/i386-solaris/types.conf +96 -96
  242. data/lib/ffi/platform/i386-windows/types.conf +43 -96
  243. data/lib/ffi/platform/ia64-linux/types.conf +79 -79
  244. data/lib/ffi/platform/mips-linux/types.conf +79 -79
  245. data/lib/ffi/platform/mips64-linux/types.conf +81 -81
  246. data/lib/ffi/platform/mips64el-linux/types.conf +81 -81
  247. data/lib/ffi/platform/mipsel-linux/types.conf +79 -79
  248. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +79 -79
  249. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +79 -79
  250. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +81 -81
  251. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +81 -81
  252. data/lib/ffi/platform/powerpc-aix/types.conf +155 -155
  253. data/lib/ffi/platform/powerpc-darwin/types.conf +63 -63
  254. data/lib/ffi/platform/powerpc-linux/types.conf +108 -78
  255. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  256. data/lib/ffi/platform/powerpc64-linux/types.conf +81 -81
  257. data/lib/ffi/platform/s390-linux/types.conf +79 -79
  258. data/lib/ffi/platform/s390x-linux/types.conf +79 -79
  259. data/lib/ffi/platform/sparc-linux/types.conf +79 -79
  260. data/lib/ffi/platform/sparc-solaris/types.conf +103 -103
  261. data/lib/ffi/platform/sparc64-linux/types.conf +79 -79
  262. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  263. data/lib/ffi/platform/sparcv9-solaris/types.conf +103 -103
  264. data/lib/ffi/platform/x86_64-cygwin/types.conf +1 -1
  265. data/lib/ffi/platform/x86_64-darwin/types.conf +88 -84
  266. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
  267. data/lib/ffi/platform/x86_64-freebsd/types.conf +89 -89
  268. data/lib/ffi/platform/x86_64-freebsd12/types.conf +139 -109
  269. data/lib/ffi/platform/x86_64-linux/types.conf +107 -77
  270. data/lib/ffi/platform/x86_64-netbsd/types.conf +89 -89
  271. data/lib/ffi/platform/x86_64-openbsd/types.conf +86 -86
  272. data/lib/ffi/platform/x86_64-solaris/types.conf +96 -96
  273. data/lib/ffi/platform/x86_64-windows/types.conf +42 -110
  274. data/lib/ffi/pointer.rb +20 -13
  275. data/lib/ffi/struct.rb +13 -68
  276. data/lib/ffi/struct_by_reference.rb +72 -0
  277. data/lib/ffi/struct_layout.rb +96 -0
  278. data/lib/ffi/tools/const_generator.rb +5 -4
  279. data/lib/ffi/tools/generator.rb +47 -2
  280. data/lib/ffi/tools/generator_task.rb +13 -17
  281. data/lib/ffi/tools/struct_generator.rb +4 -4
  282. data/lib/ffi/tools/types_generator.rb +7 -4
  283. data/lib/ffi/types.rb +1 -1
  284. data/lib/ffi/version.rb +1 -1
  285. data/samples/getlogin.rb +1 -1
  286. data/samples/getpid.rb +1 -1
  287. data/samples/gettimeofday.rb +8 -8
  288. data/samples/hello.rb +2 -1
  289. data/samples/inotify.rb +1 -1
  290. data/samples/pty.rb +1 -2
  291. data/samples/qsort.rb +0 -1
  292. metadata +141 -116
  293. data/ext/ffi_c/DataConverter.c +0 -91
  294. data/ext/ffi_c/StructByReference.c +0 -190
  295. data/ext/ffi_c/StructByReference.h +0 -50
  296. data/ext/ffi_c/libffi/ChangeLog.libffi +0 -584
  297. data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
  298. data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
  299. data/samples/sample_helper.rb +0 -6
@@ -417,7 +417,7 @@ memory_get_string(int argc, VALUE* argv, VALUE self)
417
417
  checkBounds(ptr, off, len);
418
418
 
419
419
  end = memchr(ptr->address + off, 0, len);
420
- return rb_tainted_str_new((char *) ptr->address + off,
420
+ return rb_str_new((char *) ptr->address + off,
421
421
  (end != NULL ? end - ptr->address - off : len));
422
422
  }
423
423
 
@@ -453,7 +453,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
453
453
 
454
454
  for (i = 0; i < count; ++i) {
455
455
  const char* strptr = *((const char**) (ptr->address + off) + i);
456
- rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_tainted_str_new2(strptr)));
456
+ rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_str_new2(strptr)));
457
457
  }
458
458
 
459
459
  } else {
@@ -463,7 +463,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
463
463
  if (strptr == NULL) {
464
464
  break;
465
465
  }
466
- rb_ary_push(retVal, rb_tainted_str_new2(strptr));
466
+ rb_ary_push(retVal, rb_str_new2(strptr));
467
467
  }
468
468
  }
469
469
 
@@ -542,7 +542,7 @@ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
542
542
  checkRead(ptr);
543
543
  checkBounds(ptr, off, len);
544
544
 
545
- return rb_tainted_str_new((char *) ptr->address + off, len);
545
+ return rb_str_new((char *) ptr->address + off, len);
546
546
  }
547
547
 
548
548
  /*
@@ -583,10 +583,6 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
583
583
  checkWrite(ptr);
584
584
  checkBounds(ptr, off, len);
585
585
 
586
- if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
587
- rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
588
- return Qnil;
589
- }
590
586
  memcpy(ptr->address + off, RSTRING_PTR(str) + idx, len);
591
587
 
592
588
  return self;
@@ -718,7 +714,7 @@ memory_op_get_strptr(AbstractMemory* ptr, long offset)
718
714
  memcpy(&tmp, ptr->address + offset, sizeof(tmp));
719
715
  }
720
716
 
721
- return tmp != NULL ? rb_tainted_str_new2(tmp) : Qnil;
717
+ return tmp != NULL ? rb_str_new2(tmp) : Qnil;
722
718
  }
723
719
 
724
720
  static void
@@ -114,7 +114,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
114
114
  }
115
115
 
116
116
  /* ensure the memory is aligned on at least a 8 byte boundary */
117
- p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7UL);
117
+ p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7ULL);
118
118
 
119
119
  if (p->memory.size > 0 && (nargs < 3 || RTEST(rbClear))) {
120
120
  memset(p->memory.address, 0, p->memory.size);
@@ -154,7 +154,7 @@ buffer_initialize_copy(VALUE self, VALUE other)
154
154
  return Qnil;
155
155
  }
156
156
 
157
- dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7UL);
157
+ dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7ULL);
158
158
  dst->memory.size = src->size;
159
159
  dst->memory.typeSize = src->typeSize;
160
160
 
@@ -43,10 +43,8 @@
43
43
  #endif
44
44
  #include <errno.h>
45
45
  #include <ruby.h>
46
- #if defined(HAVE_RUBY_THREAD_H)
47
46
  #include <ruby/thread.h>
48
- #endif
49
- #if defined(HAVE_NATIVETHREAD) && (defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) && !defined(_WIN32)
47
+ #if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
50
48
  # include <signal.h>
51
49
  # include <pthread.h>
52
50
  #endif
@@ -116,7 +114,7 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
116
114
  Type* paramType = paramTypes[i];
117
115
  int type;
118
116
 
119
-
117
+
120
118
  if (unlikely(paramType->nativeType == NATIVE_MAPPED)) {
121
119
  VALUE values[] = { argv[argidx], Qnil };
122
120
  argv[argidx] = rb_funcall2(((MappedType *) paramType)->rbConverter, id_to_native, 2, values);
@@ -297,13 +295,9 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
297
295
 
298
296
  case NATIVE_STRING:
299
297
  if (type == T_NIL) {
300
- param->ptr = NULL;
301
-
302
- } else {
303
- if (rb_safe_level() >= 1 && OBJ_TAINTED(argv[argidx])) {
304
- rb_raise(rb_eSecurityError, "Unsafe string parameter");
305
- }
298
+ param->ptr = NULL;
306
299
 
300
+ } else {
307
301
  param->ptr = StringValueCStr(argv[argidx]);
308
302
  }
309
303
 
@@ -345,23 +339,21 @@ static void *
345
339
  call_blocking_function(void* data)
346
340
  {
347
341
  rbffi_blocking_call_t* b = (rbffi_blocking_call_t *) data;
348
- b->frame->has_gvl = false;
349
342
  ffi_call(&b->cif, FFI_FN(b->function), b->retval, b->ffiValues);
350
- b->frame->has_gvl = true;
351
343
 
352
344
  return NULL;
353
345
  }
354
346
 
355
347
  VALUE
356
- rbffi_do_blocking_call(void *data)
348
+ rbffi_do_blocking_call(VALUE data)
357
349
  {
358
- rbffi_thread_blocking_region(call_blocking_function, data, (void *) -1, NULL);
350
+ rb_thread_call_without_gvl(call_blocking_function, (void*)data, (rb_unblock_function_t *) -1, NULL);
359
351
 
360
352
  return Qnil;
361
353
  }
362
354
 
363
355
  VALUE
364
- rbffi_save_frame_exception(void *data, VALUE exc)
356
+ rbffi_save_frame_exception(VALUE data, VALUE exc)
365
357
  {
366
358
  rbffi_frame_t* frame = (rbffi_frame_t *) data;
367
359
  frame->exc = exc;
@@ -376,28 +368,17 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
376
368
  FFIStorage* params;
377
369
  VALUE rbReturnValue;
378
370
  rbffi_frame_t frame = { 0 };
379
-
371
+
380
372
  retval = alloca(MAX(fnInfo->ffi_cif.rtype->size, FFI_SIZEOF_ARG));
381
-
373
+
382
374
  if (unlikely(fnInfo->blocking)) {
383
375
  rbffi_blocking_call_t* bc;
384
376
 
385
- /*
386
- * due to the way thread switching works on older ruby variants, we
387
- * cannot allocate anything passed to the blocking function on the stack
388
- */
389
- #if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
377
+ /* allocate information passed to the blocking function on the stack */
390
378
  ffiValues = ALLOCA_N(void *, fnInfo->parameterCount);
391
379
  params = ALLOCA_N(FFIStorage, fnInfo->parameterCount);
392
380
  bc = ALLOCA_N(rbffi_blocking_call_t, 1);
393
381
  bc->retval = retval;
394
- #else
395
- ffiValues = ALLOC_N(void *, fnInfo->parameterCount);
396
- params = ALLOC_N(FFIStorage, fnInfo->parameterCount);
397
- bc = ALLOC_N(rbffi_blocking_call_t, 1);
398
- bc->retval = xmalloc(MAX(fnInfo->ffi_cif.rtype->size, FFI_SIZEOF_ARG));
399
- bc->stkretval = retval;
400
- #endif
401
382
  bc->cif = fnInfo->ffi_cif;
402
383
  bc->function = function;
403
384
  bc->ffiValues = ffiValues;
@@ -408,18 +389,10 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
408
389
  fnInfo->parameterCount, fnInfo->parameterTypes, params, ffiValues,
409
390
  fnInfo->callbackParameters, fnInfo->callbackCount, fnInfo->rbEnums);
410
391
 
411
- rbffi_frame_push(&frame);
392
+ rbffi_frame_push(&frame);
412
393
  rb_rescue2(rbffi_do_blocking_call, (VALUE) bc, rbffi_save_frame_exception, (VALUE) &frame, rb_eException, (VALUE) 0);
413
394
  rbffi_frame_pop(&frame);
414
395
 
415
- #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
416
- memcpy(bc->stkretval, bc->retval, MAX(bc->cif.rtype->size, FFI_SIZEOF_ARG));
417
- xfree(bc->params);
418
- xfree(bc->ffiValues);
419
- xfree(bc->retval);
420
- xfree(bc);
421
- #endif
422
-
423
396
  } else {
424
397
 
425
398
  ffiValues = ALLOCA_N(void *, fnInfo->parameterCount);
@@ -436,7 +409,7 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
436
409
 
437
410
  if (unlikely(!fnInfo->ignoreErrno)) {
438
411
  rbffi_save_errno();
439
- }
412
+ }
440
413
 
441
414
  if (RTEST(frame.exc) && frame.exc != Qnil) {
442
415
  rb_exc_raise(frame.exc);
@@ -444,7 +417,7 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
444
417
 
445
418
  RB_GC_GUARD(rbReturnValue) = rbffi_NativeValue_ToRuby(fnInfo->returnType, fnInfo->rbReturnType, retval);
446
419
  RB_GC_GUARD(fnInfo->rbReturnType);
447
-
420
+
448
421
  return rbReturnValue;
449
422
  }
450
423
 
@@ -461,7 +434,7 @@ getPointer(VALUE value, int type)
461
434
  return memory != NULL ? memory->address : NULL;
462
435
 
463
436
  } else if (type == T_STRING) {
464
-
437
+
465
438
  return StringValuePtr(value);
466
439
 
467
440
  } else if (type == T_NIL) {
@@ -48,7 +48,7 @@ extern "C" {
48
48
  #if (defined(__i386__) || defined(__x86_64__)) && !(defined(_WIN32) || defined(__WIN32__))
49
49
  # define BYPASS_FFI 1
50
50
  #endif
51
-
51
+
52
52
  typedef union {
53
53
  #ifdef USE_RAW
54
54
  signed int s8, s16, s32;
@@ -70,7 +70,7 @@ typedef union {
70
70
  double f64;
71
71
  long double ld;
72
72
  } FFIStorage;
73
-
73
+
74
74
  extern void rbffi_Call_Init(VALUE moduleFFI);
75
75
 
76
76
  extern void rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
@@ -94,13 +94,10 @@ typedef struct rbffi_blocking_call {
94
94
  void **ffiValues;
95
95
  void* retval;
96
96
  void* params;
97
- #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
98
- void* stkretval;
99
- #endif
100
97
  } rbffi_blocking_call_t;
101
98
 
102
- VALUE rbffi_do_blocking_call(void* data);
103
- VALUE rbffi_save_frame_exception(void *data, VALUE exc);
99
+ VALUE rbffi_do_blocking_call(VALUE data);
100
+ VALUE rbffi_save_frame_exception(VALUE data, VALUE exc);
104
101
 
105
102
  #ifdef __cplusplus
106
103
  }
@@ -70,9 +70,6 @@
70
70
  #ifndef roundup
71
71
  # define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
72
72
  #endif
73
- #ifdef _WIN32
74
- typedef char* caddr_t;
75
- #endif
76
73
 
77
74
  typedef struct Memory {
78
75
  void* code;
@@ -96,7 +93,7 @@ static bool freePage(void *);
96
93
  static bool protectPage(void *);
97
94
 
98
95
  ClosurePool*
99
- rbffi_ClosurePool_New(int closureSize,
96
+ rbffi_ClosurePool_New(int closureSize,
100
97
  bool (*prep)(void* ctx, void *code, Closure* closure, char* errbuf, size_t errbufsize),
101
98
  void* ctx)
102
99
  {
@@ -107,7 +104,7 @@ rbffi_ClosurePool_New(int closureSize,
107
104
  pool->ctx = ctx;
108
105
  pool->prep = prep;
109
106
  pool->refcnt = 1;
110
-
107
+
111
108
  return pool;
112
109
  }
113
110
 
@@ -115,7 +112,7 @@ void
115
112
  cleanup_closure_pool(ClosurePool* pool)
116
113
  {
117
114
  Memory* memory;
118
-
115
+
119
116
  for (memory = pool->blocks; memory != NULL; ) {
120
117
  Memory* next = memory->next;
121
118
  freePage(memory->code);
@@ -142,7 +139,7 @@ rbffi_Closure_Alloc(ClosurePool* pool)
142
139
  {
143
140
  Closure *list = NULL;
144
141
  Memory* block = NULL;
145
- caddr_t code = NULL;
142
+ void *code = NULL;
146
143
  char errmsg[256];
147
144
  int nclosures;
148
145
  long trampolineSize;
@@ -152,7 +149,7 @@ rbffi_Closure_Alloc(ClosurePool* pool)
152
149
  Closure* closure = pool->list;
153
150
  pool->list = pool->list->next;
154
151
  pool->refcnt++;
155
-
152
+
156
153
  return closure;
157
154
  }
158
155
 
@@ -161,17 +158,17 @@ rbffi_Closure_Alloc(ClosurePool* pool)
161
158
  block = calloc(1, sizeof(*block));
162
159
  list = calloc(nclosures, sizeof(*list));
163
160
  code = allocatePage();
164
-
161
+
165
162
  if (block == NULL || list == NULL || code == NULL) {
166
163
  snprintf(errmsg, sizeof(errmsg), "failed to allocate a page. errno=%d (%s)", errno, strerror(errno));
167
164
  goto error;
168
165
  }
169
-
166
+
170
167
  for (i = 0; i < nclosures; ++i) {
171
168
  Closure* closure = &list[i];
172
169
  closure->next = &list[i + 1];
173
170
  closure->pool = pool;
174
- closure->code = (code + (i * trampolineSize));
171
+ closure->code = ((char *)code + (i * trampolineSize));
175
172
 
176
173
  if (!(*pool->prep)(pool->ctx, closure->code, closure, errmsg, sizeof(errmsg))) {
177
174
  goto error;
@@ -202,7 +199,7 @@ error:
202
199
  if (code != NULL) {
203
200
  freePage(code);
204
201
  }
205
-
202
+
206
203
 
207
204
  rb_raise(rb_eRuntimeError, "%s", errmsg);
208
205
  return NULL;
@@ -249,8 +246,8 @@ allocatePage(void)
249
246
  #if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__))
250
247
  return VirtualAlloc(NULL, pageSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
251
248
  #else
252
- caddr_t page = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
253
- return (page != (caddr_t) -1) ? page : NULL;
249
+ void *page = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
250
+ return (page != (void *) -1) ? page : NULL;
254
251
  #endif
255
252
  }
256
253
 
@@ -164,7 +164,7 @@ library_dlerror(VALUE self)
164
164
  {
165
165
  char errmsg[1024];
166
166
  dl_error(errmsg, sizeof(errmsg));
167
- return rb_tainted_str_new2(errmsg);
167
+ return rb_str_new2(errmsg);
168
168
  }
169
169
 
170
170
  static void
@@ -47,9 +47,7 @@
47
47
  # endif
48
48
  #endif
49
49
  #include <ruby.h>
50
- #if defined(HAVE_RUBY_THREAD_H)
51
50
  #include <ruby/thread.h>
52
- #endif
53
51
 
54
52
  #include <ffi.h>
55
53
  #if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
@@ -90,8 +88,8 @@ static VALUE function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc);
90
88
  static void callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data);
91
89
  static bool callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize);
92
90
  static void* callback_with_gvl(void* data);
93
- static VALUE invoke_callback(void* data);
94
- static VALUE save_callback_exception(void* data, VALUE exc);
91
+ static VALUE invoke_callback(VALUE data);
92
+ static VALUE save_callback_exception(VALUE data, VALUE exc);
95
93
 
96
94
  #define DEFER_ASYNC_CALLBACK 1
97
95
 
@@ -101,9 +99,8 @@ static VALUE async_cb_event(void *);
101
99
  static VALUE async_cb_call(void *);
102
100
  #endif
103
101
 
104
- #ifdef HAVE_RB_THREAD_CALL_WITH_GVL
105
- extern void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
106
- #endif
102
+ extern int ruby_thread_has_gvl_p(void);
103
+ extern int ruby_native_thread_p(void);
107
104
 
108
105
  VALUE rbffi_FunctionClass = Qnil;
109
106
 
@@ -136,15 +133,9 @@ static struct gvl_callback* async_cb_list = NULL;
136
133
  # ifndef _WIN32
137
134
  static pthread_mutex_t async_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
138
135
  static pthread_cond_t async_cb_cond = PTHREAD_COND_INITIALIZER;
139
- # if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
140
- static int async_cb_pipe[2];
141
- # endif
142
136
  # else
143
137
  static HANDLE async_cb_cond;
144
138
  static CRITICAL_SECTION async_cb_lock;
145
- # if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
146
- static int async_cb_pipe[2];
147
- # endif
148
139
  # endif
149
140
  #endif
150
141
 
@@ -323,16 +314,8 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
323
314
 
324
315
  #if defined(DEFER_ASYNC_CALLBACK)
325
316
  if (async_cb_thread == Qnil) {
326
- #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) && defined(_WIN32)
327
- _pipe(async_cb_pipe, 1024, O_BINARY);
328
- #elif !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
329
- pipe(async_cb_pipe);
330
- fcntl(async_cb_pipe[0], F_SETFL, fcntl(async_cb_pipe[0], F_GETFL) | O_NONBLOCK);
331
- fcntl(async_cb_pipe[1], F_SETFL, fcntl(async_cb_pipe[1], F_GETFL) | O_NONBLOCK);
332
- #endif
333
317
  async_cb_thread = rb_thread_create(async_cb_event, NULL);
334
318
  }
335
-
336
319
  #endif
337
320
 
338
321
  fn->closure = rbffi_Closure_Alloc(fn->info->closurePool);
@@ -474,13 +457,13 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
474
457
  cb.frame = rbffi_frame_current();
475
458
 
476
459
  if (cb.frame != NULL) cb.frame->exc = Qnil;
477
- if (cb.frame != NULL && cb.frame->has_gvl) {
478
- callback_with_gvl(&cb);
479
460
 
480
- #if defined(HAVE_RB_THREAD_CALL_WITH_GVL)
481
- } else if (cb.frame != NULL) {
461
+ if (ruby_native_thread_p()) {
462
+ if(ruby_thread_has_gvl_p()) {
463
+ callback_with_gvl(&cb);
464
+ } else {
482
465
  rb_thread_call_with_gvl(callback_with_gvl, &cb);
483
- #endif
466
+ }
484
467
  #if defined(DEFER_ASYNC_CALLBACK) && !defined(_WIN32)
485
468
  } else {
486
469
  bool empty = false;
@@ -494,17 +477,8 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
494
477
  cb.next = async_cb_list;
495
478
  async_cb_list = &cb;
496
479
 
497
- #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
498
- pthread_mutex_unlock(&async_cb_mutex);
499
- /* Only signal if the list was empty */
500
- if (empty) {
501
- char c;
502
- write(async_cb_pipe[1], &c, 1);
503
- }
504
- #else
505
480
  pthread_cond_signal(&async_cb_cond);
506
481
  pthread_mutex_unlock(&async_cb_mutex);
507
- #endif
508
482
 
509
483
  /* Wait for the thread executing the ruby callback to signal it is done */
510
484
  pthread_mutex_lock(&cb.async_mutex);
@@ -528,15 +502,7 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
528
502
  async_cb_list = &cb;
529
503
  LeaveCriticalSection(&async_cb_lock);
530
504
 
531
- #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
532
- /* Only signal if the list was empty */
533
- if (empty) {
534
- char c;
535
- write(async_cb_pipe[1], &c, 1);
536
- }
537
- #else
538
505
  SetEvent(async_cb_cond);
539
- #endif
540
506
 
541
507
  /* Wait for the thread executing the ruby callback to signal it is done */
542
508
  WaitForSingleObject(cb.async_event, INFINITE);
@@ -554,7 +520,6 @@ struct async_wait {
554
520
  static void * async_cb_wait(void *);
555
521
  static void async_cb_stop(void *);
556
522
 
557
- #if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
558
523
  static VALUE
559
524
  async_cb_event(void* unused)
560
525
  {
@@ -562,11 +527,7 @@ async_cb_event(void* unused)
562
527
 
563
528
  w.stop = false;
564
529
  while (!w.stop) {
565
- #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
566
530
  rb_thread_call_without_gvl(async_cb_wait, &w, async_cb_stop, &w);
567
- #else
568
- rb_thread_blocking_region(async_cb_wait, &w, async_cb_stop, &w);
569
- #endif
570
531
  if (w.cb != NULL) {
571
532
  /* Start up a new ruby thread to run the ruby callback */
572
533
  rb_thread_create(async_cb_call, w.cb);
@@ -576,69 +537,6 @@ async_cb_event(void* unused)
576
537
  return Qnil;
577
538
  }
578
539
 
579
- #elif defined(_WIN32)
580
- static VALUE
581
- async_cb_event(void* unused)
582
- {
583
- while (true) {
584
- struct gvl_callback* cb;
585
- char buf[64];
586
- fd_set rfds;
587
-
588
- FD_ZERO(&rfds);
589
- FD_SET(async_cb_pipe[0], &rfds);
590
- rb_thread_select(async_cb_pipe[0] + 1, &rfds, NULL, NULL, NULL);
591
- read(async_cb_pipe[0], buf, sizeof(buf));
592
-
593
- EnterCriticalSection(&async_cb_lock);
594
- cb = async_cb_list;
595
- async_cb_list = NULL;
596
- LeaveCriticalSection(&async_cb_lock);
597
-
598
- while (cb != NULL) {
599
- struct gvl_callback* next = cb->next;
600
- /* Start up a new ruby thread to run the ruby callback */
601
- rb_thread_create(async_cb_call, cb);
602
- cb = next;
603
- }
604
- }
605
-
606
- return Qnil;
607
- }
608
- #else
609
- static VALUE
610
- async_cb_event(void* unused)
611
- {
612
- while (true) {
613
- struct gvl_callback* cb;
614
- char buf[64];
615
-
616
- if (read(async_cb_pipe[0], buf, sizeof(buf)) < 0) {
617
- rb_thread_wait_fd(async_cb_pipe[0]);
618
- while (read(async_cb_pipe[0], buf, sizeof (buf)) < 0) {
619
- if (rb_io_wait_readable(async_cb_pipe[0]) != Qtrue) {
620
- return Qfalse;
621
- }
622
- }
623
- }
624
-
625
- pthread_mutex_lock(&async_cb_mutex);
626
- cb = async_cb_list;
627
- async_cb_list = NULL;
628
- pthread_mutex_unlock(&async_cb_mutex);
629
-
630
- while (cb != NULL) {
631
- struct gvl_callback* next = cb->next;
632
- /* Start up a new ruby thread to run the ruby callback */
633
- rb_thread_create(async_cb_call, cb);
634
- cb = next;
635
- }
636
- }
637
-
638
- return Qnil;
639
- }
640
- #endif
641
-
642
540
  #ifdef _WIN32
643
541
  static void *
644
542
  async_cb_wait(void *data)
@@ -742,7 +640,7 @@ callback_with_gvl(void* data)
742
640
  }
743
641
 
744
642
  static VALUE
745
- invoke_callback(void* data)
643
+ invoke_callback(VALUE data)
746
644
  {
747
645
  struct gvl_callback* cb = (struct gvl_callback *) data;
748
646
 
@@ -805,10 +703,10 @@ invoke_callback(void* data)
805
703
  param = rb_float_new(*(double *) parameters[i]);
806
704
  break;
807
705
  case NATIVE_LONGDOUBLE:
808
- param = rbffi_longdouble_new(*(long double *) parameters[i]);
706
+ param = rbffi_longdouble_new(*(long double *) parameters[i]);
809
707
  break;
810
708
  case NATIVE_STRING:
811
- param = (*(void **) parameters[i] != NULL) ? rb_tainted_str_new2(*(char **) parameters[i]) : Qnil;
709
+ param = (*(void **) parameters[i] != NULL) ? rb_str_new2(*(char **) parameters[i]) : Qnil;
812
710
  break;
813
711
  case NATIVE_POINTER:
814
712
  param = rbffi_Pointer_NewInstance(*(void **) parameters[i]);
@@ -877,6 +775,9 @@ invoke_callback(void* data)
877
775
  case NATIVE_FLOAT64:
878
776
  *((double *) retval) = NUM2DBL(rbReturnValue);
879
777
  break;
778
+ case NATIVE_LONGDOUBLE:
779
+ *((long double *) retval) = rbffi_num2longdouble(rbReturnValue);
780
+ break;
880
781
  case NATIVE_POINTER:
881
782
  if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_PointerClass)) {
882
783
  *((void **) retval) = ((AbstractMemory *) DATA_PTR(rbReturnValue))->address;
@@ -932,7 +833,7 @@ invoke_callback(void* data)
932
833
  }
933
834
 
934
835
  static VALUE
935
- save_callback_exception(void* data, VALUE exc)
836
+ save_callback_exception(VALUE data, VALUE exc)
936
837
  {
937
838
  struct gvl_callback* cb = (struct gvl_callback *) data;
938
839
 
@@ -948,9 +849,9 @@ callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errm
948
849
  FunctionType* fnInfo = (FunctionType *) ctx;
949
850
  ffi_status ffiStatus;
950
851
 
951
- ffiStatus = ffi_prep_closure(code, &fnInfo->ffi_cif, callback_invoke, closure);
852
+ ffiStatus = ffi_prep_closure_loc(code, &fnInfo->ffi_cif, callback_invoke, closure, code);
952
853
  if (ffiStatus != FFI_OK) {
953
- snprintf(errmsg, errmsgsize, "ffi_prep_closure failed. status=%#x", ffiStatus);
854
+ snprintf(errmsg, errmsgsize, "ffi_prep_closure_loc failed. status=%#x", ffiStatus);
954
855
  return false;
955
856
  }
956
857