ffi 1.10.0 → 1.15.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (349) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +240 -0
  3. data/Gemfile +3 -4
  4. data/README.md +42 -18
  5. data/Rakefile +68 -145
  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 +17 -50
  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 +2 -6
  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 +5 -56
  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 +56 -30
  39. data/ext/ffi_c/ffi.c +3 -8
  40. data/ext/ffi_c/libffi/.appveyor.yml +29 -13
  41. data/ext/ffi_c/libffi/.gitattributes +4 -0
  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/moxie-sim.exp +1 -1
  49. data/ext/ffi_c/libffi/.travis/or1k-sim.exp +58 -0
  50. data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +58 -0
  51. data/ext/ffi_c/libffi/.travis/site.exp +10 -1
  52. data/ext/ffi_c/libffi/.travis/wine-sim.exp +55 -0
  53. data/ext/ffi_c/libffi/.travis.yml +51 -2
  54. data/ext/ffi_c/libffi/{ChangeLog.libffi-3.1 → ChangeLog.old} +1407 -0
  55. data/ext/ffi_c/libffi/LICENSE +1 -1
  56. data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +5 -4
  57. data/ext/ffi_c/libffi/Makefile.am +56 -72
  58. data/ext/ffi_c/libffi/Makefile.in +458 -207
  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 +414 -342
  63. data/ext/ffi_c/libffi/configure.ac +37 -12
  64. data/ext/ffi_c/libffi/configure.host +56 -27
  65. data/ext/ffi_c/libffi/doc/Makefile.in +9 -5
  66. data/ext/ffi_c/libffi/doc/libffi.texi +26 -14
  67. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  68. data/ext/ffi_c/libffi/fficonfig.h.in +13 -0
  69. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +2 -4
  70. data/ext/ffi_c/libffi/include/Makefile.in +10 -6
  71. data/ext/ffi_c/libffi/include/ffi.h.in +19 -7
  72. data/ext/ffi_c/libffi/include/ffi_common.h +5 -1
  73. data/ext/ffi_c/libffi/install-sh +23 -13
  74. data/ext/ffi_c/libffi/libffi.map.in +8 -12
  75. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +2 -48
  76. data/ext/ffi_c/libffi/libtool-version +1 -1
  77. data/ext/ffi_c/libffi/ltmain.sh +156 -61
  78. data/ext/ffi_c/libffi/m4/asmcfi.m4 +1 -1
  79. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +5 -26
  80. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +5 -26
  81. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +2 -1
  82. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +5 -26
  83. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +7 -3
  84. data/ext/ffi_c/libffi/make_sunver.pl +333 -0
  85. data/ext/ffi_c/libffi/man/Makefile.in +9 -5
  86. data/ext/ffi_c/libffi/missing +8 -8
  87. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.sln +33 -0
  88. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj +130 -0
  89. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.filters +57 -0
  90. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user +4 -0
  91. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +511 -0
  92. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/fficonfig.h +219 -0
  93. data/ext/ffi_c/libffi/msvcc.sh +38 -13
  94. data/ext/ffi_c/libffi/src/aarch64/ffi.c +153 -69
  95. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +19 -3
  96. data/ext/ffi_c/libffi/src/aarch64/internal.h +1 -0
  97. data/ext/ffi_c/libffi/src/aarch64/sysv.S +22 -9
  98. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
  99. data/ext/ffi_c/libffi/src/arm/ffi.c +62 -5
  100. data/ext/ffi_c/libffi/src/arm/ffitarget.h +8 -1
  101. data/ext/ffi_c/libffi/src/arm/sysv.S +6 -4
  102. data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
  103. data/ext/ffi_c/libffi/src/closures.c +69 -14
  104. data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
  105. data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
  106. data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
  107. data/ext/ffi_c/libffi/src/dlmalloc.c +1 -1
  108. data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
  109. data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
  110. data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
  111. data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
  112. data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
  113. data/ext/ffi_c/libffi/src/metag/ffi.c +1 -1
  114. data/ext/ffi_c/libffi/src/mips/ffi.c +5 -1
  115. data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
  116. data/ext/ffi_c/libffi/src/mips/o32.S +2 -0
  117. data/ext/ffi_c/libffi/src/moxie/ffi.c +1 -1
  118. data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
  119. data/ext/ffi_c/libffi/src/pa/ffitarget.h +1 -6
  120. data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
  121. data/ext/ffi_c/libffi/src/pa/linux.S +27 -4
  122. data/ext/ffi_c/libffi/src/powerpc/ffi.c +6 -4
  123. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +13 -1
  124. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +211 -32
  125. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +18 -7
  126. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +10 -4
  127. data/ext/ffi_c/libffi/src/powerpc/linux64.S +91 -28
  128. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +81 -5
  129. data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
  130. data/ext/ffi_c/libffi/src/prep_cif.c +4 -2
  131. data/ext/ffi_c/libffi/src/riscv/ffi.c +42 -6
  132. data/ext/ffi_c/libffi/src/riscv/ffitarget.h +1 -0
  133. data/ext/ffi_c/libffi/src/riscv/sysv.S +86 -7
  134. data/ext/ffi_c/libffi/src/x86/ffi.c +29 -12
  135. data/ext/ffi_c/libffi/src/x86/ffi64.c +22 -11
  136. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
  137. data/ext/ffi_c/libffi/src/x86/ffiw64.c +20 -10
  138. data/ext/ffi_c/libffi/src/x86/sysv.S +105 -10
  139. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +995 -0
  140. data/ext/ffi_c/libffi/src/x86/unix64.S +100 -4
  141. data/ext/ffi_c/libffi/src/x86/win64.S +12 -3
  142. data/ext/ffi_c/libffi/src/x86/win64_intel.S +3 -2
  143. data/ext/ffi_c/libffi/testsuite/Makefile.am +114 -109
  144. data/ext/ffi_c/libffi/testsuite/Makefile.in +124 -84
  145. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +32 -8
  146. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +7 -2
  147. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +4 -4
  148. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2 -2
  149. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +12 -1
  150. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +9 -8
  151. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -1
  152. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure.exp +67 -0
  153. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +138 -0
  154. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/huge_struct.c +3 -1
  155. data/ext/ffi_c/libffi.darwin.mk +1 -1
  156. data/ext/ffi_c/rbffi.h +0 -2
  157. data/ffi.gemspec +13 -7
  158. data/lib/ffi/abstract_memory.rb +44 -0
  159. data/lib/ffi/autopointer.rb +1 -1
  160. data/lib/ffi/data_converter.rb +67 -0
  161. data/lib/ffi/ffi.rb +3 -0
  162. data/lib/ffi/io.rb +3 -3
  163. data/lib/ffi/library.rb +13 -9
  164. data/lib/ffi/managedstruct.rb +2 -2
  165. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  166. data/lib/ffi/platform/aarch64-freebsd/types.conf +89 -89
  167. data/lib/ffi/platform/aarch64-freebsd12/types.conf +162 -109
  168. data/lib/ffi/platform/aarch64-linux/types.conf +81 -81
  169. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  170. data/lib/ffi/platform/arm-freebsd/types.conf +87 -87
  171. data/lib/ffi/platform/arm-freebsd12/types.conf +87 -87
  172. data/lib/ffi/platform/arm-linux/types.conf +110 -82
  173. data/lib/ffi/platform/i386-cygwin/types.conf +1 -1
  174. data/lib/ffi/platform/i386-darwin/types.conf +63 -63
  175. data/lib/ffi/platform/i386-freebsd/types.conf +87 -87
  176. data/lib/ffi/platform/i386-freebsd12/types.conf +87 -87
  177. data/lib/ffi/platform/i386-gnu/types.conf +84 -84
  178. data/lib/ffi/platform/i386-linux/types.conf +77 -77
  179. data/lib/ffi/platform/i386-netbsd/types.conf +87 -87
  180. data/lib/ffi/platform/i386-openbsd/types.conf +89 -89
  181. data/lib/ffi/platform/i386-solaris/types.conf +96 -96
  182. data/lib/ffi/platform/i386-windows/types.conf +43 -96
  183. data/lib/ffi/platform/ia64-linux/types.conf +79 -79
  184. data/lib/ffi/platform/mips-linux/types.conf +79 -79
  185. data/lib/ffi/platform/mips64-linux/types.conf +81 -81
  186. data/lib/ffi/platform/mips64el-linux/types.conf +81 -81
  187. data/lib/ffi/platform/mipsel-linux/types.conf +79 -79
  188. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +79 -79
  189. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +79 -79
  190. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +81 -81
  191. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +81 -81
  192. data/lib/ffi/platform/powerpc-aix/types.conf +155 -155
  193. data/lib/ffi/platform/powerpc-darwin/types.conf +63 -63
  194. data/lib/ffi/platform/powerpc-linux/types.conf +108 -78
  195. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  196. data/lib/ffi/platform/powerpc64-linux/types.conf +81 -81
  197. data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
  198. data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
  199. data/lib/ffi/platform/s390-linux/types.conf +79 -79
  200. data/lib/ffi/platform/s390x-linux/types.conf +79 -79
  201. data/lib/ffi/platform/sparc-linux/types.conf +79 -79
  202. data/lib/ffi/platform/sparc-solaris/types.conf +103 -103
  203. data/lib/ffi/platform/sparc64-linux/types.conf +79 -79
  204. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  205. data/lib/ffi/platform/sparcv9-solaris/types.conf +103 -103
  206. data/lib/ffi/platform/x86_64-cygwin/types.conf +1 -1
  207. data/lib/ffi/platform/x86_64-darwin/types.conf +88 -84
  208. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
  209. data/lib/ffi/platform/x86_64-freebsd/types.conf +89 -89
  210. data/lib/ffi/platform/x86_64-freebsd12/types.conf +139 -109
  211. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  212. data/lib/ffi/platform/x86_64-linux/types.conf +107 -77
  213. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  214. data/lib/ffi/platform/x86_64-netbsd/types.conf +89 -89
  215. data/lib/ffi/platform/x86_64-openbsd/types.conf +86 -86
  216. data/lib/ffi/platform/x86_64-solaris/types.conf +96 -96
  217. data/lib/ffi/platform/x86_64-windows/types.conf +42 -110
  218. data/lib/ffi/platform.rb +24 -9
  219. data/lib/ffi/pointer.rb +22 -15
  220. data/lib/ffi/struct.rb +13 -68
  221. data/lib/ffi/struct_by_reference.rb +72 -0
  222. data/lib/ffi/struct_layout.rb +96 -0
  223. data/lib/ffi/tools/const_generator.rb +11 -8
  224. data/lib/ffi/tools/generator.rb +47 -2
  225. data/lib/ffi/tools/generator_task.rb +13 -17
  226. data/lib/ffi/tools/struct_generator.rb +6 -5
  227. data/lib/ffi/tools/types_generator.rb +7 -4
  228. data/lib/ffi/types.rb +1 -1
  229. data/lib/ffi/variadic.rb +1 -10
  230. data/lib/ffi/version.rb +1 -1
  231. data/lib/ffi.rb +10 -3
  232. data/rakelib/ffi_gem_helper.rb +65 -0
  233. data/samples/getlogin.rb +1 -1
  234. data/samples/getpid.rb +1 -1
  235. data/samples/gettimeofday.rb +8 -8
  236. data/samples/hello.rb +2 -1
  237. data/samples/inotify.rb +1 -1
  238. data/samples/pty.rb +1 -2
  239. data/samples/qsort.rb +0 -1
  240. metadata +157 -139
  241. data/.gitignore +0 -22
  242. data/.gitmodules +0 -3
  243. data/.travis.yml +0 -43
  244. data/.yardopts +0 -5
  245. data/appveyor.yml +0 -22
  246. data/ext/ffi_c/DataConverter.c +0 -91
  247. data/ext/ffi_c/StructByReference.c +0 -190
  248. data/ext/ffi_c/StructByReference.h +0 -50
  249. data/ext/ffi_c/libffi/ChangeLog.libffi +0 -584
  250. data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
  251. data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
  252. data/ext/ffi_c/win32/stdbool.h +0 -8
  253. data/ext/ffi_c/win32/stdint.h +0 -201
  254. data/samples/sample_helper.rb +0 -6
  255. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn0.c +0 -0
  256. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn1.c +0 -0
  257. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn2.c +0 -0
  258. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn3.c +0 -0
  259. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn4.c +0 -0
  260. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn5.c +0 -0
  261. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn6.c +0 -0
  262. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_loc_fn0.c +0 -0
  263. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_simple.c +0 -0
  264. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_12byte.c +0 -0
  265. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_16byte.c +0 -0
  266. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_18byte.c +0 -0
  267. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_19byte.c +0 -0
  268. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_1_1byte.c +0 -0
  269. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte.c +0 -0
  270. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte1.c +0 -0
  271. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_24byte.c +0 -0
  272. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_2byte.c +0 -0
  273. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3_1byte.c +0 -0
  274. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte1.c +0 -0
  275. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte2.c +0 -0
  276. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3float.c +0 -0
  277. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4_1byte.c +0 -0
  278. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4byte.c +0 -0
  279. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5_1_byte.c +0 -0
  280. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5byte.c +0 -0
  281. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_64byte.c +0 -0
  282. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6_1_byte.c +0 -0
  283. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6byte.c +0 -0
  284. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7_1_byte.c +0 -0
  285. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7byte.c +0 -0
  286. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_8byte.c +0 -0
  287. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte1.c +0 -0
  288. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte2.c +0 -0
  289. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_double.c +0 -0
  290. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_float.c +0 -0
  291. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble.c +0 -0
  292. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split.c +0 -0
  293. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split2.c +0 -0
  294. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_pointer.c +0 -0
  295. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint16.c +0 -0
  296. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint32.c +0 -0
  297. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint64.c +0 -0
  298. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint16.c +0 -0
  299. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint32.c +0 -0
  300. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint64.c +0 -0
  301. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_dbls_struct.c +0 -0
  302. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double.c +0 -0
  303. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double_va.c +0 -0
  304. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_float.c +0 -0
  305. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble.c +0 -0
  306. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble_va.c +0 -0
  307. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_args.c +0 -0
  308. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_float_double.c +0 -0
  309. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_schar.c +0 -0
  310. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshort.c +0 -0
  311. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshortchar.c +0 -0
  312. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_uchar.c +0 -0
  313. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushort.c +0 -0
  314. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushortchar.c +0 -0
  315. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer.c +0 -0
  316. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer_stack.c +0 -0
  317. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_schar.c +0 -0
  318. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sint.c +0 -0
  319. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sshort.c +0 -0
  320. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_struct_va1.c +0 -0
  321. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar.c +0 -0
  322. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar_va.c +0 -0
  323. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint.c +0 -0
  324. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint_va.c +0 -0
  325. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulong_va.c +0 -0
  326. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulonglong.c +0 -0
  327. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort.c +0 -0
  328. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort_va.c +0 -0
  329. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/err_bad_abi.c +0 -0
  330. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct.c +0 -0
  331. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct1.c +0 -0
  332. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct10.c +0 -0
  333. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct11.c +0 -0
  334. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct2.c +0 -0
  335. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct3.c +0 -0
  336. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct4.c +0 -0
  337. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct5.c +0 -0
  338. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct6.c +0 -0
  339. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct7.c +0 -0
  340. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct8.c +0 -0
  341. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct9.c +0 -0
  342. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/problem1.c +0 -0
  343. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large.c +0 -0
  344. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large2.c +0 -0
  345. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium.c +0 -0
  346. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium2.c +0 -0
  347. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/testclosure.c +0 -0
  348. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest.cc +0 -0
  349. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest_ffi_call.cc +0 -0
data/ext/ffi_c/Platform.c CHANGED
@@ -31,69 +31,19 @@
31
31
  # include <sys/param.h>
32
32
  #endif
33
33
  # include <sys/types.h>
34
- #ifndef _MSC_VER
35
- # include <stdint.h>
36
- # include <stdbool.h>
37
- #else
38
- # include "win32/stdint.h"
39
- # include "win32/stdbool.h"
40
- #endif
34
+ #include <stdint.h>
35
+ #include <stdbool.h>
41
36
  #include <ruby.h>
42
37
  #include <ctype.h>
43
38
  #include "rbffi_endian.h"
44
39
  #include "Platform.h"
45
40
 
46
- #if defined(__GNU__) || defined(__GLIBC__)
41
+ #if defined(__GNU__) || (defined(__GLIBC__) && !defined(__UCLIBC__))
47
42
  # include <gnu/lib-names.h>
48
43
  #endif
49
44
 
50
45
  static VALUE PlatformModule = Qnil;
51
46
 
52
- /*
53
- * Determine the cpu type at compile time - useful for MacOSX where the the
54
- * system installed ruby incorrectly reports 'host_cpu' as 'powerpc' when running
55
- * on intel.
56
- */
57
- #if defined(__x86_64__) || defined(__x86_64) || defined(__amd64) || defined(_M_X64) || defined(_M_AMD64)
58
- # define CPU "x86_64"
59
-
60
- #elif defined(__i386__) || defined(__i386) || defined(_M_IX86)
61
- # define CPU "i386"
62
-
63
- #elif defined(__ppc64__) || defined(__powerpc64__) || defined(_M_PPC)
64
- # define CPU "ppc64"
65
-
66
- #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc)
67
- # define CPU "ppc"
68
-
69
- /*
70
- * Need to check for __sparcv9 first, because __sparc will be defined either way.
71
- * Note that __sparcv9 seems to only be set for Solaris. On Linux, __sparc will
72
- * be set, along with __arch64__ if a 64-bit platform.
73
- */
74
- #elif defined(__sparcv9__) || defined(__sparcv9)
75
- # define CPU "sparcv9"
76
-
77
- #elif defined(__sparc__) || defined(__sparc)
78
- # if defined(__arch64__)
79
- # define CPU "sparcv9"
80
- # else
81
- # define CPU "sparc"
82
- # endif
83
-
84
- #elif defined(__arm__) || defined(__arm)
85
- # define CPU "arm"
86
-
87
- #elif defined(__mips__) || defined(__mips)
88
- # define CPU "mips"
89
-
90
- #elif defined(__s390__)
91
- # define CPU "s390"
92
-
93
- #else
94
- # define CPU "unknown"
95
- #endif
96
-
97
47
  static void
98
48
  export_primitive_types(VALUE module)
99
49
  {
@@ -109,6 +59,7 @@ export_primitive_types(VALUE module)
109
59
  S(LONG, long);
110
60
  S(FLOAT, float);
111
61
  S(DOUBLE, double);
62
+ S(LONG_DOUBLE, long double);
112
63
  S(ADDRESS, void*);
113
64
  #undef S
114
65
  }
@@ -120,10 +71,8 @@ rbffi_Platform_Init(VALUE moduleFFI)
120
71
  rb_define_const(PlatformModule, "BYTE_ORDER", INT2FIX(BYTE_ORDER));
121
72
  rb_define_const(PlatformModule, "LITTLE_ENDIAN", INT2FIX(LITTLE_ENDIAN));
122
73
  rb_define_const(PlatformModule, "BIG_ENDIAN", INT2FIX(BIG_ENDIAN));
123
- rb_define_const(PlatformModule, "CPU", rb_str_new2(CPU));
124
- #if defined(__GNU__) || defined(__GLIBC__)
74
+ #if defined(__GNU__) || (defined(__GLIBC__) && !defined(__UCLIBC__))
125
75
  rb_define_const(PlatformModule, "GNU_LIBC", rb_str_new2(LIBC_SO));
126
76
  #endif
127
77
  export_primitive_types(PlatformModule);
128
78
  }
129
-
data/ext/ffi_c/Pointer.c CHANGED
@@ -27,13 +27,8 @@
27
27
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
  */
29
29
 
30
- #ifndef _MSC_VER
31
- # include <stdint.h>
32
- # include <stdbool.h>
33
- #else
34
- # include "win32/stdint.h"
35
- # include "win32/stdbool.h"
36
- #endif
30
+ #include <stdint.h>
31
+ #include <stdbool.h>
37
32
  #include <limits.h>
38
33
  #include <ruby.h>
39
34
  #include "rbffi.h"
@@ -157,14 +152,14 @@ ptr_initialize_copy(VALUE self, VALUE other)
157
152
  {
158
153
  AbstractMemory* src;
159
154
  Pointer* dst;
160
-
155
+
161
156
  Data_Get_Struct(self, Pointer, dst);
162
157
  src = POINTER(other);
163
158
  if (src->size == LONG_MAX) {
164
159
  rb_raise(rb_eRuntimeError, "cannot duplicate unbounded memory area");
165
160
  return Qnil;
166
161
  }
167
-
162
+
168
163
  if ((dst->memory.flags & (MEM_RD | MEM_WR)) != (MEM_RD | MEM_WR)) {
169
164
  rb_raise(rb_eRuntimeError, "cannot duplicate unreadable/unwritable memory area");
170
165
  return Qnil;
@@ -180,13 +175,13 @@ ptr_initialize_copy(VALUE self, VALUE other)
180
175
  rb_raise(rb_eNoMemError, "failed to allocate memory size=%lu bytes", src->size);
181
176
  return Qnil;
182
177
  }
183
-
178
+
184
179
  dst->allocated = true;
185
180
  dst->autorelease = true;
186
- dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7UL);
181
+ dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7ULL);
187
182
  dst->memory.size = src->size;
188
183
  dst->memory.typeSize = src->typeSize;
189
-
184
+
190
185
  /* finally, copy the actual memory contents */
191
186
  memcpy(dst->memory.address, src->address, src->size);
192
187
 
@@ -199,7 +194,7 @@ slice(VALUE self, long offset, long size)
199
194
  AbstractMemory* ptr;
200
195
  Pointer* p;
201
196
  VALUE retval;
202
-
197
+
203
198
  Data_Get_Struct(self, AbstractMemory, ptr);
204
199
  checkBounds(ptr, offset, size == LONG_MAX ? 1 : size);
205
200
 
@@ -214,7 +209,7 @@ slice(VALUE self, long offset, long size)
214
209
  return retval;
215
210
  }
216
211
 
217
- /*
212
+ /*
218
213
  * Document-method: +
219
214
  * call-seq: ptr + offset
220
215
  * @param [Numeric] offset
@@ -237,7 +232,7 @@ ptr_plus(VALUE self, VALUE offset)
237
232
  * @param [Numeric] offset
238
233
  * @param [Numeric] length
239
234
  * @return [Pointer]
240
- * Return a new {Pointer} from an existing one. This pointer points on same contents
235
+ * Return a new {Pointer} from an existing one. This pointer points on same contents
241
236
  * from +offset+ for a length +length+.
242
237
  */
243
238
  static VALUE
@@ -256,7 +251,7 @@ ptr_inspect(VALUE self)
256
251
  {
257
252
  char buf[100];
258
253
  Pointer* ptr;
259
-
254
+
260
255
  Data_Get_Struct(self, Pointer, ptr);
261
256
 
262
257
  if (ptr->memory.size != LONG_MAX) {
@@ -295,7 +290,7 @@ static VALUE
295
290
  ptr_equals(VALUE self, VALUE other)
296
291
  {
297
292
  Pointer* ptr;
298
-
293
+
299
294
  Data_Get_Struct(self, Pointer, ptr);
300
295
 
301
296
  if (NIL_P(other)) {
@@ -314,7 +309,7 @@ static VALUE
314
309
  ptr_address(VALUE self)
315
310
  {
316
311
  Pointer* ptr;
317
-
312
+
318
313
  Data_Get_Struct(self, Pointer, ptr);
319
314
 
320
315
  return ULL2NUM((uintptr_t) ptr->memory.address);
@@ -331,9 +326,9 @@ ptr_address(VALUE self)
331
326
  * @overload order
332
327
  * @return [:big, :little] endianness of +self+
333
328
  * @overload order(order)
334
- * @param [Symbol] order endianness to set (+:little+, +:big+ or +:network+). +:big+ and +:network+
329
+ * @param [Symbol] order endianness to set (+:little+, +:big+ or +:network+). +:big+ and +:network+
335
330
  * are synonymous.
336
- * @return [self]
331
+ * @return a new pointer with the new order
337
332
  */
338
333
  static VALUE
339
334
  ptr_order(int argc, VALUE* argv, VALUE self)
@@ -358,6 +353,8 @@ ptr_order(int argc, VALUE* argv, VALUE self)
358
353
 
359
354
  } else if (id == rb_intern("big") || id == rb_intern("network")) {
360
355
  order = BIG_ENDIAN;
356
+ } else {
357
+ rb_raise(rb_eArgError, "unknown byte order");
361
358
  }
362
359
  }
363
360
  if (order != BYTE_ORDER) {
@@ -395,7 +392,7 @@ ptr_free(VALUE self)
395
392
 
396
393
  } else {
397
394
  VALUE caller = rb_funcall(rb_funcall(Qnil, rb_intern("caller"), 0), rb_intern("first"), 0);
398
-
395
+
399
396
  rb_warn("calling free on non allocated pointer %s from %s", RSTRING_PTR(ptr_inspect(self)), RSTRING_PTR(rb_str_to_str(caller)));
400
397
  }
401
398
 
@@ -408,7 +405,7 @@ ptr_type_size(VALUE self)
408
405
  Pointer* ptr;
409
406
 
410
407
  Data_Get_Struct(self, Pointer, ptr);
411
-
408
+
412
409
  return INT2NUM(ptr->memory.typeSize);
413
410
  }
414
411
 
@@ -440,7 +437,7 @@ ptr_autorelease_p(VALUE self)
440
437
  Pointer* ptr;
441
438
 
442
439
  Data_Get_Struct(self, Pointer, ptr);
443
-
440
+
444
441
  return ptr->autorelease ? Qtrue : Qfalse;
445
442
  }
446
443
 
@@ -472,9 +469,11 @@ rbffi_Pointer_Init(VALUE moduleFFI)
472
469
  * Pointer class is used to manage C pointers with ease. A {Pointer} object is defined by his
473
470
  * {#address} (as a C pointer). It permits additions with an integer for pointer arithmetic.
474
471
  *
475
- * ==Autorelease
476
- * A pointer object may autorelease his contents when freed (by default). This behaviour may be
477
- * changed with {#autorelease=} method.
472
+ * == Autorelease
473
+ * By default a pointer object frees its content when it's garbage collected.
474
+ * Therefore it's usually not necessary to call {#free} explicit.
475
+ * This behaviour may be changed with {#autorelease=} method.
476
+ * If it's set to +false+, the memory isn't freed by the garbage collector, but stays valid until +free()+ is called on C level or when the process terminates.
478
477
  */
479
478
  rbffi_PointerClass = rb_define_class_under(moduleFFI, "Pointer", ffi_AbstractMemory);
480
479
  /*
data/ext/ffi_c/Pointer.h CHANGED
@@ -30,11 +30,7 @@
30
30
  #ifndef RBFFI_POINTER_H
31
31
  #define RBFFI_POINTER_H
32
32
 
33
- #ifndef _MSC_VER
34
33
  # include <stdbool.h>
35
- #else
36
- # include "win32/stdbool.h"
37
- #endif
38
34
 
39
35
  #ifdef __cplusplus
40
36
  extern "C" {
data/ext/ffi_c/Struct.c CHANGED
@@ -31,12 +31,9 @@
31
31
  #include <sys/types.h>
32
32
  #ifndef _MSC_VER
33
33
  # include <sys/param.h>
34
- # include <stdint.h>
35
- # include <stdbool.h>
36
- #else
37
- # include "win32/stdbool.h"
38
- # include "win32/stdint.h"
39
34
  #endif
35
+ #include <stdint.h>
36
+ #include <stdbool.h>
40
37
  #include <ruby.h>
41
38
  #include "rbffi.h"
42
39
  #include "compat.h"
@@ -90,7 +87,7 @@ struct_allocate(VALUE klass)
90
87
  {
91
88
  Struct* s;
92
89
  VALUE obj = Data_Make_Struct(klass, Struct, struct_mark, struct_free, s);
93
-
90
+
94
91
  s->rbPointer = Qnil;
95
92
  s->rbLayout = Qnil;
96
93
 
@@ -112,7 +109,7 @@ struct_initialize(int argc, VALUE* argv, VALUE self)
112
109
  int nargs;
113
110
 
114
111
  Data_Get_Struct(self, Struct, s);
115
-
112
+
116
113
  nargs = rb_scan_args(argc, argv, "01*", &rbPointer, &rest);
117
114
 
118
115
  /* Call up into ruby code to adjust the layout */
@@ -127,7 +124,7 @@ struct_initialize(int argc, VALUE* argv, VALUE self)
127
124
  }
128
125
 
129
126
  Data_Get_Struct(s->rbLayout, StructLayout, s->layout);
130
-
127
+
131
128
  if (rbPointer != Qnil) {
132
129
  s->pointer = MEMORY(rbPointer);
133
130
  s->rbPointer = rbPointer;
@@ -148,16 +145,16 @@ struct_initialize_copy(VALUE self, VALUE other)
148
145
  {
149
146
  Struct* src;
150
147
  Struct* dst;
151
-
148
+
152
149
  Data_Get_Struct(self, Struct, dst);
153
150
  Data_Get_Struct(other, Struct, src);
154
151
  if (dst == src) {
155
152
  return self;
156
153
  }
157
-
154
+
158
155
  dst->rbLayout = src->rbLayout;
159
156
  dst->layout = src->layout;
160
-
157
+
161
158
  /*
162
159
  * A new MemoryPointer instance is allocated here instead of just calling
163
160
  * #dup on rbPointer, since the Pointer may not know its length, or may
@@ -176,7 +173,7 @@ struct_initialize_copy(VALUE self, VALUE other)
176
173
  dst->rbReferences = ALLOC_N(VALUE, dst->layout->referenceFieldCount);
177
174
  memcpy(dst->rbReferences, src->rbReferences, dst->layout->referenceFieldCount * sizeof(VALUE));
178
175
  }
179
-
176
+
180
177
  return self;
181
178
  }
182
179
 
@@ -279,24 +276,25 @@ store_reference_value(StructField* f, Struct* s, VALUE value)
279
276
  }
280
277
 
281
278
 
282
- static VALUE
279
+ static StructField *
283
280
  struct_field(Struct* s, VALUE fieldName)
284
281
  {
285
282
  StructLayout* layout = s->layout;
286
- VALUE rbField;
287
-
288
- if (likely(SYMBOL_P(fieldName) && st_lookup(layout->fieldSymbolTable, fieldName, (st_data_t *) &rbField))) {
289
- return rbField;
290
- }
291
-
292
- // TODO does this ever return anything?
293
- rbField = rb_hash_aref(layout->rbFieldMap, fieldName);
294
- if (rbField == Qnil) {
295
- VALUE str = rb_funcall2(fieldName, id_to_s, 0, NULL);
296
- rb_raise(rb_eArgError, "No such field '%s'", StringValuePtr(str));
283
+ struct field_cache_entry *p_ce = FIELD_CACHE_LOOKUP(layout, fieldName);
284
+
285
+ /* Do a hash lookup only if cache entry is empty or fieldName is unexpected? */
286
+ if (unlikely(!SYMBOL_P(fieldName) || !p_ce->fieldName || p_ce->fieldName != fieldName)) {
287
+ VALUE rbField = rb_hash_aref(layout->rbFieldMap, fieldName);
288
+ if (unlikely(NIL_P(rbField))) {
289
+ VALUE str = rb_funcall2(fieldName, id_to_s, 0, NULL);
290
+ rb_raise(rb_eArgError, "No such field '%s'", StringValueCStr(str));
291
+ }
292
+ /* Write the retrieved coder to the cache */
293
+ p_ce->fieldName = fieldName;
294
+ p_ce->field = (StructField *) DATA_PTR(rbField);
297
295
  }
298
296
 
299
- return rbField;
297
+ return p_ce->field;
300
298
  }
301
299
 
302
300
  /*
@@ -308,22 +306,19 @@ static VALUE
308
306
  struct_aref(VALUE self, VALUE fieldName)
309
307
  {
310
308
  Struct* s;
311
- VALUE rbField;
312
309
  StructField* f;
313
310
 
314
311
  s = struct_validate(self);
315
312
 
316
- rbField = struct_field(s, fieldName);
317
- f = (StructField *) DATA_PTR(rbField);
318
-
313
+ f = struct_field(s, fieldName);
319
314
  if (f->get != NULL) {
320
315
  return (*f->get)(f, s);
321
-
316
+
322
317
  } else if (f->memoryOp != NULL) {
323
318
  return (*f->memoryOp->get)(s->pointer, f->offset);
324
319
 
325
320
  } else {
326
-
321
+ VALUE rbField = rb_hash_aref(s->layout->rbFieldMap, fieldName);
327
322
  /* call up to the ruby code to fetch the value */
328
323
  return rb_funcall2(rbField, id_get, 1, &s->rbPointer);
329
324
  }
@@ -340,22 +335,20 @@ static VALUE
340
335
  struct_aset(VALUE self, VALUE fieldName, VALUE value)
341
336
  {
342
337
  Struct* s;
343
- VALUE rbField;
344
338
  StructField* f;
345
339
 
346
-
347
340
  s = struct_validate(self);
348
341
 
349
- rbField = struct_field(s, fieldName);
350
- f = (StructField *) DATA_PTR(rbField);
342
+ f = struct_field(s, fieldName);
351
343
  if (f->put != NULL) {
352
344
  (*f->put)(f, s, value);
353
345
 
354
346
  } else if (f->memoryOp != NULL) {
355
347
 
356
348
  (*f->memoryOp->put)(s->pointer, f->offset, value);
357
-
349
+
358
350
  } else {
351
+ VALUE rbField = rb_hash_aref(s->layout->rbFieldMap, fieldName);
359
352
  /* call up to the ruby code to set the value */
360
353
  VALUE argv[2];
361
354
  argv[0] = s->rbPointer;
@@ -366,7 +359,7 @@ struct_aset(VALUE self, VALUE fieldName, VALUE value)
366
359
  if (f->referenceRequired) {
367
360
  store_reference_value(f, s, value);
368
361
  }
369
-
362
+
370
363
  return value;
371
364
  }
372
365
 
@@ -389,7 +382,7 @@ struct_set_pointer(VALUE self, VALUE pointer)
389
382
  return Qnil;
390
383
  }
391
384
 
392
-
385
+
393
386
  Data_Get_Struct(self, Struct, s);
394
387
  Data_Get_Struct(pointer, AbstractMemory, memory);
395
388
  layout = struct_layout(self);
@@ -398,7 +391,7 @@ struct_set_pointer(VALUE self, VALUE pointer)
398
391
  rb_raise(rb_eArgError, "memory of %ld bytes too small for struct %s (expected at least %ld)",
399
392
  memory->size, rb_obj_classname(self), (long) layout->base.ffiType->size);
400
393
  }
401
-
394
+
402
395
  s->pointer = MEMORY(pointer);
403
396
  s->rbPointer = pointer;
404
397
  rb_ivar_set(self, id_pointer_ivar, pointer);
@@ -491,7 +484,7 @@ struct_order(int argc, VALUE* argv, VALUE self)
491
484
  VALUE retval = rb_obj_dup(self);
492
485
  VALUE rbPointer = rb_funcall2(s->rbPointer, rb_intern("order"), argc, argv);
493
486
  struct_set_pointer(retval, rbPointer);
494
-
487
+
495
488
  return retval;
496
489
  }
497
490
  }
@@ -527,7 +520,7 @@ static VALUE
527
520
  inline_array_initialize(VALUE self, VALUE rbMemory, VALUE rbField)
528
521
  {
529
522
  InlineArray* array;
530
-
523
+
531
524
  Data_Get_Struct(self, InlineArray, array);
532
525
  array->rbMemory = rbMemory;
533
526
  array->rbField = rbField;
@@ -536,12 +529,12 @@ inline_array_initialize(VALUE self, VALUE rbMemory, VALUE rbField)
536
529
  Data_Get_Struct(rbField, StructField, array->field);
537
530
  Data_Get_Struct(array->field->rbType, ArrayType, array->arrayType);
538
531
  Data_Get_Struct(array->arrayType->rbComponentType, Type, array->componentType);
539
-
532
+
540
533
  array->op = get_memory_op(array->componentType);
541
534
  if (array->op == NULL && array->componentType->nativeType == NATIVE_MAPPED) {
542
535
  array->op = get_memory_op(((MappedType *) array->componentType)->type);
543
536
  }
544
-
537
+
545
538
  array->length = array->arrayType->length;
546
539
 
547
540
  return self;
@@ -585,15 +578,15 @@ inline_array_aref(VALUE self, VALUE rbIndex)
585
578
  Data_Get_Struct(self, InlineArray, array);
586
579
 
587
580
  if (array->op != NULL) {
588
- VALUE rbNativeValue = array->op->get(array->memory,
581
+ VALUE rbNativeValue = array->op->get(array->memory,
589
582
  inline_array_offset(array, NUM2INT(rbIndex)));
590
583
  if (unlikely(array->componentType->nativeType == NATIVE_MAPPED)) {
591
- return rb_funcall(((MappedType *) array->componentType)->rbConverter,
584
+ return rb_funcall(((MappedType *) array->componentType)->rbConverter,
592
585
  rb_intern("from_native"), 2, rbNativeValue, Qnil);
593
586
  } else {
594
- return rbNativeValue;
587
+ return rbNativeValue;
595
588
  }
596
-
589
+
597
590
  } else if (array->componentType->nativeType == NATIVE_STRUCT) {
598
591
  VALUE rbOffset = INT2NUM(inline_array_offset(array, NUM2INT(rbIndex)));
599
592
  VALUE rbLength = INT2NUM(array->componentType->ffiType->size);
@@ -622,12 +615,12 @@ inline_array_aset(VALUE self, VALUE rbIndex, VALUE rbValue)
622
615
 
623
616
  if (array->op != NULL) {
624
617
  if (unlikely(array->componentType->nativeType == NATIVE_MAPPED)) {
625
- rbValue = rb_funcall(((MappedType *) array->componentType)->rbConverter,
618
+ rbValue = rb_funcall(((MappedType *) array->componentType)->rbConverter,
626
619
  rb_intern("to_native"), 2, rbValue, Qnil);
627
620
  }
628
621
  array->op->put(array->memory, inline_array_offset(array, NUM2INT(rbIndex)),
629
622
  rbValue);
630
-
623
+
631
624
  } else if (array->componentType->nativeType == NATIVE_STRUCT) {
632
625
  int offset = inline_array_offset(array, NUM2INT(rbIndex));
633
626
  Struct* s;
@@ -665,11 +658,11 @@ static VALUE
665
658
  inline_array_each(VALUE self)
666
659
  {
667
660
  InlineArray* array;
668
-
661
+
669
662
  int i;
670
663
 
671
664
  Data_Get_Struct(self, InlineArray, array);
672
-
665
+
673
666
  for (i = 0; i < array->length; ++i) {
674
667
  rb_yield(inline_array_aref(self, INT2FIX(i)));
675
668
  }
@@ -692,7 +685,7 @@ inline_array_to_a(VALUE self)
692
685
  Data_Get_Struct(self, InlineArray, array);
693
686
  obj = rb_ary_new2(array->length);
694
687
 
695
-
688
+
696
689
  for (i = 0; i < array->length; ++i) {
697
690
  rb_ary_push(obj, inline_array_aref(self, INT2FIX(i)));
698
691
  }
@@ -713,7 +706,7 @@ inline_array_to_s(VALUE self)
713
706
  VALUE argv[2];
714
707
 
715
708
  Data_Get_Struct(self, InlineArray, array);
716
-
709
+
717
710
  if (array->componentType->nativeType != NATIVE_INT8 && array->componentType->nativeType != NATIVE_UINT8) {
718
711
  VALUE dummy = Qnil;
719
712
  return rb_call_super(0, &dummy);
@@ -734,7 +727,7 @@ static VALUE
734
727
  inline_array_to_ptr(VALUE self)
735
728
  {
736
729
  InlineArray* array;
737
-
730
+
738
731
  Data_Get_Struct(self, InlineArray, array);
739
732
 
740
733
  return rb_funcall(array->rbMemory, rb_intern("slice"), 2,
@@ -778,7 +771,7 @@ rbffi_Struct_Init(VALUE moduleFFI)
778
771
  /*
779
772
  * Document-class: FFI::StructLayout::CharArray < FFI::Struct::InlineArray
780
773
  */
781
- rbffi_StructLayoutCharArrayClass = rb_define_class_under(rbffi_StructLayoutClass, "CharArray",
774
+ rbffi_StructLayoutCharArrayClass = rb_define_class_under(rbffi_StructLayoutClass, "CharArray",
782
775
  rbffi_StructInlineArrayClass);
783
776
  rb_global_variable(&rbffi_StructLayoutCharArrayClass);
784
777
 
@@ -787,7 +780,7 @@ rbffi_Struct_Init(VALUE moduleFFI)
787
780
  rb_define_method(StructClass, "initialize", struct_initialize, -1);
788
781
  rb_define_method(StructClass, "initialize_copy", struct_initialize_copy, 1);
789
782
  rb_define_method(StructClass, "order", struct_order, -1);
790
-
783
+
791
784
  rb_define_alias(rb_singleton_class(StructClass), "alloc_in", "new");
792
785
  rb_define_alias(rb_singleton_class(StructClass), "alloc_out", "new");
793
786
  rb_define_alias(rb_singleton_class(StructClass), "alloc_inout", "new");
data/ext/ffi_c/Struct.h CHANGED
@@ -34,11 +34,7 @@
34
34
  #include "extconf.h"
35
35
  #include "AbstractMemory.h"
36
36
  #include "Type.h"
37
- #ifdef RUBY_1_9
38
37
  #include <ruby/st.h>
39
- #else
40
- #include <st.h>
41
- #endif
42
38
 
43
39
  #ifdef __cplusplus
44
40
  extern "C" {
@@ -73,11 +69,21 @@ extern "C" {
73
69
  int size;
74
70
  int align;
75
71
  ffi_type** ffiTypes;
76
- struct st_table* fieldSymbolTable;
72
+
73
+ /*
74
+ * We use the fieldName's minor 8 Bits as index to a 256 entry cache.
75
+ * This avoids full ruby hash lookups for repeated lookups.
76
+ */
77
+ #define FIELD_CACHE_LOOKUP(this, sym) ( &(this)->cache_row[((sym) >> 8) & 0xff] )
78
+
79
+ struct field_cache_entry {
80
+ VALUE fieldName;
81
+ StructField *field;
82
+ } cache_row[0x100];
77
83
 
78
84
  /** The number of reference tracking fields in this struct */
79
85
  int referenceFieldCount;
80
-
86
+
81
87
  VALUE rbFieldNames;
82
88
  VALUE rbFieldMap;
83
89
  VALUE rbFields;
@@ -32,13 +32,8 @@
32
32
  #endif
33
33
  #include <sys/types.h>
34
34
  #include <stdio.h>
35
- #ifndef _MSC_VER
36
- # include <stdint.h>
37
- # include <stdbool.h>
38
- #else
39
- # include "win32/stdbool.h"
40
- # include "win32/stdint.h"
41
- #endif
35
+ #include <stdint.h>
36
+ #include <stdbool.h>
42
37
  #include <errno.h>
43
38
  #include <ruby.h>
44
39