ffi 1.9.25 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (339) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +212 -0
  3. data/Gemfile +3 -4
  4. data/README.md +38 -18
  5. data/Rakefile +55 -146
  6. data/ext/ffi_c/AbstractMemory.c +29 -34
  7. data/ext/ffi_c/Buffer.c +4 -9
  8. data/ext/ffi_c/Call.c +16 -49
  9. data/ext/ffi_c/Call.h +4 -7
  10. data/ext/ffi_c/ClosurePool.c +75 -25
  11. data/ext/ffi_c/ClosurePool.h +3 -1
  12. data/ext/ffi_c/DynamicLibrary.c +2 -7
  13. data/ext/ffi_c/Function.c +47 -131
  14. data/ext/ffi_c/Function.h +0 -4
  15. data/ext/ffi_c/FunctionInfo.c +3 -8
  16. data/ext/ffi_c/LastError.c +49 -8
  17. data/ext/ffi_c/LongDouble.c +12 -10
  18. data/ext/ffi_c/LongDouble.h +0 -4
  19. data/ext/ffi_c/MemoryPointer.c +3 -8
  20. data/ext/ffi_c/MemoryPointer.h +0 -4
  21. data/ext/ffi_c/MethodHandle.c +21 -31
  22. data/ext/ffi_c/MethodHandle.h +3 -2
  23. data/ext/ffi_c/Platform.c +3 -54
  24. data/ext/ffi_c/Pointer.c +25 -26
  25. data/ext/ffi_c/Pointer.h +0 -4
  26. data/ext/ffi_c/Struct.c +49 -56
  27. data/ext/ffi_c/Struct.h +12 -6
  28. data/ext/ffi_c/StructByValue.c +2 -7
  29. data/ext/ffi_c/StructLayout.c +22 -20
  30. data/ext/ffi_c/Thread.c +4 -228
  31. data/ext/ffi_c/Thread.h +1 -20
  32. data/ext/ffi_c/Type.c +1 -19
  33. data/ext/ffi_c/Type.h +0 -1
  34. data/ext/ffi_c/Types.c +7 -8
  35. data/ext/ffi_c/Types.h +3 -4
  36. data/ext/ffi_c/Variadic.c +23 -24
  37. data/ext/ffi_c/compat.h +4 -0
  38. data/ext/ffi_c/extconf.rb +53 -30
  39. data/ext/ffi_c/ffi.c +3 -8
  40. data/ext/ffi_c/libffi.darwin.mk +1 -1
  41. data/ext/ffi_c/libffi/.appveyor.yml +29 -13
  42. data/ext/ffi_c/libffi/.gitattributes +4 -0
  43. data/ext/ffi_c/libffi/.travis.yml +51 -2
  44. data/ext/ffi_c/libffi/.travis/bfin-sim.exp +58 -0
  45. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +14 -0
  46. data/ext/ffi_c/libffi/.travis/build-in-container.sh +12 -0
  47. data/ext/ffi_c/libffi/.travis/build.sh +116 -8
  48. data/ext/ffi_c/libffi/.travis/install.sh +65 -16
  49. data/ext/ffi_c/libffi/.travis/m32r-sim.exp +58 -0
  50. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +1 -1
  51. data/ext/ffi_c/libffi/.travis/or1k-sim.exp +58 -0
  52. data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +58 -0
  53. data/ext/ffi_c/libffi/.travis/site.exp +10 -1
  54. data/ext/ffi_c/libffi/.travis/wine-sim.exp +55 -0
  55. data/ext/ffi_c/libffi/{ChangeLog.libffi-3.1 → ChangeLog.old} +1407 -0
  56. data/ext/ffi_c/libffi/LICENSE +1 -1
  57. data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +5 -4
  58. data/ext/ffi_c/libffi/Makefile.am +56 -72
  59. data/ext/ffi_c/libffi/README.md +33 -8
  60. data/ext/ffi_c/libffi/config.guess +552 -331
  61. data/ext/ffi_c/libffi/config.sub +1321 -1306
  62. data/ext/ffi_c/libffi/configure.ac +37 -12
  63. data/ext/ffi_c/libffi/configure.host +56 -27
  64. data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
  65. data/ext/ffi_c/libffi/doc/libffi.texi +997 -0
  66. data/ext/ffi_c/libffi/doc/version.texi +4 -0
  67. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +2 -4
  68. data/ext/ffi_c/libffi/include/ffi.h.in +19 -7
  69. data/ext/ffi_c/libffi/include/ffi_common.h +5 -1
  70. data/ext/ffi_c/libffi/libffi.map.in +8 -12
  71. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +2 -48
  72. data/ext/ffi_c/libffi/libtool-version +1 -1
  73. data/ext/ffi_c/libffi/m4/asmcfi.m4 +1 -1
  74. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +5 -26
  75. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +5 -26
  76. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +2 -1
  77. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +5 -26
  78. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +7 -3
  79. data/ext/ffi_c/libffi/make_sunver.pl +333 -0
  80. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.sln +33 -0
  81. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj +130 -0
  82. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.filters +57 -0
  83. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user +4 -0
  84. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +511 -0
  85. data/ext/ffi_c/libffi/msvcc.sh +38 -13
  86. data/ext/ffi_c/libffi/src/aarch64/ffi.c +153 -69
  87. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +19 -3
  88. data/ext/ffi_c/libffi/src/aarch64/internal.h +1 -0
  89. data/ext/ffi_c/libffi/src/aarch64/sysv.S +22 -9
  90. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
  91. data/ext/ffi_c/libffi/src/arm/ffi.c +62 -5
  92. data/ext/ffi_c/libffi/src/arm/ffitarget.h +8 -1
  93. data/ext/ffi_c/libffi/src/arm/sysv.S +6 -4
  94. data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
  95. data/ext/ffi_c/libffi/src/closures.c +69 -14
  96. data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
  97. data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
  98. data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
  99. data/ext/ffi_c/libffi/src/dlmalloc.c +1 -1
  100. data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
  101. data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
  102. data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
  103. data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
  104. data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
  105. data/ext/ffi_c/libffi/src/metag/ffi.c +1 -1
  106. data/ext/ffi_c/libffi/src/mips/ffi.c +5 -1
  107. data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
  108. data/ext/ffi_c/libffi/src/mips/o32.S +2 -0
  109. data/ext/ffi_c/libffi/src/moxie/ffi.c +1 -1
  110. data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
  111. data/ext/ffi_c/libffi/src/pa/ffitarget.h +1 -6
  112. data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
  113. data/ext/ffi_c/libffi/src/pa/linux.S +27 -4
  114. data/ext/ffi_c/libffi/src/powerpc/ffi.c +6 -4
  115. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +13 -1
  116. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +211 -32
  117. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +18 -7
  118. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +10 -4
  119. data/ext/ffi_c/libffi/src/powerpc/linux64.S +91 -28
  120. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +81 -5
  121. data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
  122. data/ext/ffi_c/libffi/src/prep_cif.c +4 -2
  123. data/ext/ffi_c/libffi/src/riscv/ffi.c +42 -6
  124. data/ext/ffi_c/libffi/src/riscv/ffitarget.h +1 -0
  125. data/ext/ffi_c/libffi/src/riscv/sysv.S +86 -7
  126. data/ext/ffi_c/libffi/src/x86/ffi.c +29 -12
  127. data/ext/ffi_c/libffi/src/x86/ffi64.c +22 -11
  128. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
  129. data/ext/ffi_c/libffi/src/x86/ffiw64.c +20 -10
  130. data/ext/ffi_c/libffi/src/x86/sysv.S +105 -10
  131. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +995 -0
  132. data/ext/ffi_c/libffi/src/x86/unix64.S +100 -4
  133. data/ext/ffi_c/libffi/src/x86/win64.S +12 -3
  134. data/ext/ffi_c/libffi/src/x86/win64_intel.S +3 -2
  135. data/ext/ffi_c/libffi/testsuite/Makefile.am +114 -109
  136. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +32 -8
  137. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +7 -2
  138. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +4 -4
  139. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2 -2
  140. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +12 -1
  141. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +9 -8
  142. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -1
  143. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure.exp +67 -0
  144. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn0.c +0 -0
  145. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn1.c +0 -0
  146. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn2.c +0 -0
  147. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn3.c +0 -0
  148. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn4.c +0 -0
  149. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn5.c +0 -0
  150. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn6.c +0 -0
  151. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_loc_fn0.c +0 -0
  152. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_simple.c +0 -0
  153. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_12byte.c +0 -0
  154. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_16byte.c +0 -0
  155. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_18byte.c +0 -0
  156. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_19byte.c +0 -0
  157. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_1_1byte.c +0 -0
  158. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte.c +0 -0
  159. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte1.c +0 -0
  160. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_24byte.c +0 -0
  161. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_2byte.c +0 -0
  162. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3_1byte.c +0 -0
  163. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte1.c +0 -0
  164. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte2.c +0 -0
  165. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3float.c +0 -0
  166. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4_1byte.c +0 -0
  167. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4byte.c +0 -0
  168. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5_1_byte.c +0 -0
  169. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5byte.c +0 -0
  170. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_64byte.c +0 -0
  171. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6_1_byte.c +0 -0
  172. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6byte.c +0 -0
  173. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7_1_byte.c +0 -0
  174. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7byte.c +0 -0
  175. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_8byte.c +0 -0
  176. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte1.c +0 -0
  177. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte2.c +0 -0
  178. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_double.c +0 -0
  179. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_float.c +0 -0
  180. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble.c +0 -0
  181. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split.c +0 -0
  182. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split2.c +0 -0
  183. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_pointer.c +0 -0
  184. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint16.c +0 -0
  185. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint32.c +0 -0
  186. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint64.c +0 -0
  187. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint16.c +0 -0
  188. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint32.c +0 -0
  189. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint64.c +0 -0
  190. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_dbls_struct.c +0 -0
  191. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double.c +0 -0
  192. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double_va.c +0 -0
  193. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_float.c +0 -0
  194. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble.c +0 -0
  195. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble_va.c +0 -0
  196. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_args.c +0 -0
  197. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_float_double.c +0 -0
  198. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_schar.c +0 -0
  199. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshort.c +0 -0
  200. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshortchar.c +0 -0
  201. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_uchar.c +0 -0
  202. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushort.c +0 -0
  203. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushortchar.c +0 -0
  204. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer.c +0 -0
  205. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer_stack.c +0 -0
  206. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_schar.c +0 -0
  207. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sint.c +0 -0
  208. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sshort.c +0 -0
  209. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_struct_va1.c +0 -0
  210. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar.c +0 -0
  211. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar_va.c +0 -0
  212. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint.c +0 -0
  213. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint_va.c +0 -0
  214. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulong_va.c +0 -0
  215. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulonglong.c +0 -0
  216. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort.c +0 -0
  217. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort_va.c +0 -0
  218. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/err_bad_abi.c +0 -0
  219. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +138 -0
  220. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/huge_struct.c +3 -1
  221. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct.c +0 -0
  222. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct1.c +0 -0
  223. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct10.c +0 -0
  224. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct11.c +0 -0
  225. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct2.c +0 -0
  226. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct3.c +0 -0
  227. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct4.c +0 -0
  228. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct5.c +0 -0
  229. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct6.c +0 -0
  230. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct7.c +0 -0
  231. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct8.c +0 -0
  232. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct9.c +0 -0
  233. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/problem1.c +0 -0
  234. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large.c +0 -0
  235. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large2.c +0 -0
  236. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium.c +0 -0
  237. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium2.c +0 -0
  238. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/testclosure.c +0 -0
  239. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest.cc +0 -0
  240. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest_ffi_call.cc +0 -0
  241. data/ext/ffi_c/rbffi.h +0 -2
  242. data/ffi.gemspec +13 -6
  243. data/lib/ffi.rb +10 -2
  244. data/lib/ffi/abstract_memory.rb +44 -0
  245. data/lib/ffi/autopointer.rb +1 -1
  246. data/lib/ffi/data_converter.rb +67 -0
  247. data/lib/ffi/ffi.rb +3 -0
  248. data/lib/ffi/io.rb +3 -3
  249. data/lib/ffi/library.rb +12 -8
  250. data/lib/ffi/managedstruct.rb +2 -2
  251. data/lib/ffi/platform.rb +34 -10
  252. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  253. data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
  254. data/lib/ffi/platform/aarch64-freebsd12/types.conf +128 -0
  255. data/lib/ffi/platform/aarch64-linux/types.conf +81 -81
  256. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  257. data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
  258. data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
  259. data/lib/ffi/platform/arm-linux/types.conf +110 -82
  260. data/lib/ffi/platform/i386-cygwin/types.conf +1 -1
  261. data/lib/ffi/platform/i386-darwin/types.conf +63 -63
  262. data/lib/ffi/platform/i386-freebsd/types.conf +89 -89
  263. data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
  264. data/lib/ffi/platform/i386-gnu/types.conf +84 -84
  265. data/lib/ffi/platform/i386-linux/types.conf +77 -77
  266. data/lib/ffi/platform/i386-netbsd/types.conf +87 -87
  267. data/lib/ffi/platform/i386-openbsd/types.conf +89 -89
  268. data/lib/ffi/platform/i386-solaris/types.conf +96 -96
  269. data/lib/ffi/platform/i386-windows/types.conf +43 -96
  270. data/lib/ffi/platform/ia64-linux/types.conf +79 -79
  271. data/lib/ffi/platform/mips-linux/types.conf +79 -79
  272. data/lib/ffi/platform/mips64-linux/types.conf +81 -81
  273. data/lib/ffi/platform/mips64el-linux/types.conf +81 -81
  274. data/lib/ffi/platform/mipsel-linux/types.conf +79 -79
  275. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +79 -79
  276. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +79 -79
  277. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +81 -81
  278. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +81 -81
  279. data/lib/ffi/platform/powerpc-aix/types.conf +155 -155
  280. data/lib/ffi/platform/powerpc-darwin/types.conf +63 -63
  281. data/lib/ffi/platform/powerpc-linux/types.conf +108 -78
  282. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  283. data/lib/ffi/platform/powerpc64-linux/types.conf +81 -81
  284. data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
  285. data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
  286. data/lib/ffi/platform/s390-linux/types.conf +79 -79
  287. data/lib/ffi/platform/s390x-linux/types.conf +79 -79
  288. data/lib/ffi/platform/sparc-linux/types.conf +79 -79
  289. data/lib/ffi/platform/sparc-solaris/types.conf +103 -103
  290. data/lib/ffi/platform/sparc64-linux/types.conf +79 -79
  291. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  292. data/lib/ffi/platform/sparcv9-solaris/types.conf +103 -103
  293. data/lib/ffi/platform/x86_64-cygwin/types.conf +1 -1
  294. data/lib/ffi/platform/x86_64-darwin/types.conf +88 -84
  295. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
  296. data/lib/ffi/platform/x86_64-freebsd/types.conf +90 -90
  297. data/lib/ffi/platform/x86_64-freebsd12/types.conf +158 -0
  298. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  299. data/lib/ffi/platform/x86_64-linux/types.conf +107 -77
  300. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  301. data/lib/ffi/platform/x86_64-netbsd/types.conf +89 -89
  302. data/lib/ffi/platform/x86_64-openbsd/types.conf +86 -86
  303. data/lib/ffi/platform/x86_64-solaris/types.conf +96 -96
  304. data/lib/ffi/platform/x86_64-windows/types.conf +42 -110
  305. data/lib/ffi/pointer.rb +26 -20
  306. data/lib/ffi/struct.rb +13 -68
  307. data/lib/ffi/struct_by_reference.rb +72 -0
  308. data/lib/ffi/struct_layout.rb +96 -0
  309. data/lib/ffi/tools/const_generator.rb +5 -4
  310. data/lib/ffi/tools/generator.rb +47 -2
  311. data/lib/ffi/tools/generator_task.rb +13 -17
  312. data/lib/ffi/tools/struct_generator.rb +4 -4
  313. data/lib/ffi/tools/types_generator.rb +7 -4
  314. data/lib/ffi/types.rb +1 -1
  315. data/lib/ffi/variadic.rb +1 -10
  316. data/lib/ffi/version.rb +1 -1
  317. data/rakelib/ffi_gem_helper.rb +65 -0
  318. data/samples/getlogin.rb +1 -1
  319. data/samples/getpid.rb +1 -1
  320. data/samples/gettimeofday.rb +8 -8
  321. data/samples/hello.rb +2 -1
  322. data/samples/inotify.rb +1 -1
  323. data/samples/pty.rb +1 -2
  324. data/samples/qsort.rb +0 -1
  325. metadata +160 -122
  326. data/.gitignore +0 -22
  327. data/.gitmodules +0 -3
  328. data/.travis.yml +0 -52
  329. data/.yardopts +0 -5
  330. data/appveyor.yml +0 -22
  331. data/ext/ffi_c/DataConverter.c +0 -91
  332. data/ext/ffi_c/StructByReference.c +0 -190
  333. data/ext/ffi_c/StructByReference.h +0 -50
  334. data/ext/ffi_c/libffi/ChangeLog.libffi +0 -584
  335. data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
  336. data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
  337. data/ext/ffi_c/win32/stdbool.h +0 -8
  338. data/ext/ffi_c/win32/stdint.h +0 -201
  339. data/samples/sample_helper.rb +0 -6
@@ -35,7 +35,9 @@ typedef struct Closure_ Closure;
35
35
  struct Closure_ {
36
36
  void* info; /* opaque handle for storing closure-instance specific data */
37
37
  void* function; /* closure-instance specific function, called by custom trampoline */
38
- void* code; /* The native trampoline code location */
38
+ void* code; /* Executable address for the native trampoline code location */
39
+ void* pcl; /* Writeable address for the native trampoline code location */
40
+
39
41
  struct ClosurePool_* pool;
40
42
  Closure* next;
41
43
  };
@@ -29,9 +29,7 @@
29
29
 
30
30
  #include <sys/types.h>
31
31
  #include <stdio.h>
32
- #ifndef _MSC_VER
33
- # include <stdint.h>
34
- #endif
32
+ #include <stdint.h>
35
33
  #if (defined(_WIN32) || defined(__WIN32__)) && !defined(__CYGWIN__)
36
34
  # include <winsock2.h>
37
35
  # define _WINSOCKAPI_
@@ -41,9 +39,6 @@
41
39
  # include <dlfcn.h>
42
40
  #endif
43
41
  #include <ruby.h>
44
- #if defined(_MSC_VER) && !defined(INT8_MIN)
45
- # include "win32/stdint.h"
46
- #endif
47
42
 
48
43
  #include <ffi.h>
49
44
 
@@ -164,7 +159,7 @@ library_dlerror(VALUE self)
164
159
  {
165
160
  char errmsg[1024];
166
161
  dl_error(errmsg, sizeof(errmsg));
167
- return rb_tainted_str_new2(errmsg);
162
+ return rb_str_new2(errmsg);
168
163
  }
169
164
 
170
165
  static void
data/ext/ffi_c/Function.c CHANGED
@@ -37,19 +37,10 @@
37
37
  #endif
38
38
 
39
39
  #include <stdio.h>
40
- #ifndef _MSC_VER
41
- # include <stdint.h>
42
- # include <stdbool.h>
43
- #else
44
- # include "win32/stdbool.h"
45
- # if !defined(INT8_MIN)
46
- # include "win32/stdint.h"
47
- # endif
48
- #endif
40
+ #include <stdint.h>
41
+ #include <stdbool.h>
49
42
  #include <ruby.h>
50
- #if defined(HAVE_RUBY_THREAD_H)
51
43
  #include <ruby/thread.h>
52
- #endif
53
44
 
54
45
  #include <ffi.h>
55
46
  #if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
@@ -90,8 +81,8 @@ static VALUE function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc);
90
81
  static void callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data);
91
82
  static bool callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize);
92
83
  static void* callback_with_gvl(void* data);
93
- static VALUE invoke_callback(void* data);
94
- static VALUE save_callback_exception(void* data, VALUE exc);
84
+ static VALUE invoke_callback(VALUE data);
85
+ static VALUE save_callback_exception(VALUE data, VALUE exc);
95
86
 
96
87
  #define DEFER_ASYNC_CALLBACK 1
97
88
 
@@ -101,9 +92,8 @@ static VALUE async_cb_event(void *);
101
92
  static VALUE async_cb_call(void *);
102
93
  #endif
103
94
 
104
- #ifdef HAVE_RB_THREAD_CALL_WITH_GVL
105
- extern void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
106
- #endif
95
+ extern int ruby_thread_has_gvl_p(void);
96
+ extern int ruby_native_thread_p(void);
107
97
 
108
98
  VALUE rbffi_FunctionClass = Qnil;
109
99
 
@@ -136,15 +126,9 @@ static struct gvl_callback* async_cb_list = NULL;
136
126
  # ifndef _WIN32
137
127
  static pthread_mutex_t async_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
138
128
  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
129
  # else
143
130
  static HANDLE async_cb_cond;
144
131
  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
132
  # endif
149
133
  #endif
150
134
 
@@ -265,11 +249,11 @@ VALUE
265
249
  rbffi_Function_ForProc(VALUE rbFunctionInfo, VALUE proc)
266
250
  {
267
251
  VALUE callback, cbref, cbTable;
268
- Function* fp;
269
252
 
270
253
  cbref = RTEST(rb_ivar_defined(proc, id_cb_ref)) ? rb_ivar_get(proc, id_cb_ref) : Qnil;
271
254
  /* If the first callback reference has the same function function signature, use it */
272
255
  if (cbref != Qnil && CLASS_OF(cbref) == rbffi_FunctionClass) {
256
+ Function* fp;
273
257
  Data_Get_Struct(cbref, Function, fp);
274
258
  if (fp->rbFunctionInfo == rbFunctionInfo) {
275
259
  return cbref;
@@ -288,14 +272,27 @@ rbffi_Function_ForProc(VALUE rbFunctionInfo, VALUE proc)
288
272
  rb_ivar_set(proc, id_cb_ref, callback);
289
273
  } else {
290
274
  /* The proc instance has been used as more than one type of callback, store extras in a hash */
291
- cbTable = rb_hash_new();
292
- rb_ivar_set(proc, id_cbtable, cbTable);
275
+ if(cbTable == Qnil) {
276
+ cbTable = rb_hash_new();
277
+ rb_ivar_set(proc, id_cbtable, cbTable);
278
+ }
293
279
  rb_hash_aset(cbTable, rbFunctionInfo, callback);
294
280
  }
295
281
 
296
282
  return callback;
297
283
  }
298
284
 
285
+ #if !defined(_WIN32) && defined(DEFER_ASYNC_CALLBACK)
286
+ static void
287
+ after_fork_callback(void)
288
+ {
289
+ /* Ensure that a new dispatcher thread is started in a forked process */
290
+ async_cb_thread = Qnil;
291
+ pthread_mutex_init(&async_cb_mutex, NULL);
292
+ pthread_cond_init(&async_cb_cond, NULL);
293
+ }
294
+ #endif
295
+
299
296
  static VALUE
300
297
  function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
301
298
  {
@@ -323,16 +320,17 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
323
320
 
324
321
  #if defined(DEFER_ASYNC_CALLBACK)
325
322
  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);
323
+
324
+ #if !defined(_WIN32)
325
+ if( pthread_atfork(NULL, NULL, after_fork_callback) ){
326
+ rb_warn("FFI: unable to register fork callback");
327
+ }
332
328
  #endif
329
+
333
330
  async_cb_thread = rb_thread_create(async_cb_event, NULL);
331
+ /* Name thread, for better debugging */
332
+ rb_funcall(async_cb_thread, rb_intern("name="), 1, rb_str_new2("FFI Callback Dispatcher"));
334
333
  }
335
-
336
334
  #endif
337
335
 
338
336
  fn->closure = rbffi_Closure_Alloc(fn->info->closurePool);
@@ -474,13 +472,13 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
474
472
  cb.frame = rbffi_frame_current();
475
473
 
476
474
  if (cb.frame != NULL) cb.frame->exc = Qnil;
477
- if (cb.frame != NULL && cb.frame->has_gvl) {
478
- callback_with_gvl(&cb);
479
475
 
480
- #if defined(HAVE_RB_THREAD_CALL_WITH_GVL)
481
- } else if (cb.frame != NULL) {
476
+ if (ruby_native_thread_p()) {
477
+ if(ruby_thread_has_gvl_p()) {
478
+ callback_with_gvl(&cb);
479
+ } else {
482
480
  rb_thread_call_with_gvl(callback_with_gvl, &cb);
483
- #endif
481
+ }
484
482
  #if defined(DEFER_ASYNC_CALLBACK) && !defined(_WIN32)
485
483
  } else {
486
484
  bool empty = false;
@@ -494,17 +492,8 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
494
492
  cb.next = async_cb_list;
495
493
  async_cb_list = &cb;
496
494
 
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
495
  pthread_cond_signal(&async_cb_cond);
506
496
  pthread_mutex_unlock(&async_cb_mutex);
507
- #endif
508
497
 
509
498
  /* Wait for the thread executing the ruby callback to signal it is done */
510
499
  pthread_mutex_lock(&cb.async_mutex);
@@ -528,15 +517,7 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
528
517
  async_cb_list = &cb;
529
518
  LeaveCriticalSection(&async_cb_lock);
530
519
 
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
520
  SetEvent(async_cb_cond);
539
- #endif
540
521
 
541
522
  /* Wait for the thread executing the ruby callback to signal it is done */
542
523
  WaitForSingleObject(cb.async_event, INFINITE);
@@ -554,7 +535,6 @@ struct async_wait {
554
535
  static void * async_cb_wait(void *);
555
536
  static void async_cb_stop(void *);
556
537
 
557
- #if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
558
538
  static VALUE
559
539
  async_cb_event(void* unused)
560
540
  {
@@ -562,82 +542,17 @@ async_cb_event(void* unused)
562
542
 
563
543
  w.stop = false;
564
544
  while (!w.stop) {
565
- #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
566
545
  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
546
  if (w.cb != NULL) {
571
547
  /* Start up a new ruby thread to run the ruby callback */
572
- rb_thread_create(async_cb_call, w.cb);
573
- }
574
- }
575
-
576
- return Qnil;
577
- }
578
-
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;
548
+ VALUE new_thread = rb_thread_create(async_cb_call, w.cb);
549
+ /* Name thread, for better debugging */
550
+ rb_funcall(new_thread, rb_intern("name="), 1, rb_str_new2("FFI Callback Runner"));
603
551
  }
604
552
  }
605
553
 
606
554
  return Qnil;
607
555
  }
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
556
 
642
557
  #ifdef _WIN32
643
558
  static void *
@@ -742,7 +657,7 @@ callback_with_gvl(void* data)
742
657
  }
743
658
 
744
659
  static VALUE
745
- invoke_callback(void* data)
660
+ invoke_callback(VALUE data)
746
661
  {
747
662
  struct gvl_callback* cb = (struct gvl_callback *) data;
748
663
 
@@ -805,10 +720,10 @@ invoke_callback(void* data)
805
720
  param = rb_float_new(*(double *) parameters[i]);
806
721
  break;
807
722
  case NATIVE_LONGDOUBLE:
808
- param = rbffi_longdouble_new(*(long double *) parameters[i]);
723
+ param = rbffi_longdouble_new(*(long double *) parameters[i]);
809
724
  break;
810
725
  case NATIVE_STRING:
811
- param = (*(void **) parameters[i] != NULL) ? rb_tainted_str_new2(*(char **) parameters[i]) : Qnil;
726
+ param = (*(void **) parameters[i] != NULL) ? rb_str_new2(*(char **) parameters[i]) : Qnil;
812
727
  break;
813
728
  case NATIVE_POINTER:
814
729
  param = rbffi_Pointer_NewInstance(*(void **) parameters[i]);
@@ -818,7 +733,6 @@ invoke_callback(void* data)
818
733
  break;
819
734
 
820
735
  case NATIVE_FUNCTION:
821
- case NATIVE_CALLBACK:
822
736
  case NATIVE_STRUCT:
823
737
  param = rbffi_NativeValue_ToRuby(paramType, rbParamType, parameters[i]);
824
738
  break;
@@ -877,6 +791,9 @@ invoke_callback(void* data)
877
791
  case NATIVE_FLOAT64:
878
792
  *((double *) retval) = NUM2DBL(rbReturnValue);
879
793
  break;
794
+ case NATIVE_LONGDOUBLE:
795
+ *((long double *) retval) = rbffi_num2longdouble(rbReturnValue);
796
+ break;
880
797
  case NATIVE_POINTER:
881
798
  if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_PointerClass)) {
882
799
  *((void **) retval) = ((AbstractMemory *) DATA_PTR(rbReturnValue))->address;
@@ -891,7 +808,6 @@ invoke_callback(void* data)
891
808
  break;
892
809
 
893
810
  case NATIVE_FUNCTION:
894
- case NATIVE_CALLBACK:
895
811
  if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_PointerClass)) {
896
812
 
897
813
  *((void **) retval) = ((AbstractMemory *) DATA_PTR(rbReturnValue))->address;
@@ -932,7 +848,7 @@ invoke_callback(void* data)
932
848
  }
933
849
 
934
850
  static VALUE
935
- save_callback_exception(void* data, VALUE exc)
851
+ save_callback_exception(VALUE data, VALUE exc)
936
852
  {
937
853
  struct gvl_callback* cb = (struct gvl_callback *) data;
938
854
 
@@ -948,9 +864,9 @@ callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errm
948
864
  FunctionType* fnInfo = (FunctionType *) ctx;
949
865
  ffi_status ffiStatus;
950
866
 
951
- ffiStatus = ffi_prep_closure(code, &fnInfo->ffi_cif, callback_invoke, closure);
867
+ ffiStatus = ffi_prep_closure_loc(closure->pcl, &fnInfo->ffi_cif, callback_invoke, closure, code);
952
868
  if (ffiStatus != FFI_OK) {
953
- snprintf(errmsg, errmsgsize, "ffi_prep_closure failed. status=%#x", ffiStatus);
869
+ snprintf(errmsg, errmsgsize, "ffi_prep_closure_loc failed. status=%#x", ffiStatus);
954
870
  return false;
955
871
  }
956
872
 
data/ext/ffi_c/Function.h CHANGED
@@ -34,11 +34,7 @@
34
34
  extern "C" {
35
35
  #endif
36
36
 
37
- #ifndef _MSC_VER
38
37
  # include <stdbool.h>
39
- #else
40
- # include "win32/stdbool.h"
41
- #endif
42
38
 
43
39
  #include <ffi.h>
44
40
 
@@ -33,12 +33,8 @@
33
33
  #include <sys/types.h>
34
34
  #include <stdio.h>
35
35
 
36
- #ifndef _MSC_VER
37
- # include <stdint.h>
38
- # include <stdbool.h>
39
- #else
40
- # include "win32/stdbool.h"
41
- #endif
36
+ #include <stdint.h>
37
+ #include <stdbool.h>
42
38
 
43
39
  #include <errno.h>
44
40
  #include <ruby.h>
@@ -172,7 +168,7 @@ fntype_initialize(int argc, VALUE* argv, VALUE self)
172
168
  VALUE typeName = rb_funcall2(rbReturnType, rb_intern("inspect"), 0, NULL);
173
169
  rb_raise(rb_eTypeError, "Invalid return type (%s)", RSTRING_PTR(typeName));
174
170
  }
175
-
171
+
176
172
  if (rb_obj_is_kind_of(fnInfo->rbReturnType, rbffi_StructByValueClass)) {
177
173
  fnInfo->hasStruct = true;
178
174
  }
@@ -180,7 +176,6 @@ fntype_initialize(int argc, VALUE* argv, VALUE self)
180
176
  Data_Get_Struct(fnInfo->rbReturnType, Type, fnInfo->returnType);
181
177
  fnInfo->ffiReturnType = fnInfo->returnType->ffiType;
182
178
 
183
-
184
179
  #if defined(X86_WIN32)
185
180
  rbConventionStr = (rbConvention != Qnil) ? rb_funcall2(rbConvention, rb_intern("to_s"), 0, NULL) : Qnil;
186
181
  fnInfo->abi = (rbConventionStr != Qnil && strcmp(StringValueCStr(rbConventionStr), "stdcall") == 0)
@@ -33,12 +33,8 @@
33
33
  #endif
34
34
  #include <sys/types.h>
35
35
  #include <stdio.h>
36
- #ifndef _MSC_VER
37
- # include <stdint.h>
38
- # include <stdbool.h>
39
- #else
40
- # include "win32/stdbool.h"
41
- #endif
36
+ #include <stdint.h>
37
+ #include <stdbool.h>
42
38
  #include <errno.h>
43
39
  #include <ruby.h>
44
40
 
@@ -49,8 +45,17 @@
49
45
  # define USE_PTHREAD_LOCAL
50
46
  #endif
51
47
 
48
+ #if defined(__CYGWIN__)
49
+ typedef uint32_t DWORD;
50
+ DWORD __stdcall GetLastError(void);
51
+ void __stdcall SetLastError(DWORD);
52
+ #endif
53
+
52
54
  typedef struct ThreadData {
53
55
  int td_errno;
56
+ #if defined(_WIN32) || defined(__CYGWIN__)
57
+ DWORD td_winapi_errno;
58
+ #endif
54
59
  } ThreadData;
55
60
 
56
61
  #if defined(USE_PTHREAD_LOCAL)
@@ -126,6 +131,19 @@ get_last_error(VALUE self)
126
131
  return INT2NUM(thread_data_get()->td_errno);
127
132
  }
128
133
 
134
+ #if defined(_WIN32) || defined(__CYGWIN__)
135
+ /*
136
+ * call-seq: winapi_error
137
+ * @return [Numeric]
138
+ * Get +GetLastError()+ value. Only Windows or Cygwin.
139
+ */
140
+ static VALUE
141
+ get_last_winapi_error(VALUE self)
142
+ {
143
+ return INT2NUM(thread_data_get()->td_winapi_errno);
144
+ }
145
+ #endif
146
+
129
147
 
130
148
  /*
131
149
  * call-seq: error(error)
@@ -146,22 +164,40 @@ set_last_error(VALUE self, VALUE error)
146
164
  return Qnil;
147
165
  }
148
166
 
167
+ #if defined(_WIN32) || defined(__CYGWIN__)
168
+ /*
169
+ * call-seq: error(error)
170
+ * @param [Numeric] error
171
+ * @return [nil]
172
+ * Set +GetLastError()+ value. Only on Windows and Cygwin.
173
+ */
174
+ static VALUE
175
+ set_last_winapi_error(VALUE self, VALUE error)
176
+ {
177
+ SetLastError(NUM2INT(error));
178
+ return Qnil;
179
+ }
180
+ #endif
181
+
149
182
 
150
183
  void
151
184
  rbffi_save_errno(void)
152
185
  {
153
186
  int error = 0;
154
-
155
187
  #ifdef _WIN32
156
188
  error = GetLastError();
157
189
  #else
158
190
  error = errno;
159
191
  #endif
160
192
 
193
+ #if defined(_WIN32) || defined(__CYGWIN__)
194
+ DWORD winapi_error = GetLastError();
195
+ thread_data_get()->td_winapi_errno = winapi_error;
196
+ #endif
197
+
161
198
  thread_data_get()->td_errno = error;
162
199
  }
163
200
 
164
-
165
201
  void
166
202
  rbffi_LastError_Init(VALUE moduleFFI)
167
203
  {
@@ -175,6 +211,11 @@ rbffi_LastError_Init(VALUE moduleFFI)
175
211
  rb_define_module_function(moduleError, "error", get_last_error, 0);
176
212
  rb_define_module_function(moduleError, "error=", set_last_error, 1);
177
213
 
214
+ #if defined(_WIN32) || defined(__CYGWIN__)
215
+ rb_define_module_function(moduleError, "winapi_error", get_last_winapi_error, 0);
216
+ rb_define_module_function(moduleError, "winapi_error=", set_last_winapi_error, 1);
217
+ #endif
218
+
178
219
  #if defined(USE_PTHREAD_LOCAL)
179
220
  pthread_key_create(&threadDataKey, thread_data_free);
180
221
  #else