ffi 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (530) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.gitmodules +4 -0
  4. data/.travis.yml +42 -0
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +131 -0
  7. data/COPYING +49 -0
  8. data/Gemfile +15 -0
  9. data/LICENSE +24 -0
  10. data/LICENSE.SPECS +22 -0
  11. data/README.md +115 -0
  12. data/Rakefile +195 -0
  13. data/appveyor.yml +27 -0
  14. data/ext/ffi_c/AbstractMemory.c +1109 -0
  15. data/ext/ffi_c/AbstractMemory.h +175 -0
  16. data/ext/ffi_c/ArrayType.c +162 -0
  17. data/ext/ffi_c/ArrayType.h +59 -0
  18. data/ext/ffi_c/Buffer.c +365 -0
  19. data/ext/ffi_c/Call.c +503 -0
  20. data/ext/ffi_c/Call.h +107 -0
  21. data/ext/ffi_c/ClosurePool.c +283 -0
  22. data/ext/ffi_c/ClosurePool.h +57 -0
  23. data/ext/ffi_c/DynamicLibrary.c +339 -0
  24. data/ext/ffi_c/DynamicLibrary.h +98 -0
  25. data/ext/ffi_c/Function.c +917 -0
  26. data/ext/ffi_c/Function.h +87 -0
  27. data/ext/ffi_c/FunctionInfo.c +271 -0
  28. data/ext/ffi_c/LastError.c +229 -0
  29. data/ext/ffi_c/LastError.h +47 -0
  30. data/ext/ffi_c/LongDouble.c +63 -0
  31. data/ext/ffi_c/LongDouble.h +51 -0
  32. data/ext/ffi_c/MappedType.c +168 -0
  33. data/ext/ffi_c/MappedType.h +59 -0
  34. data/ext/ffi_c/MemoryPointer.c +197 -0
  35. data/ext/ffi_c/MemoryPointer.h +53 -0
  36. data/ext/ffi_c/MethodHandle.c +358 -0
  37. data/ext/ffi_c/MethodHandle.h +55 -0
  38. data/ext/ffi_c/Platform.c +82 -0
  39. data/ext/ffi_c/Platform.h +45 -0
  40. data/ext/ffi_c/Pointer.c +508 -0
  41. data/ext/ffi_c/Pointer.h +63 -0
  42. data/ext/ffi_c/Struct.c +829 -0
  43. data/ext/ffi_c/Struct.h +106 -0
  44. data/ext/ffi_c/StructByValue.c +150 -0
  45. data/ext/ffi_c/StructByValue.h +55 -0
  46. data/ext/ffi_c/StructLayout.c +698 -0
  47. data/ext/ffi_c/Thread.c +137 -0
  48. data/ext/ffi_c/Thread.h +84 -0
  49. data/ext/ffi_c/Type.c +379 -0
  50. data/ext/ffi_c/Type.h +61 -0
  51. data/ext/ffi_c/Types.c +139 -0
  52. data/ext/ffi_c/Types.h +89 -0
  53. data/ext/ffi_c/Variadic.c +298 -0
  54. data/ext/ffi_c/compat.h +78 -0
  55. data/ext/ffi_c/extconf.rb +86 -0
  56. data/ext/ffi_c/ffi.c +93 -0
  57. data/ext/ffi_c/libffi.bsd.mk +40 -0
  58. data/ext/ffi_c/libffi.darwin.mk +105 -0
  59. data/ext/ffi_c/libffi.gnu.mk +32 -0
  60. data/ext/ffi_c/libffi.mk +18 -0
  61. data/ext/ffi_c/libffi.vc.mk +26 -0
  62. data/ext/ffi_c/libffi.vc64.mk +26 -0
  63. data/ext/ffi_c/libffi/.appveyor.yml +50 -0
  64. data/ext/ffi_c/libffi/.github/issue_template.md +10 -0
  65. data/ext/ffi_c/libffi/.gitignore +38 -0
  66. data/ext/ffi_c/libffi/.travis.yml +34 -0
  67. data/ext/ffi_c/libffi/.travis/ar-lib +270 -0
  68. data/ext/ffi_c/libffi/.travis/build.sh +34 -0
  69. data/ext/ffi_c/libffi/.travis/compile +351 -0
  70. data/ext/ffi_c/libffi/.travis/install.sh +22 -0
  71. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +60 -0
  72. data/ext/ffi_c/libffi/.travis/site.exp +18 -0
  73. data/ext/ffi_c/libffi/ChangeLog.libffi +584 -0
  74. data/ext/ffi_c/libffi/ChangeLog.libffi-3.1 +6000 -0
  75. data/ext/ffi_c/libffi/ChangeLog.libgcj +40 -0
  76. data/ext/ffi_c/libffi/ChangeLog.v1 +764 -0
  77. data/ext/ffi_c/libffi/LICENSE +21 -0
  78. data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +352 -0
  79. data/ext/ffi_c/libffi/Makefile.am +166 -0
  80. data/ext/ffi_c/libffi/README.md +461 -0
  81. data/ext/ffi_c/libffi/acinclude.m4 +479 -0
  82. data/ext/ffi_c/libffi/autogen.sh +2 -0
  83. data/ext/ffi_c/libffi/config.guess +1466 -0
  84. data/ext/ffi_c/libffi/config.sub +1836 -0
  85. data/ext/ffi_c/libffi/configure.ac +394 -0
  86. data/ext/ffi_c/libffi/configure.host +289 -0
  87. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +203 -0
  88. data/ext/ffi_c/libffi/include/Makefile.am +9 -0
  89. data/ext/ffi_c/libffi/include/ffi.h.in +511 -0
  90. data/ext/ffi_c/libffi/include/ffi_cfi.h +55 -0
  91. data/ext/ffi_c/libffi/include/ffi_common.h +149 -0
  92. data/ext/ffi_c/libffi/libffi.map.in +80 -0
  93. data/ext/ffi_c/libffi/libffi.pc.in +11 -0
  94. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +1043 -0
  95. data/ext/ffi_c/libffi/libtool-version +29 -0
  96. data/ext/ffi_c/libffi/m4/asmcfi.m4 +13 -0
  97. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +71 -0
  98. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +194 -0
  99. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +122 -0
  100. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +74 -0
  101. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +87 -0
  102. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
  103. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +302 -0
  104. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +263 -0
  105. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +89 -0
  106. data/ext/ffi_c/libffi/m4/ax_require_defined.m4 +37 -0
  107. data/ext/ffi_c/libffi/man/Makefile.am +8 -0
  108. data/ext/ffi_c/libffi/man/ffi.3 +41 -0
  109. data/ext/ffi_c/libffi/man/ffi_call.3 +103 -0
  110. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +68 -0
  111. data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +73 -0
  112. data/ext/ffi_c/libffi/msvcc.sh +328 -0
  113. data/ext/ffi_c/libffi/src/aarch64/ffi.c +941 -0
  114. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +81 -0
  115. data/ext/ffi_c/libffi/src/aarch64/internal.h +67 -0
  116. data/ext/ffi_c/libffi/src/aarch64/sysv.S +438 -0
  117. data/ext/ffi_c/libffi/src/alpha/ffi.c +521 -0
  118. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +57 -0
  119. data/ext/ffi_c/libffi/src/alpha/internal.h +23 -0
  120. data/ext/ffi_c/libffi/src/alpha/osf.S +282 -0
  121. data/ext/ffi_c/libffi/src/arc/arcompact.S +135 -0
  122. data/ext/ffi_c/libffi/src/arc/ffi.c +266 -0
  123. data/ext/ffi_c/libffi/src/arc/ffitarget.h +53 -0
  124. data/ext/ffi_c/libffi/src/arm/ffi.c +819 -0
  125. data/ext/ffi_c/libffi/src/arm/ffitarget.h +82 -0
  126. data/ext/ffi_c/libffi/src/arm/internal.h +7 -0
  127. data/ext/ffi_c/libffi/src/arm/sysv.S +383 -0
  128. data/ext/ffi_c/libffi/src/avr32/ffi.c +423 -0
  129. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +55 -0
  130. data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
  131. data/ext/ffi_c/libffi/src/bfin/ffi.c +196 -0
  132. data/ext/ffi_c/libffi/src/bfin/ffitarget.h +43 -0
  133. data/ext/ffi_c/libffi/src/bfin/sysv.S +179 -0
  134. data/ext/ffi_c/libffi/src/closures.c +966 -0
  135. data/ext/ffi_c/libffi/src/cris/ffi.c +386 -0
  136. data/ext/ffi_c/libffi/src/cris/ffitarget.h +56 -0
  137. data/ext/ffi_c/libffi/src/cris/sysv.S +215 -0
  138. data/ext/ffi_c/libffi/src/debug.c +64 -0
  139. data/ext/ffi_c/libffi/src/dlmalloc.c +5166 -0
  140. data/ext/ffi_c/libffi/src/frv/eabi.S +128 -0
  141. data/ext/ffi_c/libffi/src/frv/ffi.c +292 -0
  142. data/ext/ffi_c/libffi/src/frv/ffitarget.h +62 -0
  143. data/ext/ffi_c/libffi/src/ia64/ffi.c +604 -0
  144. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +56 -0
  145. data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +40 -0
  146. data/ext/ffi_c/libffi/src/ia64/unix.S +567 -0
  147. data/ext/ffi_c/libffi/src/java_raw_api.c +374 -0
  148. data/ext/ffi_c/libffi/src/m32r/ffi.c +232 -0
  149. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +53 -0
  150. data/ext/ffi_c/libffi/src/m32r/sysv.S +121 -0
  151. data/ext/ffi_c/libffi/src/m68k/ffi.c +362 -0
  152. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +54 -0
  153. data/ext/ffi_c/libffi/src/m68k/sysv.S +357 -0
  154. data/ext/ffi_c/libffi/src/m88k/ffi.c +400 -0
  155. data/ext/ffi_c/libffi/src/m88k/ffitarget.h +49 -0
  156. data/ext/ffi_c/libffi/src/m88k/obsd.S +209 -0
  157. data/ext/ffi_c/libffi/src/metag/ffi.c +330 -0
  158. data/ext/ffi_c/libffi/src/metag/ffitarget.h +53 -0
  159. data/ext/ffi_c/libffi/src/metag/sysv.S +311 -0
  160. data/ext/ffi_c/libffi/src/microblaze/ffi.c +321 -0
  161. data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +53 -0
  162. data/ext/ffi_c/libffi/src/microblaze/sysv.S +302 -0
  163. data/ext/ffi_c/libffi/src/mips/ffi.c +1130 -0
  164. data/ext/ffi_c/libffi/src/mips/ffitarget.h +244 -0
  165. data/ext/ffi_c/libffi/src/mips/n32.S +663 -0
  166. data/ext/ffi_c/libffi/src/mips/o32.S +502 -0
  167. data/ext/ffi_c/libffi/src/moxie/eabi.S +101 -0
  168. data/ext/ffi_c/libffi/src/moxie/ffi.c +285 -0
  169. data/ext/ffi_c/libffi/src/moxie/ffitarget.h +52 -0
  170. data/ext/ffi_c/libffi/src/nios2/ffi.c +304 -0
  171. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +52 -0
  172. data/ext/ffi_c/libffi/src/nios2/sysv.S +136 -0
  173. data/ext/ffi_c/libffi/src/or1k/ffi.c +328 -0
  174. data/ext/ffi_c/libffi/src/or1k/ffitarget.h +58 -0
  175. data/ext/ffi_c/libffi/src/or1k/sysv.S +107 -0
  176. data/ext/ffi_c/libffi/src/pa/ffi.c +719 -0
  177. data/ext/ffi_c/libffi/src/pa/ffitarget.h +85 -0
  178. data/ext/ffi_c/libffi/src/pa/hpux32.S +368 -0
  179. data/ext/ffi_c/libffi/src/pa/linux.S +357 -0
  180. data/ext/ffi_c/libffi/src/powerpc/aix.S +566 -0
  181. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +694 -0
  182. data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
  183. data/ext/ffi_c/libffi/src/powerpc/darwin.S +378 -0
  184. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +571 -0
  185. data/ext/ffi_c/libffi/src/powerpc/ffi.c +173 -0
  186. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +1440 -0
  187. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +974 -0
  188. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +94 -0
  189. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +923 -0
  190. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +198 -0
  191. data/ext/ffi_c/libffi/src/powerpc/linux64.S +228 -0
  192. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +488 -0
  193. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +397 -0
  194. data/ext/ffi_c/libffi/src/powerpc/sysv.S +175 -0
  195. data/ext/ffi_c/libffi/src/prep_cif.c +261 -0
  196. data/ext/ffi_c/libffi/src/raw_api.c +267 -0
  197. data/ext/ffi_c/libffi/src/riscv/ffi.c +481 -0
  198. data/ext/ffi_c/libffi/src/riscv/ffitarget.h +69 -0
  199. data/ext/ffi_c/libffi/src/riscv/sysv.S +293 -0
  200. data/ext/ffi_c/libffi/src/s390/ffi.c +756 -0
  201. data/ext/ffi_c/libffi/src/s390/ffitarget.h +70 -0
  202. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  203. data/ext/ffi_c/libffi/src/s390/sysv.S +325 -0
  204. data/ext/ffi_c/libffi/src/sh/ffi.c +717 -0
  205. data/ext/ffi_c/libffi/src/sh/ffitarget.h +54 -0
  206. data/ext/ffi_c/libffi/src/sh/sysv.S +850 -0
  207. data/ext/ffi_c/libffi/src/sh64/ffi.c +469 -0
  208. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +58 -0
  209. data/ext/ffi_c/libffi/src/sh64/sysv.S +539 -0
  210. data/ext/ffi_c/libffi/src/sparc/ffi.c +468 -0
  211. data/ext/ffi_c/libffi/src/sparc/ffi64.c +608 -0
  212. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +81 -0
  213. data/ext/ffi_c/libffi/src/sparc/internal.h +26 -0
  214. data/ext/ffi_c/libffi/src/sparc/v8.S +443 -0
  215. data/ext/ffi_c/libffi/src/sparc/v9.S +440 -0
  216. data/ext/ffi_c/libffi/src/tile/ffi.c +355 -0
  217. data/ext/ffi_c/libffi/src/tile/ffitarget.h +65 -0
  218. data/ext/ffi_c/libffi/src/tile/tile.S +360 -0
  219. data/ext/ffi_c/libffi/src/types.c +108 -0
  220. data/ext/ffi_c/libffi/src/vax/elfbsd.S +195 -0
  221. data/ext/ffi_c/libffi/src/vax/ffi.c +276 -0
  222. data/ext/ffi_c/libffi/src/vax/ffitarget.h +49 -0
  223. data/ext/ffi_c/libffi/src/x86/asmnames.h +30 -0
  224. data/ext/ffi_c/libffi/src/x86/ffi.c +754 -0
  225. data/ext/ffi_c/libffi/src/x86/ffi64.c +884 -0
  226. data/ext/ffi_c/libffi/src/x86/ffitarget.h +147 -0
  227. data/ext/ffi_c/libffi/src/x86/ffiw64.c +308 -0
  228. data/ext/ffi_c/libffi/src/x86/internal.h +29 -0
  229. data/ext/ffi_c/libffi/src/x86/internal64.h +22 -0
  230. data/ext/ffi_c/libffi/src/x86/sysv.S +1129 -0
  231. data/ext/ffi_c/libffi/src/x86/unix64.S +566 -0
  232. data/ext/ffi_c/libffi/src/x86/win64.S +232 -0
  233. data/ext/ffi_c/libffi/src/x86/win64_intel.S +237 -0
  234. data/ext/ffi_c/libffi/src/xtensa/ffi.c +298 -0
  235. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +53 -0
  236. data/ext/ffi_c/libffi/src/xtensa/sysv.S +258 -0
  237. data/ext/ffi_c/libffi/stamp-h.in +1 -0
  238. data/ext/ffi_c/libffi/testsuite/Makefile.am +117 -0
  239. data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
  240. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +636 -0
  241. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +283 -0
  242. data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +45 -0
  243. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/Makefile +28 -0
  244. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/README +78 -0
  245. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/alignof.h +50 -0
  246. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +58 -0
  247. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1745 -0
  248. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2885 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +743 -0
  250. data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +46 -0
  251. data/ext/ffi_c/libffi/testsuite/libffi.call/align_stdcall.c +46 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +43 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +89 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +81 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +81 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +82 -0
  257. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +89 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +92 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +90 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_simple.c +55 -0
  262. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +94 -0
  263. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +95 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +96 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +102 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +89 -0
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +91 -0
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +93 -0
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +113 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +90 -0
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +95 -0
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +90 -0
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +90 -0
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3float.c +95 -0
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +98 -0
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +90 -0
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +109 -0
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +98 -0
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +124 -0
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +113 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +99 -0
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +117 -0
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +97 -0
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +88 -0
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +90 -0
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +91 -0
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +93 -0
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +91 -0
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +92 -0
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +132 -0
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +115 -0
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +95 -0
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +91 -0
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +91 -0
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +92 -0
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +91 -0
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +91 -0
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +93 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +43 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +61 -0
  302. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +42 -0
  303. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
  304. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +61 -0
  305. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_args.c +70 -0
  306. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_float_double.c +55 -0
  307. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +74 -0
  308. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +74 -0
  309. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +86 -0
  310. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +91 -0
  311. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +74 -0
  312. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +86 -0
  313. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
  314. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +142 -0
  315. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +44 -0
  316. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +42 -0
  317. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +42 -0
  318. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_struct_va1.c +114 -0
  319. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +42 -0
  320. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar_va.c +44 -0
  321. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +43 -0
  322. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint_va.c +45 -0
  323. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulong_va.c +45 -0
  324. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +47 -0
  325. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +43 -0
  326. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort_va.c +44 -0
  327. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +36 -0
  328. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +26 -0
  329. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +138 -0
  330. data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +59 -0
  331. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +60 -0
  332. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +60 -0
  333. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +74 -0
  334. data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +62 -0
  335. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +107 -0
  336. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +341 -0
  337. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +59 -0
  338. data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +57 -0
  339. data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +70 -0
  340. data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +78 -0
  341. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +52 -0
  342. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +152 -0
  343. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +161 -0
  344. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +134 -0
  345. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct11.c +121 -0
  346. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +110 -0
  347. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +111 -0
  348. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +111 -0
  349. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +112 -0
  350. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +131 -0
  351. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +111 -0
  352. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +131 -0
  353. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +131 -0
  354. data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +46 -0
  355. data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +127 -0
  356. data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +90 -0
  357. data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +59 -0
  358. data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +114 -0
  359. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +36 -0
  360. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +43 -0
  361. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +42 -0
  362. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +35 -0
  363. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +36 -0
  364. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +49 -0
  365. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +42 -0
  366. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +34 -0
  367. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +41 -0
  368. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +43 -0
  369. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +36 -0
  370. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +38 -0
  371. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +38 -0
  372. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +38 -0
  373. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
  374. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
  375. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
  376. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +125 -0
  377. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +44 -0
  378. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +49 -0
  379. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +49 -0
  380. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +55 -0
  381. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +67 -0
  382. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +57 -0
  383. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +67 -0
  384. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +60 -0
  385. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +64 -0
  386. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +66 -0
  387. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +64 -0
  388. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +74 -0
  389. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +81 -0
  390. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +68 -0
  391. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
  392. data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +61 -0
  393. data/ext/ffi_c/libffi/testsuite/libffi.call/unwindtest.cc +117 -0
  394. data/ext/ffi_c/libffi/testsuite/libffi.call/unwindtest_ffi_call.cc +54 -0
  395. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +196 -0
  396. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +121 -0
  397. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +123 -0
  398. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +125 -0
  399. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +91 -0
  400. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +10 -0
  401. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +10 -0
  402. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +10 -0
  403. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +42 -0
  404. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +10 -0
  405. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +10 -0
  406. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +10 -0
  407. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +71 -0
  408. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +10 -0
  409. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +10 -0
  410. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +10 -0
  411. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +80 -0
  412. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +10 -0
  413. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +16 -0
  414. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +10 -0
  415. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.exp +36 -0
  416. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +51 -0
  417. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +7 -0
  418. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +7 -0
  419. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +7 -0
  420. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +10 -0
  421. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +10 -0
  422. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +86 -0
  423. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +10 -0
  424. data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +1 -0
  425. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +78 -0
  426. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +10 -0
  427. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +10 -0
  428. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +10 -0
  429. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +37 -0
  430. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +41 -0
  431. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +10 -0
  432. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +10 -0
  433. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +10 -0
  434. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +44 -0
  435. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +10 -0
  436. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +10 -0
  437. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +10 -0
  438. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +10 -0
  439. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +10 -0
  440. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +10 -0
  441. data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +34 -0
  442. data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +28 -0
  443. data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +1 -0
  444. data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +36 -0
  445. data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +19 -0
  446. data/ext/ffi_c/rbffi.h +55 -0
  447. data/ext/ffi_c/rbffi_endian.h +59 -0
  448. data/ext/ffi_c/win32/stdbool.h +8 -0
  449. data/ext/ffi_c/win32/stdint.h +201 -0
  450. data/ffi.gemspec +43 -0
  451. data/lib/ffi.rb +20 -0
  452. data/lib/ffi/autopointer.rb +203 -0
  453. data/lib/ffi/buffer.rb +4 -0
  454. data/lib/ffi/callback.rb +4 -0
  455. data/lib/ffi/data_converter.rb +67 -0
  456. data/lib/ffi/enum.rb +296 -0
  457. data/lib/ffi/errno.rb +43 -0
  458. data/lib/ffi/ffi.rb +45 -0
  459. data/lib/ffi/io.rb +62 -0
  460. data/lib/ffi/library.rb +588 -0
  461. data/lib/ffi/managedstruct.rb +84 -0
  462. data/lib/ffi/memorypointer.rb +1 -0
  463. data/lib/ffi/platform.rb +172 -0
  464. data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
  465. data/lib/ffi/platform/aarch64-freebsd12/types.conf +128 -0
  466. data/lib/ffi/platform/aarch64-linux/types.conf +104 -0
  467. data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
  468. data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
  469. data/lib/ffi/platform/arm-linux/types.conf +104 -0
  470. data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  471. data/lib/ffi/platform/i386-darwin/types.conf +100 -0
  472. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  473. data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
  474. data/lib/ffi/platform/i386-gnu/types.conf +107 -0
  475. data/lib/ffi/platform/i386-linux/types.conf +103 -0
  476. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  477. data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
  478. data/lib/ffi/platform/i386-solaris/types.conf +122 -0
  479. data/lib/ffi/platform/i386-windows/types.conf +105 -0
  480. data/lib/ffi/platform/ia64-linux/types.conf +104 -0
  481. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  482. data/lib/ffi/platform/mips64-linux/types.conf +104 -0
  483. data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
  484. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  485. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +102 -0
  486. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +102 -0
  487. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +104 -0
  488. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +104 -0
  489. data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
  490. data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
  491. data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  492. data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
  493. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  494. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  495. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  496. data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
  497. data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
  498. data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
  499. data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
  500. data/lib/ffi/platform/x86_64-darwin/types.conf +126 -0
  501. data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
  502. data/lib/ffi/platform/x86_64-freebsd12/types.conf +128 -0
  503. data/lib/ffi/platform/x86_64-linux/types.conf +102 -0
  504. data/lib/ffi/platform/x86_64-netbsd/types.conf +128 -0
  505. data/lib/ffi/platform/x86_64-openbsd/types.conf +134 -0
  506. data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
  507. data/lib/ffi/platform/x86_64-windows/types.conf +120 -0
  508. data/lib/ffi/pointer.rb +160 -0
  509. data/lib/ffi/struct.rb +311 -0
  510. data/lib/ffi/struct_by_reference.rb +72 -0
  511. data/lib/ffi/struct_layout.rb +96 -0
  512. data/lib/ffi/struct_layout_builder.rb +227 -0
  513. data/lib/ffi/tools/const_generator.rb +230 -0
  514. data/lib/ffi/tools/generator.rb +105 -0
  515. data/lib/ffi/tools/generator_task.rb +32 -0
  516. data/lib/ffi/tools/struct_generator.rb +194 -0
  517. data/lib/ffi/tools/types_generator.rb +134 -0
  518. data/lib/ffi/types.rb +194 -0
  519. data/lib/ffi/union.rb +43 -0
  520. data/lib/ffi/variadic.rb +78 -0
  521. data/lib/ffi/version.rb +3 -0
  522. data/samples/getlogin.rb +8 -0
  523. data/samples/getpid.rb +8 -0
  524. data/samples/gettimeofday.rb +18 -0
  525. data/samples/hello.rb +7 -0
  526. data/samples/inotify.rb +60 -0
  527. data/samples/pty.rb +76 -0
  528. data/samples/qsort.rb +21 -0
  529. data/samples/sample_helper.rb +6 -0
  530. metadata +663 -0
@@ -0,0 +1,195 @@
1
+ require 'rubygems/tasks'
2
+ require 'rbconfig'
3
+ require 'rake/clean'
4
+ require File.expand_path("./lib/ffi/version")
5
+
6
+ require 'date'
7
+ require 'fileutils'
8
+ require 'rbconfig'
9
+ require 'rspec/core/rake_task'
10
+ require 'rubygems/package_task'
11
+
12
+ def java?
13
+ /java/ === RUBY_PLATFORM
14
+ end
15
+
16
+ BUILD_DIR = "build"
17
+ BUILD_EXT_DIR = File.join(BUILD_DIR, "#{RbConfig::CONFIG['arch']}", 'ffi_c', RUBY_VERSION)
18
+
19
+ def gem_spec
20
+ @gem_spec ||= Gem::Specification.load('ffi.gemspec')
21
+ end
22
+
23
+ TEST_DEPS = []
24
+ if RUBY_PLATFORM == "java"
25
+ RSpec::Core::RakeTask.new(:spec) do |config|
26
+ config.rspec_opts = YAML.load_file 'spec/spec.opts'
27
+ end
28
+ else
29
+ RSpec::Core::RakeTask.new(:spec => :compile) do |config|
30
+ config.rspec_opts = YAML.load_file 'spec/spec.opts'
31
+ end
32
+
33
+ TEST_DEPS.unshift :compile
34
+ end
35
+
36
+ desc "Build all packages"
37
+ task :package => %w[ gem:java gem:windows ]
38
+
39
+ CLOBBER.include 'lib/ffi/types.conf'
40
+ CLOBBER.include 'pkg'
41
+ CLOBBER.include 'log'
42
+
43
+ CLEAN.include 'build'
44
+ CLEAN.include 'conftest.dSYM'
45
+ CLEAN.include 'spec/ffi/fixtures/libtest.{dylib,so,dll}'
46
+ CLEAN.include 'spec/ffi/fixtures/*.o'
47
+ CLEAN.include 'spec/ffi/embed-test/ext/*.{o,def}'
48
+ CLEAN.include 'spec/ffi/embed-test/ext/Makefile'
49
+ CLEAN.include "pkg/ffi-*-{mingw32,java}"
50
+ CLEAN.include 'lib/1.*'
51
+ CLEAN.include 'lib/2.*'
52
+
53
+ task :distclean => :clobber
54
+
55
+ desc "Test the extension"
56
+ task :test => [ :spec ]
57
+
58
+
59
+ namespace :bench do
60
+ ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000
61
+ bench_libs = "-Ilib" unless RUBY_PLATFORM == "java"
62
+ bench_files = Dir["bench/bench_*.rb"].reject { |f| f == "bench/bench_helper.rb" }
63
+ bench_files.each do |bench|
64
+ task File.basename(bench, ".rb")[6..-1] => TEST_DEPS do
65
+ sh %{#{Gem.ruby} #{bench_libs} #{bench} #{ITER}}
66
+ end
67
+ end
68
+ task :all => TEST_DEPS do
69
+ bench_files.each do |bench|
70
+ sh %{#{Gem.ruby} #{bench_libs} #{bench}}
71
+ end
72
+ end
73
+ end
74
+
75
+ task 'spec:run' => TEST_DEPS
76
+ task 'spec:specdoc' => TEST_DEPS
77
+
78
+ task :default => :spec
79
+
80
+ namespace 'java' do
81
+
82
+ java_gem_spec = Gem::Specification.new do |s|
83
+ s.name = gem_spec.name
84
+ s.version = gem_spec.version
85
+ s.author = gem_spec.author
86
+ s.email = gem_spec.email
87
+ s.homepage = gem_spec.homepage
88
+ s.summary = gem_spec.summary
89
+ s.description = gem_spec.description
90
+ s.files = %w(LICENSE COPYING README.md CHANGELOG.md Rakefile)
91
+ s.license = gem_spec.license
92
+ s.platform = 'java'
93
+ end
94
+
95
+ Gem::PackageTask.new(java_gem_spec) do |pkg|
96
+ pkg.need_zip = true
97
+ pkg.need_tar = true
98
+ pkg.package_dir = 'pkg'
99
+ end
100
+ end
101
+
102
+ task 'gem:java' => 'java:gem'
103
+
104
+ unless java?
105
+ require 'rake/extensiontask'
106
+ Rake::ExtensionTask.new('ffi_c', gem_spec) do |ext|
107
+ ext.name = 'ffi_c' # indicate the name of the extension.
108
+ # ext.lib_dir = BUILD_DIR # put binaries into this folder.
109
+ ext.tmp_dir = BUILD_DIR # temporary folder used during compilation.
110
+ ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
111
+ ext.cross_platform = %w[i386-mingw32 x64-mingw32] # forces the Windows platform instead of the default one
112
+ ext.cross_compiling do |spec|
113
+ spec.files.reject! { |path| File.fnmatch?('ext/*', path) }
114
+ end
115
+ end
116
+
117
+ # To reduce the gem file size strip mingw32 dlls before packaging
118
+ ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
119
+ task "build/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so" do |t|
120
+ sh "i686-w64-mingw32-strip -S build/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
121
+ end
122
+
123
+ task "build/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so" do |t|
124
+ sh "x86_64-w64-mingw32-strip -S build/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
125
+ end
126
+ end
127
+ end
128
+
129
+ desc "build a windows gem without all the ceremony"
130
+ task "gem:windows" do
131
+ require "rake_compiler_dock"
132
+ sh "bundle package"
133
+ RakeCompilerDock.sh "sudo apt-get update && sudo apt-get install -y libltdl-dev && bundle --local && rake cross native gem MAKE='nice make -j`nproc`'"
134
+ end
135
+
136
+ directory "ext/ffi_c/libffi"
137
+ file "ext/ffi_c/libffi/autogen.sh" => "ext/ffi_c/libffi" do
138
+ warn "Downloading libffi ..."
139
+ sh "git submodule update --init --recursive"
140
+ end
141
+ task :libffi => "ext/ffi_c/libffi/autogen.sh"
142
+
143
+ LIBFFI_GIT_FILES = `git --git-dir ext/ffi_c/libffi/.git ls-files -z`.split("\x0")
144
+
145
+ # Generate files in gemspec but not in libffi's git repo by running autogen.sh
146
+ gem_spec.files.select do |f|
147
+ f =~ /ext\/ffi_c\/libffi\/(.*)/ && !LIBFFI_GIT_FILES.include?($1)
148
+ end.each do |f|
149
+ file f => "ext/ffi_c/libffi/autogen.sh" do
150
+ chdir "ext/ffi_c/libffi" do
151
+ sh "sh ./autogen.sh"
152
+ end
153
+ touch f
154
+ if gem_spec.files != Gem::Specification.load('./ffi.gemspec').files
155
+ warn "gemspec files have changed -> Please restart rake!"
156
+ exit 1
157
+ end
158
+ end
159
+ end
160
+
161
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
162
+ require 'ffi/platform'
163
+ types_conf = File.expand_path(File.join(FFI::Platform::CONF_DIR, 'types.conf'))
164
+ logfile = File.join(File.dirname(__FILE__), 'types_log')
165
+
166
+ file types_conf => File.join("lib", "ffi", "version.rb") do |task|
167
+ require 'fileutils'
168
+ require 'ffi/tools/types_generator'
169
+ options = {}
170
+ FileUtils.mkdir_p(File.dirname(task.name), { :mode => 0755 })
171
+ File.open(task.name, File::CREAT|File::TRUNC|File::RDWR, 0644) do |f|
172
+ f.puts FFI::TypesGenerator.generate(options)
173
+ end
174
+ File.open(logfile, 'w') do |log|
175
+ log.puts(types_conf)
176
+ end
177
+ end
178
+
179
+ task :types_conf => types_conf do
180
+ end
181
+
182
+ Gem::Tasks.new do |t|
183
+ t.scm.tag.format = '%s'
184
+ end
185
+
186
+ begin
187
+ require 'yard'
188
+
189
+ namespace :doc do
190
+ YARD::Rake::YardocTask.new do |yard|
191
+ end
192
+ end
193
+ rescue LoadError
194
+ warn "[warn] YARD unavailable"
195
+ end
@@ -0,0 +1,27 @@
1
+ install:
2
+ - SET PATH=C:\Ruby%RUBYVER%\bin;%PATH%
3
+ - SET RAKEOPT=-rdevkit
4
+ - ps: |
5
+ if ($env:RUBYVER -like "*head*") {
6
+ $(new-object net.webclient).DownloadFile("https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-$env:RUBYVER.exe", "$pwd/ruby-setup.exe")
7
+ cmd /c ruby-setup.exe /verysilent /dir=C:/Ruby$env:RUBYVER
8
+ }
9
+ - ridk version
10
+ - gem --version
11
+ - gem install bundler --quiet --no-document
12
+ - bundle install
13
+ build: off
14
+ build_script:
15
+ - bundle exec rake libffi compile -- %EXTCONFOPTS% || bundle exec rake compile -- %EXTCONFOPTS%
16
+ test_script:
17
+ - bundle exec rake test
18
+ environment:
19
+ matrix:
20
+ - RUBYVER: "head-x64"
21
+ EXTCONFOPTS: "--disable-system-libffi"
22
+ - RUBYVER: 24
23
+ EXTCONFOPTS: "--disable-system-libffi"
24
+ - RUBYVER: 25-x64
25
+ EXTCONFOPTS: "--enable-system-libffi"
26
+ - RUBYVER: 25
27
+ EXTCONFOPTS: "--enable-system-libffi"
@@ -0,0 +1,1109 @@
1
+ /*
2
+ * Copyright (c) 2008, 2009, Wayne Meissner
3
+ * Copyright (C) 2009 Jake Douglas <jake@shiftedlabs.com>
4
+ * Copyright (C) 2008 Luc Heinrich <luc@honk-honk.com>
5
+ *
6
+ * Copyright (c) 2008-2013, Ruby FFI project contributors
7
+ * All rights reserved.
8
+ *
9
+ * Redistribution and use in source and binary forms, with or without
10
+ * modification, are permitted provided that the following conditions are met:
11
+ * * Redistributions of source code must retain the above copyright
12
+ * notice, this list of conditions and the following disclaimer.
13
+ * * Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ * * Neither the name of the Ruby FFI project nor the
17
+ * names of its contributors may be used to endorse or promote products
18
+ * derived from this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
24
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ */
31
+
32
+ #include <sys/types.h>
33
+ #ifndef _MSC_VER
34
+ # include <sys/param.h>
35
+ # include <stdint.h>
36
+ # include <stdbool.h>
37
+ #else
38
+ # include "win32/stdbool.h"
39
+ # include "win32/stdint.h"
40
+ #endif
41
+
42
+ #include <limits.h>
43
+ #include <ruby.h>
44
+
45
+ #include "rbffi.h"
46
+ #include "compat.h"
47
+ #include "AbstractMemory.h"
48
+ #include "Pointer.h"
49
+ #include "Function.h"
50
+ #include "LongDouble.h"
51
+
52
+ #ifdef PRIsVALUE
53
+ # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
54
+ # define RB_OBJ_STRING(obj) (obj)
55
+ #else
56
+ # define PRIsVALUE "s"
57
+ # define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
58
+ # define RB_OBJ_STRING(obj) StringValueCStr(obj)
59
+ #endif
60
+
61
+ static inline char* memory_address(VALUE self);
62
+ VALUE rbffi_AbstractMemoryClass = Qnil;
63
+ static VALUE NullPointerErrorClass = Qnil;
64
+ static ID id_to_ptr = 0, id_plus = 0, id_call = 0;
65
+
66
+ static VALUE
67
+ memory_allocate(VALUE klass)
68
+ {
69
+ AbstractMemory* memory;
70
+ VALUE obj;
71
+ obj = Data_Make_Struct(klass, AbstractMemory, NULL, -1, memory);
72
+ memory->flags = MEM_RD | MEM_WR;
73
+
74
+ return obj;
75
+ }
76
+ #define VAL(x, swap) (unlikely(((memory->flags & MEM_SWAP) != 0)) ? swap((x)) : (x))
77
+
78
+ #define NUM_OP(name, type, toNative, fromNative, swap) \
79
+ static void memory_op_put_##name(AbstractMemory* memory, long off, VALUE value); \
80
+ static void \
81
+ memory_op_put_##name(AbstractMemory* memory, long off, VALUE value) \
82
+ { \
83
+ type tmp = (type) VAL(toNative(value), swap); \
84
+ checkWrite(memory); \
85
+ checkBounds(memory, off, sizeof(type)); \
86
+ memcpy(memory->address + off, &tmp, sizeof(tmp)); \
87
+ } \
88
+ static VALUE memory_put_##name(VALUE self, VALUE offset, VALUE value); \
89
+ static VALUE \
90
+ memory_put_##name(VALUE self, VALUE offset, VALUE value) \
91
+ { \
92
+ AbstractMemory* memory; \
93
+ Data_Get_Struct(self, AbstractMemory, memory); \
94
+ memory_op_put_##name(memory, NUM2LONG(offset), value); \
95
+ return self; \
96
+ } \
97
+ static VALUE memory_write_##name(VALUE self, VALUE value); \
98
+ static VALUE \
99
+ memory_write_##name(VALUE self, VALUE value) \
100
+ { \
101
+ AbstractMemory* memory; \
102
+ Data_Get_Struct(self, AbstractMemory, memory); \
103
+ memory_op_put_##name(memory, 0, value); \
104
+ return self; \
105
+ } \
106
+ static VALUE memory_op_get_##name(AbstractMemory* memory, long off); \
107
+ static VALUE \
108
+ memory_op_get_##name(AbstractMemory* memory, long off) \
109
+ { \
110
+ type tmp; \
111
+ checkRead(memory); \
112
+ checkBounds(memory, off, sizeof(type)); \
113
+ memcpy(&tmp, memory->address + off, sizeof(tmp)); \
114
+ return fromNative(VAL(tmp, swap)); \
115
+ } \
116
+ static VALUE memory_get_##name(VALUE self, VALUE offset); \
117
+ static VALUE \
118
+ memory_get_##name(VALUE self, VALUE offset) \
119
+ { \
120
+ AbstractMemory* memory; \
121
+ Data_Get_Struct(self, AbstractMemory, memory); \
122
+ return memory_op_get_##name(memory, NUM2LONG(offset)); \
123
+ } \
124
+ static VALUE memory_read_##name(VALUE self); \
125
+ static VALUE \
126
+ memory_read_##name(VALUE self) \
127
+ { \
128
+ AbstractMemory* memory; \
129
+ Data_Get_Struct(self, AbstractMemory, memory); \
130
+ return memory_op_get_##name(memory, 0); \
131
+ } \
132
+ static MemoryOp memory_op_##name = { memory_op_get_##name, memory_op_put_##name }; \
133
+ \
134
+ static VALUE memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary); \
135
+ static VALUE \
136
+ memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \
137
+ { \
138
+ long count = RARRAY_LEN(ary); \
139
+ long off = NUM2LONG(offset); \
140
+ AbstractMemory* memory = MEMORY(self); \
141
+ long i; \
142
+ checkWrite(memory); \
143
+ checkBounds(memory, off, count * sizeof(type)); \
144
+ for (i = 0; i < count; i++) { \
145
+ type tmp = (type) VAL(toNative(RARRAY_PTR(ary)[i]), swap); \
146
+ memcpy(memory->address + off + (i * sizeof(type)), &tmp, sizeof(tmp)); \
147
+ } \
148
+ return self; \
149
+ } \
150
+ static VALUE memory_write_array_of_##name(VALUE self, VALUE ary); \
151
+ static VALUE \
152
+ memory_write_array_of_##name(VALUE self, VALUE ary) \
153
+ { \
154
+ return memory_put_array_of_##name(self, INT2FIX(0), ary); \
155
+ } \
156
+ static VALUE memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length); \
157
+ static VALUE \
158
+ memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length) \
159
+ { \
160
+ long count = NUM2LONG(length); \
161
+ long off = NUM2LONG(offset); \
162
+ AbstractMemory* memory = MEMORY(self); \
163
+ VALUE retVal = rb_ary_new2(count); \
164
+ long i; \
165
+ checkRead(memory); \
166
+ checkBounds(memory, off, count * sizeof(type)); \
167
+ for (i = 0; i < count; ++i) { \
168
+ type tmp; \
169
+ memcpy(&tmp, memory->address + off + (i * sizeof(type)), sizeof(tmp)); \
170
+ rb_ary_push(retVal, fromNative(VAL(tmp, swap))); \
171
+ } \
172
+ return retVal; \
173
+ } \
174
+ static VALUE memory_read_array_of_##name(VALUE self, VALUE length); \
175
+ static VALUE \
176
+ memory_read_array_of_##name(VALUE self, VALUE length) \
177
+ { \
178
+ return memory_get_array_of_##name(self, INT2FIX(0), length); \
179
+ }
180
+
181
+ #define NOSWAP(x) (x)
182
+ #define bswap16(x) (((x) >> 8) & 0xff) | (((x) << 8) & 0xff00);
183
+ static inline int16_t
184
+ SWAPS16(int16_t x)
185
+ {
186
+ return bswap16(x);
187
+ }
188
+
189
+ static inline uint16_t
190
+ SWAPU16(uint16_t x)
191
+ {
192
+ return bswap16(x);
193
+ }
194
+
195
+ #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
196
+ #define bswap32(x) \
197
+ (((x << 24) & 0xff000000) | \
198
+ ((x << 8) & 0x00ff0000) | \
199
+ ((x >> 8) & 0x0000ff00) | \
200
+ ((x >> 24) & 0x000000ff))
201
+
202
+ #define bswap64(x) \
203
+ (((x << 56) & 0xff00000000000000ULL) | \
204
+ ((x << 40) & 0x00ff000000000000ULL) | \
205
+ ((x << 24) & 0x0000ff0000000000ULL) | \
206
+ ((x << 8) & 0x000000ff00000000ULL) | \
207
+ ((x >> 8) & 0x00000000ff000000ULL) | \
208
+ ((x >> 24) & 0x0000000000ff0000ULL) | \
209
+ ((x >> 40) & 0x000000000000ff00ULL) | \
210
+ ((x >> 56) & 0x00000000000000ffULL))
211
+
212
+ static inline int32_t
213
+ SWAPS32(int32_t x)
214
+ {
215
+ return bswap32(x);
216
+ }
217
+
218
+ static inline uint32_t
219
+ SWAPU32(uint32_t x)
220
+ {
221
+ return bswap32(x);
222
+ }
223
+
224
+ static inline int64_t
225
+ SWAPS64(int64_t x)
226
+ {
227
+ return bswap64(x);
228
+ }
229
+
230
+ static inline uint64_t
231
+ SWAPU64(uint64_t x)
232
+ {
233
+ return bswap64(x);
234
+ }
235
+
236
+ #else
237
+ # define SWAPS32(x) ((int32_t) __builtin_bswap32(x))
238
+ # define SWAPU32(x) ((uint32_t) __builtin_bswap32(x))
239
+ # define SWAPS64(x) ((int64_t) __builtin_bswap64(x))
240
+ # define SWAPU64(x) ((uint64_t) __builtin_bswap64(x))
241
+ #endif
242
+
243
+ #if LONG_MAX > INT_MAX
244
+ # define SWAPSLONG SWAPS64
245
+ # define SWAPULONG SWAPU64
246
+ #else
247
+ # define SWAPSLONG SWAPS32
248
+ # define SWAPULONG SWAPU32
249
+ #endif
250
+
251
+ NUM_OP(int8, int8_t, NUM2INT, INT2NUM, NOSWAP);
252
+ NUM_OP(uint8, uint8_t, NUM2UINT, UINT2NUM, NOSWAP);
253
+ NUM_OP(int16, int16_t, NUM2INT, INT2NUM, SWAPS16);
254
+ NUM_OP(uint16, uint16_t, NUM2UINT, UINT2NUM, SWAPU16);
255
+ NUM_OP(int32, int32_t, NUM2INT, INT2NUM, SWAPS32);
256
+ NUM_OP(uint32, uint32_t, NUM2UINT, UINT2NUM, SWAPU32);
257
+ NUM_OP(int64, int64_t, NUM2LL, LL2NUM, SWAPS64);
258
+ NUM_OP(uint64, uint64_t, NUM2ULL, ULL2NUM, SWAPU64);
259
+ NUM_OP(long, long, NUM2LONG, LONG2NUM, SWAPSLONG);
260
+ NUM_OP(ulong, unsigned long, NUM2ULONG, ULONG2NUM, SWAPULONG);
261
+ NUM_OP(float32, float, NUM2DBL, rb_float_new, NOSWAP);
262
+ NUM_OP(float64, double, NUM2DBL, rb_float_new, NOSWAP);
263
+ NUM_OP(longdouble, long double, rbffi_num2longdouble, rbffi_longdouble_new, NOSWAP);
264
+
265
+ static inline void*
266
+ get_pointer_value(VALUE value)
267
+ {
268
+ const int type = TYPE(value);
269
+ if (type == T_DATA && rb_obj_is_kind_of(value, rbffi_PointerClass)) {
270
+ return memory_address(value);
271
+ } else if (type == T_NIL) {
272
+ return NULL;
273
+ } else if (type == T_FIXNUM) {
274
+ return (void *) (uintptr_t) FIX2ULONG(value);
275
+ } else if (type == T_BIGNUM) {
276
+ return (void *) (uintptr_t) NUM2ULL(value);
277
+ } else if (rb_respond_to(value, id_to_ptr)) {
278
+ return MEMORY_PTR(rb_funcall2(value, id_to_ptr, 0, NULL));
279
+ } else {
280
+ rb_raise(rb_eArgError, "value is not a pointer");
281
+ return NULL;
282
+ }
283
+ }
284
+
285
+ NUM_OP(pointer, void *, get_pointer_value, rbffi_Pointer_NewInstance, NOSWAP);
286
+
287
+ static inline uint8_t
288
+ rbffi_bool_value(VALUE value)
289
+ {
290
+ return RTEST(value);
291
+ }
292
+
293
+ static inline VALUE
294
+ rbffi_bool_new(uint8_t value)
295
+ {
296
+ return (value & 1) != 0 ? Qtrue : Qfalse;
297
+ }
298
+
299
+ NUM_OP(bool, unsigned char, rbffi_bool_value, rbffi_bool_new, NOSWAP);
300
+
301
+
302
+ /*
303
+ * call-seq: memory.clear
304
+ * Set the memory to all-zero.
305
+ * @return [self]
306
+ */
307
+ static VALUE
308
+ memory_clear(VALUE self)
309
+ {
310
+ AbstractMemory* ptr = MEMORY(self);
311
+ memset(ptr->address, 0, ptr->size);
312
+ return self;
313
+ }
314
+
315
+ /*
316
+ * call-seq: memory.size
317
+ * Return memory size in bytes (alias: #total)
318
+ * @return [Numeric]
319
+ */
320
+ static VALUE
321
+ memory_size(VALUE self)
322
+ {
323
+ AbstractMemory* ptr;
324
+
325
+ Data_Get_Struct(self, AbstractMemory, ptr);
326
+
327
+ return LONG2NUM(ptr->size);
328
+ }
329
+
330
+ /*
331
+ * call-seq: memory.get(type, offset)
332
+ * Return data of given type contained in memory.
333
+ * @param [Symbol, Type] type_name type of data to get
334
+ * @param [Numeric] offset point in buffer to start from
335
+ * @return [Object]
336
+ * @raise {ArgumentError} if type is not supported
337
+ */
338
+ static VALUE
339
+ memory_get(VALUE self, VALUE type_name, VALUE offset)
340
+ {
341
+ AbstractMemory* ptr;
342
+ VALUE nType;
343
+ Type *type;
344
+
345
+ nType = rbffi_Type_Lookup(type_name);
346
+ if(NIL_P(nType)) goto undefined_type;
347
+
348
+ Data_Get_Struct(self, AbstractMemory, ptr);
349
+ Data_Get_Struct(nType, Type, type);
350
+
351
+ MemoryOp *op = get_memory_op(type);
352
+ if(op == NULL) goto undefined_type;
353
+
354
+ return op->get(ptr, NUM2LONG(offset));
355
+
356
+ undefined_type: {
357
+ VALUE msg = rb_sprintf("undefined type '%" PRIsVALUE "'", type_name);
358
+ rb_exc_raise(rb_exc_new3(rb_eArgError, msg));
359
+ return Qnil;
360
+ }
361
+ }
362
+
363
+ /*
364
+ * call-seq: memory.put(type, offset, value)
365
+ * @param [Symbol, Type] type_name type of data to put
366
+ * @param [Numeric] offset point in buffer to start from
367
+ * @return [nil]
368
+ * @raise {ArgumentError} if type is not supported
369
+ */
370
+ static VALUE
371
+ memory_put(VALUE self, VALUE type_name, VALUE offset, VALUE value)
372
+ {
373
+ AbstractMemory* ptr;
374
+ VALUE nType;
375
+ Type *type;
376
+
377
+ nType = rbffi_Type_Lookup(type_name);
378
+ if(NIL_P(nType)) goto undefined_type;
379
+
380
+ Data_Get_Struct(self, AbstractMemory, ptr);
381
+ Data_Get_Struct(nType, Type, type);
382
+
383
+ MemoryOp *op = get_memory_op(type);
384
+ if(op == NULL) goto undefined_type;
385
+
386
+ op->put(ptr, NUM2LONG(offset), value);
387
+ return Qnil;
388
+
389
+ undefined_type: {
390
+ VALUE msg = rb_sprintf("unsupported type '%" PRIsVALUE "'", type_name);
391
+ rb_exc_raise(rb_exc_new3(rb_eArgError, msg));
392
+ return Qnil;
393
+ }
394
+ }
395
+
396
+ /*
397
+ * call-seq: memory.get_string(offset, length=nil)
398
+ * Return string contained in memory.
399
+ * @param [Numeric] offset point in buffer to start from
400
+ * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
401
+ * @return [String]
402
+ * @raise {IndexError} if +length+ is too great
403
+ * @raise {NullPointerError} if memory not initialized
404
+ */
405
+ static VALUE
406
+ memory_get_string(int argc, VALUE* argv, VALUE self)
407
+ {
408
+ VALUE length = Qnil, offset = Qnil;
409
+ AbstractMemory* ptr = MEMORY(self);
410
+ long off, len;
411
+ char* end;
412
+ int nargs = rb_scan_args(argc, argv, "11", &offset, &length);
413
+
414
+ off = NUM2LONG(offset);
415
+ len = nargs > 1 && length != Qnil ? NUM2LONG(length) : (ptr->size - off);
416
+ checkRead(ptr);
417
+ checkBounds(ptr, off, len);
418
+
419
+ end = memchr(ptr->address + off, 0, len);
420
+ return rb_tainted_str_new((char *) ptr->address + off,
421
+ (end != NULL ? end - ptr->address - off : len));
422
+ }
423
+
424
+ /*
425
+ * call-seq: memory.get_array_of_string(offset, count=nil)
426
+ * Return an array of strings contained in memory.
427
+ * @param [Numeric] offset point in memory to start from
428
+ * @param [Numeric] count number of strings to get. If nil, return all strings
429
+ * @return [Array<String>]
430
+ * @raise {IndexError} if +offset+ is too great
431
+ * @raise {NullPointerError} if memory not initialized
432
+ */
433
+ static VALUE
434
+ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
435
+ {
436
+ VALUE offset = Qnil, countnum = Qnil, retVal = Qnil;
437
+ AbstractMemory* ptr;
438
+ long off;
439
+ int count;
440
+
441
+ rb_scan_args(argc, argv, "11", &offset, &countnum);
442
+ off = NUM2LONG(offset);
443
+ count = (countnum == Qnil ? 0 : NUM2INT(countnum));
444
+ retVal = rb_ary_new2(count);
445
+
446
+ Data_Get_Struct(self, AbstractMemory, ptr);
447
+ checkRead(ptr);
448
+
449
+ if (countnum != Qnil) {
450
+ int i;
451
+
452
+ checkBounds(ptr, off, count * sizeof (char*));
453
+
454
+ for (i = 0; i < count; ++i) {
455
+ const char* strptr = *((const char**) (ptr->address + off) + i);
456
+ rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_tainted_str_new2(strptr)));
457
+ }
458
+
459
+ } else {
460
+ checkBounds(ptr, off, sizeof (char*));
461
+ for ( ; off < ptr->size - (long) sizeof (void *); off += (long) sizeof (void *)) {
462
+ const char* strptr = *(const char**) (ptr->address + off);
463
+ if (strptr == NULL) {
464
+ break;
465
+ }
466
+ rb_ary_push(retVal, rb_tainted_str_new2(strptr));
467
+ }
468
+ }
469
+
470
+ return retVal;
471
+ }
472
+
473
+ /*
474
+ * call-seq: memory.read_array_of_string(count=nil)
475
+ * Return an array of strings contained in memory. Same as:
476
+ * memory.get_array_of_string(0, count)
477
+ * @param [Numeric] count number of strings to get. If nil, return all strings
478
+ * @return [Array<String>]
479
+ */
480
+ static VALUE
481
+ memory_read_array_of_string(int argc, VALUE* argv, VALUE self)
482
+ {
483
+ VALUE* rargv = ALLOCA_N(VALUE, argc + 1);
484
+ int i;
485
+
486
+ rargv[0] = INT2FIX(0);
487
+ for (i = 0; i < argc; i++) {
488
+ rargv[i + 1] = argv[i];
489
+ }
490
+
491
+ return memory_get_array_of_string(argc + 1, rargv, self);
492
+ }
493
+
494
+
495
+ /*
496
+ * call-seq: memory.put_string(offset, str)
497
+ * @param [Numeric] offset
498
+ * @param [String] str
499
+ * @return [self]
500
+ * @raise {SecurityError} when writing unsafe string to memory
501
+ * @raise {IndexError} if +offset+ is too great
502
+ * @raise {NullPointerError} if memory not initialized
503
+ * Put a string in memory.
504
+ */
505
+ static VALUE
506
+ memory_put_string(VALUE self, VALUE offset, VALUE str)
507
+ {
508
+ AbstractMemory* ptr = MEMORY(self);
509
+ long off, len;
510
+
511
+ Check_Type(str, T_STRING);
512
+ off = NUM2LONG(offset);
513
+ len = RSTRING_LEN(str);
514
+
515
+ checkWrite(ptr);
516
+ checkBounds(ptr, off, len + 1);
517
+
518
+ memcpy(ptr->address + off, RSTRING_PTR(str), len);
519
+ *((char *) ptr->address + off + len) = '\0';
520
+
521
+ return self;
522
+ }
523
+
524
+ /*
525
+ * call-seq: memory.get_bytes(offset, length)
526
+ * Return string contained in memory.
527
+ * @param [Numeric] offset point in buffer to start from
528
+ * @param [Numeric] length string's length in bytes.
529
+ * @return [String]
530
+ * @raise {IndexError} if +length+ is too great
531
+ * @raise {NullPointerError} if memory not initialized
532
+ */
533
+ static VALUE
534
+ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
535
+ {
536
+ AbstractMemory* ptr = MEMORY(self);
537
+ long off, len;
538
+
539
+ off = NUM2LONG(offset);
540
+ len = NUM2LONG(length);
541
+
542
+ checkRead(ptr);
543
+ checkBounds(ptr, off, len);
544
+
545
+ return rb_tainted_str_new((char *) ptr->address + off, len);
546
+ }
547
+
548
+ /*
549
+ * call-seq: memory.put_bytes(offset, str, index=0, length=nil)
550
+ * Put a string in memory.
551
+ * @param [Numeric] offset point in buffer to start from
552
+ * @param [String] str string to put to memory
553
+ * @param [Numeric] index
554
+ * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
555
+ * @return [self]
556
+ * @raise {IndexError} if +length+ is too great
557
+ * @raise {NullPointerError} if memory not initialized
558
+ * @raise {RangeError} if +index+ is negative, or if index+length is greater than size of string
559
+ * @raise {SecurityError} when writing unsafe string to memory
560
+ */
561
+ static VALUE
562
+ memory_put_bytes(int argc, VALUE* argv, VALUE self)
563
+ {
564
+ AbstractMemory* ptr = MEMORY(self);
565
+ VALUE offset = Qnil, str = Qnil, rbIndex = Qnil, rbLength = Qnil;
566
+ long off, len, idx;
567
+ int nargs = rb_scan_args(argc, argv, "22", &offset, &str, &rbIndex, &rbLength);
568
+
569
+ Check_Type(str, T_STRING);
570
+
571
+ off = NUM2LONG(offset);
572
+ idx = nargs > 2 ? NUM2LONG(rbIndex) : 0;
573
+ if (idx < 0) {
574
+ rb_raise(rb_eRangeError, "index cannot be less than zero");
575
+ return Qnil;
576
+ }
577
+ len = nargs > 3 ? NUM2LONG(rbLength) : (RSTRING_LEN(str) - idx);
578
+ if ((idx + len) > RSTRING_LEN(str)) {
579
+ rb_raise(rb_eRangeError, "index+length is greater than size of string");
580
+ return Qnil;
581
+ }
582
+
583
+ checkWrite(ptr);
584
+ checkBounds(ptr, off, len);
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
+ memcpy(ptr->address + off, RSTRING_PTR(str) + idx, len);
591
+
592
+ return self;
593
+ }
594
+
595
+ /*
596
+ * call-seq: memory.read_bytes(length)
597
+ * @param [Numeric] length of string to return
598
+ * @return [String]
599
+ * equivalent to :
600
+ * memory.get_bytes(0, length)
601
+ */
602
+ static VALUE
603
+ memory_read_bytes(VALUE self, VALUE length)
604
+ {
605
+ return memory_get_bytes(self, INT2FIX(0), length);
606
+ }
607
+
608
+ /*
609
+ * call-seq: memory.write_bytes(str, index=0, length=nil)
610
+ * @param [String] str string to put to memory
611
+ * @param [Numeric] index
612
+ * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
613
+ * @return [self]
614
+ * equivalent to :
615
+ * memory.put_bytes(0, str, index, length)
616
+ */
617
+ static VALUE
618
+ memory_write_bytes(int argc, VALUE* argv, VALUE self)
619
+ {
620
+ VALUE* wargv = ALLOCA_N(VALUE, argc + 1);
621
+ int i;
622
+
623
+ wargv[0] = INT2FIX(0);
624
+ for (i = 0; i < argc; i++) {
625
+ wargv[i + 1] = argv[i];
626
+ }
627
+
628
+ return memory_put_bytes(argc + 1, wargv, self);
629
+ }
630
+
631
+ /*
632
+ * call-seq: memory.type_size
633
+ * @return [Numeric] type size in bytes
634
+ * Get the memory's type size.
635
+ */
636
+ static VALUE
637
+ memory_type_size(VALUE self)
638
+ {
639
+ AbstractMemory* ptr;
640
+
641
+ Data_Get_Struct(self, AbstractMemory, ptr);
642
+
643
+ return INT2NUM(ptr->typeSize);
644
+ }
645
+
646
+ /*
647
+ * Document-method: []
648
+ * call-seq: memory[idx]
649
+ * @param [Numeric] idx index to access in memory
650
+ * @return
651
+ * Memory read accessor.
652
+ */
653
+ static VALUE
654
+ memory_aref(VALUE self, VALUE idx)
655
+ {
656
+ AbstractMemory* ptr;
657
+ VALUE rbOffset = Qnil;
658
+
659
+ Data_Get_Struct(self, AbstractMemory, ptr);
660
+
661
+ rbOffset = ULONG2NUM(NUM2ULONG(idx) * ptr->typeSize);
662
+
663
+ return rb_funcall2(self, id_plus, 1, &rbOffset);
664
+ }
665
+
666
+ static inline char*
667
+ memory_address(VALUE obj)
668
+ {
669
+ return ((AbstractMemory *) DATA_PTR(obj))->address;
670
+ }
671
+
672
+ static VALUE
673
+ memory_copy_from(VALUE self, VALUE rbsrc, VALUE rblen)
674
+ {
675
+ AbstractMemory* dst;
676
+
677
+ Data_Get_Struct(self, AbstractMemory, dst);
678
+
679
+ memcpy(dst->address, rbffi_AbstractMemory_Cast(rbsrc, rbffi_AbstractMemoryClass)->address, NUM2INT(rblen));
680
+
681
+ return self;
682
+ }
683
+
684
+ AbstractMemory*
685
+ rbffi_AbstractMemory_Cast(VALUE obj, VALUE klass)
686
+ {
687
+ if (rb_obj_is_kind_of(obj, klass)) {
688
+ AbstractMemory* memory;
689
+ Data_Get_Struct(obj, AbstractMemory, memory);
690
+ return memory;
691
+ }
692
+
693
+ rb_raise(rb_eArgError, "Invalid Memory object");
694
+ return NULL;
695
+ }
696
+
697
+ void
698
+ rbffi_AbstractMemory_Error(AbstractMemory *mem, int op)
699
+ {
700
+ VALUE rbErrorClass = mem->address == NULL ? NullPointerErrorClass : rb_eRuntimeError;
701
+ if (op == MEM_RD) {
702
+ rb_raise(rbErrorClass, "invalid memory read at address=%p", mem->address);
703
+ } else if (op == MEM_WR) {
704
+ rb_raise(rbErrorClass, "invalid memory write at address=%p", mem->address);
705
+ } else {
706
+ rb_raise(rbErrorClass, "invalid memory access at address=%p", mem->address);
707
+ }
708
+ }
709
+
710
+ static VALUE
711
+ memory_op_get_strptr(AbstractMemory* ptr, long offset)
712
+ {
713
+ void* tmp = NULL;
714
+
715
+ if (ptr != NULL && ptr->address != NULL) {
716
+ checkRead(ptr);
717
+ checkBounds(ptr, offset, sizeof(tmp));
718
+ memcpy(&tmp, ptr->address + offset, sizeof(tmp));
719
+ }
720
+
721
+ return tmp != NULL ? rb_tainted_str_new2(tmp) : Qnil;
722
+ }
723
+
724
+ static void
725
+ memory_op_put_strptr(AbstractMemory* ptr, long offset, VALUE value)
726
+ {
727
+ rb_raise(rb_eArgError, "Cannot set :string fields");
728
+ }
729
+
730
+ static MemoryOp memory_op_strptr = { memory_op_get_strptr, memory_op_put_strptr };
731
+
732
+
733
+ MemoryOps rbffi_AbstractMemoryOps = {
734
+ &memory_op_int8, /*.int8 */
735
+ &memory_op_uint8, /* .uint8 */
736
+ &memory_op_int16, /* .int16 */
737
+ &memory_op_uint16, /* .uint16 */
738
+ &memory_op_int32, /* .int32 */
739
+ &memory_op_uint32, /* .uint32 */
740
+ &memory_op_int64, /* .int64 */
741
+ &memory_op_uint64, /* .uint64 */
742
+ &memory_op_long, /* .slong */
743
+ &memory_op_ulong, /* .uslong */
744
+ &memory_op_float32, /* .float32 */
745
+ &memory_op_float64, /* .float64 */
746
+ &memory_op_longdouble, /* .longdouble */
747
+ &memory_op_pointer, /* .pointer */
748
+ &memory_op_strptr, /* .strptr */
749
+ &memory_op_bool /* .boolOp */
750
+ };
751
+
752
+ void
753
+ rbffi_AbstractMemory_Init(VALUE moduleFFI)
754
+ {
755
+ /*
756
+ * Document-class: FFI::AbstractMemory
757
+ *
758
+ * {AbstractMemory} is the base class for many memory management classes such as {Buffer}.
759
+ *
760
+ * This class has a lot of methods to work with integers :
761
+ * * put_int<i>size</i>(offset, value)
762
+ * * get_int<i>size</i>(offset)
763
+ * * put_uint<i>size</i>(offset, value)
764
+ * * get_uint<i>size</i>(offset)
765
+ * * writeuint<i>size</i>(value)
766
+ * * read_int<i>size</i>
767
+ * * write_uint<i>size</i>(value)
768
+ * * read_uint<i>size</i>
769
+ * * put_array_of_int<i>size</i>(offset, ary)
770
+ * * get_array_of_int<i>size</i>(offset, length)
771
+ * * put_array_of_uint<i>size</i>(offset, ary)
772
+ * * get_array_of_uint<i>size</i>(offset, length)
773
+ * * write_array_of_int<i>size</i>(ary)
774
+ * * read_array_of_int<i>size</i>(length)
775
+ * * write_array_of_uint<i>size</i>(ary)
776
+ * * read_array_of_uint<i>size</i>(length)
777
+ * where _size_ is 8, 16, 32 or 64. Same methods exist for long type.
778
+ *
779
+ * Aliases exist : _char_ for _int8_, _short_ for _int16_, _int_ for _int32_ and <i>long_long</i> for _int64_.
780
+ *
781
+ * Others methods are listed below.
782
+ */
783
+ VALUE classMemory = rb_define_class_under(moduleFFI, "AbstractMemory", rb_cObject);
784
+ rbffi_AbstractMemoryClass = classMemory;
785
+ /*
786
+ * Document-variable: FFI::AbstractMemory
787
+ */
788
+ rb_global_variable(&rbffi_AbstractMemoryClass);
789
+ rb_define_alloc_func(classMemory, memory_allocate);
790
+
791
+ NullPointerErrorClass = rb_define_class_under(moduleFFI, "NullPointerError", rb_eRuntimeError);
792
+ /* Document-variable: NullPointerError */
793
+ rb_global_variable(&NullPointerErrorClass);
794
+
795
+
796
+ #undef INT
797
+ #define INT(type) \
798
+ rb_define_method(classMemory, "put_" #type, memory_put_##type, 2); \
799
+ rb_define_method(classMemory, "get_" #type, memory_get_##type, 1); \
800
+ rb_define_method(classMemory, "put_u" #type, memory_put_u##type, 2); \
801
+ rb_define_method(classMemory, "get_u" #type, memory_get_u##type, 1); \
802
+ rb_define_method(classMemory, "write_" #type, memory_write_##type, 1); \
803
+ rb_define_method(classMemory, "read_" #type, memory_read_##type, 0); \
804
+ rb_define_method(classMemory, "write_u" #type, memory_write_u##type, 1); \
805
+ rb_define_method(classMemory, "read_u" #type, memory_read_u##type, 0); \
806
+ rb_define_method(classMemory, "put_array_of_" #type, memory_put_array_of_##type, 2); \
807
+ rb_define_method(classMemory, "get_array_of_" #type, memory_get_array_of_##type, 2); \
808
+ rb_define_method(classMemory, "put_array_of_u" #type, memory_put_array_of_u##type, 2); \
809
+ rb_define_method(classMemory, "get_array_of_u" #type, memory_get_array_of_u##type, 2); \
810
+ rb_define_method(classMemory, "write_array_of_" #type, memory_write_array_of_##type, 1); \
811
+ rb_define_method(classMemory, "read_array_of_" #type, memory_read_array_of_##type, 1); \
812
+ rb_define_method(classMemory, "write_array_of_u" #type, memory_write_array_of_u##type, 1); \
813
+ rb_define_method(classMemory, "read_array_of_u" #type, memory_read_array_of_u##type, 1);
814
+
815
+ INT(int8);
816
+ INT(int16);
817
+ INT(int32);
818
+ INT(int64);
819
+ INT(long);
820
+
821
+ #define ALIAS(name, old) \
822
+ rb_define_alias(classMemory, "put_" #name, "put_" #old); \
823
+ rb_define_alias(classMemory, "get_" #name, "get_" #old); \
824
+ rb_define_alias(classMemory, "put_u" #name, "put_u" #old); \
825
+ rb_define_alias(classMemory, "get_u" #name, "get_u" #old); \
826
+ rb_define_alias(classMemory, "write_" #name, "write_" #old); \
827
+ rb_define_alias(classMemory, "read_" #name, "read_" #old); \
828
+ rb_define_alias(classMemory, "write_u" #name, "write_u" #old); \
829
+ rb_define_alias(classMemory, "read_u" #name, "read_u" #old); \
830
+ rb_define_alias(classMemory, "put_array_of_" #name, "put_array_of_" #old); \
831
+ rb_define_alias(classMemory, "get_array_of_" #name, "get_array_of_" #old); \
832
+ rb_define_alias(classMemory, "put_array_of_u" #name, "put_array_of_u" #old); \
833
+ rb_define_alias(classMemory, "get_array_of_u" #name, "get_array_of_u" #old); \
834
+ rb_define_alias(classMemory, "write_array_of_" #name, "write_array_of_" #old); \
835
+ rb_define_alias(classMemory, "read_array_of_" #name, "read_array_of_" #old); \
836
+ rb_define_alias(classMemory, "write_array_of_u" #name, "write_array_of_u" #old); \
837
+ rb_define_alias(classMemory, "read_array_of_u" #name, "read_array_of_u" #old);
838
+
839
+ ALIAS(char, int8);
840
+ ALIAS(short, int16);
841
+ ALIAS(int, int32);
842
+ ALIAS(long_long, int64);
843
+
844
+ /*
845
+ * Document-method: put_float32
846
+ * call-seq: memory.put_float32offset, value)
847
+ * @param [Numeric] offset
848
+ * @param [Numeric] value
849
+ * @return [self]
850
+ * Put +value+ as a 32-bit float in memory at offset +offset+ (alias: #put_float).
851
+ */
852
+ rb_define_method(classMemory, "put_float32", memory_put_float32, 2);
853
+ /*
854
+ * Document-method: get_float32
855
+ * call-seq: memory.get_float32(offset)
856
+ * @param [Numeric] offset
857
+ * @return [Float]
858
+ * Get a 32-bit float from memory at offset +offset+ (alias: #get_float).
859
+ */
860
+ rb_define_method(classMemory, "get_float32", memory_get_float32, 1);
861
+ rb_define_alias(classMemory, "put_float", "put_float32");
862
+ rb_define_alias(classMemory, "get_float", "get_float32");
863
+ /*
864
+ * Document-method: write_float
865
+ * call-seq: memory.write_float(value)
866
+ * @param [Numeric] value
867
+ * @return [self]
868
+ * Write +value+ as a 32-bit float in memory.
869
+ *
870
+ * Same as:
871
+ * memory.put_float(0, value)
872
+ */
873
+ rb_define_method(classMemory, "write_float", memory_write_float32, 1);
874
+ /*
875
+ * Document-method: read_float
876
+ * call-seq: memory.read_float
877
+ * @return [Float]
878
+ * Read a 32-bit float from memory.
879
+ *
880
+ * Same as:
881
+ * memory.get_float(0)
882
+ */
883
+ rb_define_method(classMemory, "read_float", memory_read_float32, 0);
884
+ /*
885
+ * Document-method: put_array_of_float32
886
+ * call-seq: memory.put_array_of_float32(offset, ary)
887
+ * @param [Numeric] offset
888
+ * @param [Array<Numeric>] ary
889
+ * @return [self]
890
+ * Put values from +ary+ as 32-bit floats in memory from offset +offset+ (alias: #put_array_of_float).
891
+ */
892
+ rb_define_method(classMemory, "put_array_of_float32", memory_put_array_of_float32, 2);
893
+ /*
894
+ * Document-method: get_array_of_float32
895
+ * call-seq: memory.get_array_of_float32(offset, length)
896
+ * @param [Numeric] offset
897
+ * @param [Numeric] length number of Float to get
898
+ * @return [Array<Float>]
899
+ * Get 32-bit floats in memory from offset +offset+ (alias: #get_array_of_float).
900
+ */
901
+ rb_define_method(classMemory, "get_array_of_float32", memory_get_array_of_float32, 2);
902
+ /*
903
+ * Document-method: write_array_of_float
904
+ * call-seq: memory.write_array_of_float(ary)
905
+ * @param [Array<Numeric>] ary
906
+ * @return [self]
907
+ * Write values from +ary+ as 32-bit floats in memory.
908
+ *
909
+ * Same as:
910
+ * memory.put_array_of_float(0, ary)
911
+ */
912
+ rb_define_method(classMemory, "write_array_of_float", memory_write_array_of_float32, 1);
913
+ /*
914
+ * Document-method: read_array_of_float
915
+ * call-seq: memory.read_array_of_float(length)
916
+ * @param [Numeric] length number of Float to read
917
+ * @return [Array<Float>]
918
+ * Read 32-bit floats from memory.
919
+ *
920
+ * Same as:
921
+ * memory.get_array_of_float(0, ary)
922
+ */
923
+ rb_define_method(classMemory, "read_array_of_float", memory_read_array_of_float32, 1);
924
+ rb_define_alias(classMemory, "put_array_of_float", "put_array_of_float32");
925
+ rb_define_alias(classMemory, "get_array_of_float", "get_array_of_float32");
926
+ /*
927
+ * Document-method: put_float64
928
+ * call-seq: memory.put_float64(offset, value)
929
+ * @param [Numeric] offset
930
+ * @param [Numeric] value
931
+ * @return [self]
932
+ * Put +value+ as a 64-bit float (double) in memory at offset +offset+ (alias: #put_double).
933
+ */
934
+ rb_define_method(classMemory, "put_float64", memory_put_float64, 2);
935
+ /*
936
+ * Document-method: get_float64
937
+ * call-seq: memory.get_float64(offset)
938
+ * @param [Numeric] offset
939
+ * @return [Float]
940
+ * Get a 64-bit float (double) from memory at offset +offset+ (alias: #get_double).
941
+ */
942
+ rb_define_method(classMemory, "get_float64", memory_get_float64, 1);
943
+ rb_define_alias(classMemory, "put_double", "put_float64");
944
+ rb_define_alias(classMemory, "get_double", "get_float64");
945
+ /*
946
+ * Document-method: write_double
947
+ * call-seq: memory.write_double(value)
948
+ * @param [Numeric] value
949
+ * @return [self]
950
+ * Write +value+ as a 64-bit float (double) in memory.
951
+ *
952
+ * Same as:
953
+ * memory.put_double(0, value)
954
+ */
955
+ rb_define_method(classMemory, "write_double", memory_write_float64, 1);
956
+ /*
957
+ * Document-method: read_double
958
+ * call-seq: memory.read_double
959
+ * @return [Float]
960
+ * Read a 64-bit float (double) from memory.
961
+ *
962
+ * Same as:
963
+ * memory.get_double(0)
964
+ */
965
+ rb_define_method(classMemory, "read_double", memory_read_float64, 0);
966
+ /*
967
+ * Document-method: put_array_of_float64
968
+ * call-seq: memory.put_array_of_float64(offset, ary)
969
+ * @param [Numeric] offset
970
+ * @param [Array<Numeric>] ary
971
+ * @return [self]
972
+ * Put values from +ary+ as 64-bit floats (doubles) in memory from offset +offset+ (alias: #put_array_of_double).
973
+ */
974
+ rb_define_method(classMemory, "put_array_of_float64", memory_put_array_of_float64, 2);
975
+ /*
976
+ * Document-method: get_array_of_float64
977
+ * call-seq: memory.get_array_of_float64(offset, length)
978
+ * @param [Numeric] offset
979
+ * @param [Numeric] length number of Float to get
980
+ * @return [Array<Float>]
981
+ * Get 64-bit floats (doubles) in memory from offset +offset+ (alias: #get_array_of_double).
982
+ */
983
+ rb_define_method(classMemory, "get_array_of_float64", memory_get_array_of_float64, 2);
984
+ /*
985
+ * Document-method: write_array_of_double
986
+ * call-seq: memory.write_array_of_double(ary)
987
+ * @param [Array<Numeric>] ary
988
+ * @return [self]
989
+ * Write values from +ary+ as 64-bit floats (doubles) in memory.
990
+ *
991
+ * Same as:
992
+ * memory.put_array_of_double(0, ary)
993
+ */
994
+ rb_define_method(classMemory, "write_array_of_double", memory_write_array_of_float64, 1);
995
+ /*
996
+ * Document-method: read_array_of_double
997
+ * call-seq: memory.read_array_of_double(length)
998
+ * @param [Numeric] length number of Float to read
999
+ * @return [Array<Float>]
1000
+ * Read 64-bit floats (doubles) from memory.
1001
+ *
1002
+ * Same as:
1003
+ * memory.get_array_of_double(0, ary)
1004
+ */
1005
+ rb_define_method(classMemory, "read_array_of_double", memory_read_array_of_float64, 1);
1006
+ rb_define_alias(classMemory, "put_array_of_double", "put_array_of_float64");
1007
+ rb_define_alias(classMemory, "get_array_of_double", "get_array_of_float64");
1008
+ /*
1009
+ * Document-method: put_pointer
1010
+ * call-seq: memory.put_pointer(offset, value)
1011
+ * @param [Numeric] offset
1012
+ * @param [nil,Pointer, Integer, #to_ptr] value
1013
+ * @return [self]
1014
+ * Put +value+ in memory from +offset+..
1015
+ */
1016
+ rb_define_method(classMemory, "put_pointer", memory_put_pointer, 2);
1017
+ /*
1018
+ * Document-method: get_pointer
1019
+ * call-seq: memory.get_pointer(offset)
1020
+ * @param [Numeric] offset
1021
+ * @return [Pointer]
1022
+ * Get a {Pointer} to the memory from +offset+.
1023
+ */
1024
+ rb_define_method(classMemory, "get_pointer", memory_get_pointer, 1);
1025
+ /*
1026
+ * Document-method: write_pointer
1027
+ * call-seq: memory.write_pointer(value)
1028
+ * @param [nil,Pointer, Integer, #to_ptr] value
1029
+ * @return [self]
1030
+ * Write +value+ in memory.
1031
+ *
1032
+ * Equivalent to:
1033
+ * memory.put_pointer(0, value)
1034
+ */
1035
+ rb_define_method(classMemory, "write_pointer", memory_write_pointer, 1);
1036
+ /*
1037
+ * Document-method: read_pointer
1038
+ * call-seq: memory.read_pointer
1039
+ * @return [Pointer]
1040
+ * Get a {Pointer} to the memory from base address.
1041
+ *
1042
+ * Equivalent to:
1043
+ * memory.get_pointer(0)
1044
+ */
1045
+ rb_define_method(classMemory, "read_pointer", memory_read_pointer, 0);
1046
+ /*
1047
+ * Document-method: put_array_of_pointer
1048
+ * call-seq: memory.put_array_of_pointer(offset, ary)
1049
+ * @param [Numeric] offset
1050
+ * @param [Array<#to_ptr>] ary
1051
+ * @return [self]
1052
+ * Put an array of {Pointer} into memory from +offset+.
1053
+ */
1054
+ rb_define_method(classMemory, "put_array_of_pointer", memory_put_array_of_pointer, 2);
1055
+ /*
1056
+ * Document-method: get_array_of_pointer
1057
+ * call-seq: memory.get_array_of_pointer(offset, length)
1058
+ * @param [Numeric] offset
1059
+ * @param [Numeric] length
1060
+ * @return [Array<Pointer>]
1061
+ * Get an array of {Pointer} of length +length+ from +offset+.
1062
+ */
1063
+ rb_define_method(classMemory, "get_array_of_pointer", memory_get_array_of_pointer, 2);
1064
+ /*
1065
+ * Document-method: write_array_of_pointer
1066
+ * call-seq: memory.write_array_of_pointer(ary)
1067
+ * @param [Array<#to_ptr>] ary
1068
+ * @return [self]
1069
+ * Write an array of {Pointer} into memory from +offset+.
1070
+ *
1071
+ * Same as :
1072
+ * memory.put_array_of_pointer(0, ary)
1073
+ */
1074
+ rb_define_method(classMemory, "write_array_of_pointer", memory_write_array_of_pointer, 1);
1075
+ /*
1076
+ * Document-method: read_array_of_pointer
1077
+ * call-seq: memory.read_array_of_pointer(length)
1078
+ * @param [Numeric] length
1079
+ * @return [Array<Pointer>]
1080
+ * Read an array of {Pointer} of length +length+.
1081
+ *
1082
+ * Same as:
1083
+ * memory.get_array_of_pointer(0, length)
1084
+ */
1085
+ rb_define_method(classMemory, "read_array_of_pointer", memory_read_array_of_pointer, 1);
1086
+
1087
+ rb_define_method(classMemory, "get_string", memory_get_string, -1);
1088
+ rb_define_method(classMemory, "put_string", memory_put_string, 2);
1089
+ rb_define_method(classMemory, "get_bytes", memory_get_bytes, 2);
1090
+ rb_define_method(classMemory, "put_bytes", memory_put_bytes, -1);
1091
+ rb_define_method(classMemory, "read_bytes", memory_read_bytes, 1);
1092
+ rb_define_method(classMemory, "write_bytes", memory_write_bytes, -1);
1093
+ rb_define_method(classMemory, "get_array_of_string", memory_get_array_of_string, -1);
1094
+
1095
+ rb_define_method(classMemory, "get", memory_get, 2);
1096
+ rb_define_method(classMemory, "put", memory_put, 3);
1097
+
1098
+ rb_define_method(classMemory, "clear", memory_clear, 0);
1099
+ rb_define_method(classMemory, "total", memory_size, 0);
1100
+ rb_define_alias(classMemory, "size", "total");
1101
+ rb_define_method(classMemory, "type_size", memory_type_size, 0);
1102
+ rb_define_method(classMemory, "[]", memory_aref, 1);
1103
+ rb_define_method(classMemory, "__copy_from__", memory_copy_from, 2);
1104
+
1105
+ id_to_ptr = rb_intern("to_ptr");
1106
+ id_call = rb_intern("call");
1107
+ id_plus = rb_intern("+");
1108
+ }
1109
+