ffi 1.9.3-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

Files changed (436) hide show
  1. data/COPYING +49 -0
  2. data/LICENSE +24 -0
  3. data/README.md +109 -0
  4. data/Rakefile +220 -0
  5. data/ext/ffi_c/AbstractMemory.c +1032 -0
  6. data/ext/ffi_c/AbstractMemory.h +175 -0
  7. data/ext/ffi_c/ArrayType.c +162 -0
  8. data/ext/ffi_c/ArrayType.h +59 -0
  9. data/ext/ffi_c/Buffer.c +365 -0
  10. data/ext/ffi_c/Call.c +465 -0
  11. data/ext/ffi_c/Call.h +93 -0
  12. data/ext/ffi_c/ClosurePool.c +283 -0
  13. data/ext/ffi_c/ClosurePool.h +57 -0
  14. data/ext/ffi_c/DataConverter.c +91 -0
  15. data/ext/ffi_c/DynamicLibrary.c +333 -0
  16. data/ext/ffi_c/DynamicLibrary.h +49 -0
  17. data/ext/ffi_c/Function.c +999 -0
  18. data/ext/ffi_c/Function.h +87 -0
  19. data/ext/ffi_c/FunctionInfo.c +271 -0
  20. data/ext/ffi_c/LastError.c +184 -0
  21. data/ext/ffi_c/LastError.h +47 -0
  22. data/ext/ffi_c/LongDouble.c +63 -0
  23. data/ext/ffi_c/LongDouble.h +51 -0
  24. data/ext/ffi_c/MappedType.c +168 -0
  25. data/ext/ffi_c/MappedType.h +59 -0
  26. data/ext/ffi_c/MemoryPointer.c +197 -0
  27. data/ext/ffi_c/MemoryPointer.h +53 -0
  28. data/ext/ffi_c/MethodHandle.c +360 -0
  29. data/ext/ffi_c/MethodHandle.h +55 -0
  30. data/ext/ffi_c/Platform.c +121 -0
  31. data/ext/ffi_c/Platform.h +45 -0
  32. data/ext/ffi_c/Pointer.c +508 -0
  33. data/ext/ffi_c/Pointer.h +63 -0
  34. data/ext/ffi_c/Struct.c +828 -0
  35. data/ext/ffi_c/Struct.h +106 -0
  36. data/ext/ffi_c/StructByReference.c +190 -0
  37. data/ext/ffi_c/StructByReference.h +50 -0
  38. data/ext/ffi_c/StructByValue.c +150 -0
  39. data/ext/ffi_c/StructByValue.h +55 -0
  40. data/ext/ffi_c/StructLayout.c +698 -0
  41. data/ext/ffi_c/Thread.c +352 -0
  42. data/ext/ffi_c/Thread.h +95 -0
  43. data/ext/ffi_c/Type.c +397 -0
  44. data/ext/ffi_c/Type.h +62 -0
  45. data/ext/ffi_c/Types.c +139 -0
  46. data/ext/ffi_c/Types.h +89 -0
  47. data/ext/ffi_c/Variadic.c +276 -0
  48. data/ext/ffi_c/compat.h +83 -0
  49. data/ext/ffi_c/extconf.rb +64 -0
  50. data/ext/ffi_c/ffi.c +98 -0
  51. data/ext/ffi_c/libffi.bsd.mk +34 -0
  52. data/ext/ffi_c/libffi.darwin.mk +95 -0
  53. data/ext/ffi_c/libffi.gnu.mk +31 -0
  54. data/ext/ffi_c/libffi.mk +13 -0
  55. data/ext/ffi_c/libffi.vc.mk +26 -0
  56. data/ext/ffi_c/libffi.vc64.mk +26 -0
  57. data/ext/ffi_c/libffi/ChangeLog +4600 -0
  58. data/ext/ffi_c/libffi/ChangeLog.libffi +584 -0
  59. data/ext/ffi_c/libffi/ChangeLog.libgcj +40 -0
  60. data/ext/ffi_c/libffi/ChangeLog.v1 +764 -0
  61. data/ext/ffi_c/libffi/LICENSE +21 -0
  62. data/ext/ffi_c/libffi/Makefile.am +196 -0
  63. data/ext/ffi_c/libffi/Makefile.in +1820 -0
  64. data/ext/ffi_c/libffi/Makefile.vc +141 -0
  65. data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
  66. data/ext/ffi_c/libffi/README +342 -0
  67. data/ext/ffi_c/libffi/acinclude.m4 +92 -0
  68. data/ext/ffi_c/libffi/aclocal.m4 +1873 -0
  69. data/ext/ffi_c/libffi/build-ios.sh +67 -0
  70. data/ext/ffi_c/libffi/compile +143 -0
  71. data/ext/ffi_c/libffi/config.guess +1501 -0
  72. data/ext/ffi_c/libffi/config.sub +1705 -0
  73. data/ext/ffi_c/libffi/configure +17191 -0
  74. data/ext/ffi_c/libffi/configure.ac +496 -0
  75. data/ext/ffi_c/libffi/configure.host +11 -0
  76. data/ext/ffi_c/libffi/depcomp +630 -0
  77. data/ext/ffi_c/libffi/doc/libffi.info +593 -0
  78. data/ext/ffi_c/libffi/doc/libffi.texi +600 -0
  79. data/ext/ffi_c/libffi/doc/stamp-vti +4 -0
  80. data/ext/ffi_c/libffi/doc/version.texi +4 -0
  81. data/ext/ffi_c/libffi/fficonfig.h.in +199 -0
  82. data/ext/ffi_c/libffi/fficonfig.hw +57 -0
  83. data/ext/ffi_c/libffi/include/Makefile.am +9 -0
  84. data/ext/ffi_c/libffi/include/Makefile.in +487 -0
  85. data/ext/ffi_c/libffi/include/ffi.h.in +427 -0
  86. data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
  87. data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
  88. data/ext/ffi_c/libffi/include/ffi_common.h +126 -0
  89. data/ext/ffi_c/libffi/install-sh +520 -0
  90. data/ext/ffi_c/libffi/libffi.pc.in +10 -0
  91. data/ext/ffi_c/libffi/libtool-version +29 -0
  92. data/ext/ffi_c/libffi/ltmain.sh +9636 -0
  93. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
  94. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
  95. data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
  96. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
  97. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
  98. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
  99. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
  100. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
  101. data/ext/ffi_c/libffi/m4/libtool.m4 +7831 -0
  102. data/ext/ffi_c/libffi/m4/ltoptions.m4 +369 -0
  103. data/ext/ffi_c/libffi/m4/ltsugar.m4 +123 -0
  104. data/ext/ffi_c/libffi/m4/ltversion.m4 +23 -0
  105. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +98 -0
  106. data/ext/ffi_c/libffi/man/Makefile.am +8 -0
  107. data/ext/ffi_c/libffi/man/Makefile.in +466 -0
  108. data/ext/ffi_c/libffi/man/ffi.3 +31 -0
  109. data/ext/ffi_c/libffi/man/ffi_call.3 +103 -0
  110. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +66 -0
  111. data/ext/ffi_c/libffi/mdate-sh +201 -0
  112. data/ext/ffi_c/libffi/missing +376 -0
  113. data/ext/ffi_c/libffi/msvcc.sh +197 -0
  114. data/ext/ffi_c/libffi/src/alpha/ffi.c +284 -0
  115. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +48 -0
  116. data/ext/ffi_c/libffi/src/alpha/osf.S +387 -0
  117. data/ext/ffi_c/libffi/src/arm/ffi.c +728 -0
  118. data/ext/ffi_c/libffi/src/arm/ffitarget.h +65 -0
  119. data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
  120. data/ext/ffi_c/libffi/src/arm/sysv.S +497 -0
  121. data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
  122. data/ext/ffi_c/libffi/src/avr32/ffi.c +423 -0
  123. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +50 -0
  124. data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
  125. data/ext/ffi_c/libffi/src/closures.c +615 -0
  126. data/ext/ffi_c/libffi/src/cris/ffi.c +383 -0
  127. data/ext/ffi_c/libffi/src/cris/ffitarget.h +51 -0
  128. data/ext/ffi_c/libffi/src/cris/sysv.S +215 -0
  129. data/ext/ffi_c/libffi/src/debug.c +59 -0
  130. data/ext/ffi_c/libffi/src/dlmalloc.c +5161 -0
  131. data/ext/ffi_c/libffi/src/frv/eabi.S +128 -0
  132. data/ext/ffi_c/libffi/src/frv/ffi.c +292 -0
  133. data/ext/ffi_c/libffi/src/frv/ffitarget.h +57 -0
  134. data/ext/ffi_c/libffi/src/ia64/ffi.c +582 -0
  135. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +50 -0
  136. data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +40 -0
  137. data/ext/ffi_c/libffi/src/ia64/unix.S +560 -0
  138. data/ext/ffi_c/libffi/src/java_raw_api.c +356 -0
  139. data/ext/ffi_c/libffi/src/m32r/ffi.c +232 -0
  140. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +48 -0
  141. data/ext/ffi_c/libffi/src/m32r/sysv.S +121 -0
  142. data/ext/ffi_c/libffi/src/m68k/ffi.c +288 -0
  143. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +49 -0
  144. data/ext/ffi_c/libffi/src/m68k/sysv.S +270 -0
  145. data/ext/ffi_c/libffi/src/mips/ffi.c +1036 -0
  146. data/ext/ffi_c/libffi/src/mips/ffitarget.h +242 -0
  147. data/ext/ffi_c/libffi/src/mips/n32.S +591 -0
  148. data/ext/ffi_c/libffi/src/mips/o32.S +381 -0
  149. data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
  150. data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
  151. data/ext/ffi_c/libffi/src/pa/ffi.c +719 -0
  152. data/ext/ffi_c/libffi/src/pa/ffitarget.h +78 -0
  153. data/ext/ffi_c/libffi/src/pa/hpux32.S +368 -0
  154. data/ext/ffi_c/libffi/src/pa/linux.S +357 -0
  155. data/ext/ffi_c/libffi/src/powerpc/aix.S +328 -0
  156. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +445 -0
  157. data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
  158. data/ext/ffi_c/libffi/src/powerpc/darwin.S +383 -0
  159. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +575 -0
  160. data/ext/ffi_c/libffi/src/powerpc/ffi.c +1448 -0
  161. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +1359 -0
  162. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +139 -0
  163. data/ext/ffi_c/libffi/src/powerpc/linux64.S +187 -0
  164. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +236 -0
  165. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +327 -0
  166. data/ext/ffi_c/libffi/src/powerpc/sysv.S +219 -0
  167. data/ext/ffi_c/libffi/src/prep_cif.c +177 -0
  168. data/ext/ffi_c/libffi/src/raw_api.c +254 -0
  169. data/ext/ffi_c/libffi/src/s390/ffi.c +780 -0
  170. data/ext/ffi_c/libffi/src/s390/ffitarget.h +62 -0
  171. data/ext/ffi_c/libffi/src/s390/sysv.S +434 -0
  172. data/ext/ffi_c/libffi/src/sh/ffi.c +716 -0
  173. data/ext/ffi_c/libffi/src/sh/ffitarget.h +49 -0
  174. data/ext/ffi_c/libffi/src/sh/sysv.S +850 -0
  175. data/ext/ffi_c/libffi/src/sh64/ffi.c +468 -0
  176. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +53 -0
  177. data/ext/ffi_c/libffi/src/sh64/sysv.S +539 -0
  178. data/ext/ffi_c/libffi/src/sparc/ffi.c +669 -0
  179. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +68 -0
  180. data/ext/ffi_c/libffi/src/sparc/v8.S +313 -0
  181. data/ext/ffi_c/libffi/src/sparc/v9.S +307 -0
  182. data/ext/ffi_c/libffi/src/types.c +77 -0
  183. data/ext/ffi_c/libffi/src/x86/darwin.S +444 -0
  184. data/ext/ffi_c/libffi/src/x86/darwin64.S +416 -0
  185. data/ext/ffi_c/libffi/src/x86/ffi.c +644 -0
  186. data/ext/ffi_c/libffi/src/x86/ffi64.c +635 -0
  187. data/ext/ffi_c/libffi/src/x86/ffitarget.h +121 -0
  188. data/ext/ffi_c/libffi/src/x86/freebsd.S +458 -0
  189. data/ext/ffi_c/libffi/src/x86/sysv.S +468 -0
  190. data/ext/ffi_c/libffi/src/x86/unix64.S +426 -0
  191. data/ext/ffi_c/libffi/src/x86/win32.S +1065 -0
  192. data/ext/ffi_c/libffi/src/x86/win64.S +468 -0
  193. data/ext/ffi_c/libffi/testsuite/Makefile.am +80 -0
  194. data/ext/ffi_c/libffi/testsuite/Makefile.in +500 -0
  195. data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
  196. data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +300 -0
  197. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
  198. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +263 -0
  199. data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +45 -0
  200. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +32 -0
  201. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +89 -0
  202. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +81 -0
  203. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +81 -0
  204. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +82 -0
  205. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +89 -0
  206. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +92 -0
  207. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +90 -0
  208. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
  209. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_stdcall.c +64 -0
  210. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +94 -0
  211. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +95 -0
  212. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +96 -0
  213. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +102 -0
  214. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +89 -0
  215. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +91 -0
  216. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +93 -0
  217. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +113 -0
  218. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +90 -0
  219. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +95 -0
  220. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +90 -0
  221. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +90 -0
  222. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +98 -0
  223. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +90 -0
  224. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +109 -0
  225. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +98 -0
  226. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +124 -0
  227. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +113 -0
  228. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +99 -0
  229. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +117 -0
  230. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +97 -0
  231. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +88 -0
  232. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +90 -0
  233. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +91 -0
  234. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +93 -0
  235. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +91 -0
  236. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +92 -0
  237. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +134 -0
  238. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +117 -0
  239. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +95 -0
  240. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +91 -0
  241. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +91 -0
  242. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +92 -0
  243. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +91 -0
  244. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +91 -0
  245. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +93 -0
  246. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
  247. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +43 -0
  248. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +60 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +42 -0
  250. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
  251. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +60 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +74 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +74 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +86 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +91 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +74 -0
  257. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +86 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +140 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +44 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +42 -0
  262. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +42 -0
  263. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +42 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +43 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +47 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +43 -0
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +36 -0
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +26 -0
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +153 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +59 -0
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +58 -0
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +58 -0
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +72 -0
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +62 -0
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +342 -0
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +69 -0
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +63 -0
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +53 -0
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +152 -0
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +161 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +133 -0
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +110 -0
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +111 -0
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +111 -0
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +112 -0
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +131 -0
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +111 -0
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +131 -0
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +131 -0
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +90 -0
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +59 -0
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +114 -0
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +35 -0
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +43 -0
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +42 -0
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +35 -0
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +36 -0
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +49 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +42 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +34 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +41 -0
  302. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +43 -0
  303. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +36 -0
  304. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +38 -0
  305. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +38 -0
  306. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +38 -0
  307. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
  308. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
  309. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
  310. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +125 -0
  311. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +44 -0
  312. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +44 -0
  313. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +65 -0
  314. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +67 -0
  315. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +59 -0
  316. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +63 -0
  317. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +65 -0
  318. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +64 -0
  319. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +74 -0
  320. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +80 -0
  321. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +67 -0
  322. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
  323. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +96 -0
  324. data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +35 -0
  325. data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +124 -0
  326. data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc +53 -0
  327. data/ext/ffi_c/libffi/texinfo.tex +7210 -0
  328. data/ext/ffi_c/rbffi.h +57 -0
  329. data/ext/ffi_c/rbffi_endian.h +59 -0
  330. data/ext/ffi_c/win32/stdbool.h +8 -0
  331. data/ext/ffi_c/win32/stdint.h +201 -0
  332. data/ffi.gemspec +22 -0
  333. data/gen/Rakefile +30 -0
  334. data/lib/ffi.rb +28 -0
  335. data/lib/ffi/autopointer.rb +194 -0
  336. data/lib/ffi/buffer.rb +4 -0
  337. data/lib/ffi/callback.rb +4 -0
  338. data/lib/ffi/enum.rb +173 -0
  339. data/lib/ffi/errno.rb +43 -0
  340. data/lib/ffi/ffi.rb +44 -0
  341. data/lib/ffi/io.rb +62 -0
  342. data/lib/ffi/library.rb +499 -0
  343. data/lib/ffi/managedstruct.rb +84 -0
  344. data/lib/ffi/memorypointer.rb +1 -0
  345. data/lib/ffi/platform.rb +148 -0
  346. data/lib/ffi/platform/arm-linux/types.conf +104 -0
  347. data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  348. data/lib/ffi/platform/i386-darwin/types.conf +100 -0
  349. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  350. data/lib/ffi/platform/i386-gnu/types.conf +107 -0
  351. data/lib/ffi/platform/i386-linux/types.conf +103 -0
  352. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  353. data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
  354. data/lib/ffi/platform/i386-solaris/types.conf +122 -0
  355. data/lib/ffi/platform/i386-windows/types.conf +105 -0
  356. data/lib/ffi/platform/ia64-linux/types.conf +104 -0
  357. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  358. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  359. data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
  360. data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
  361. data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  362. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  363. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  364. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  365. data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
  366. data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
  367. data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
  368. data/lib/ffi/platform/x86_64-darwin/types.conf +100 -0
  369. data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
  370. data/lib/ffi/platform/x86_64-linux/types.conf +102 -0
  371. data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
  372. data/lib/ffi/platform/x86_64-openbsd/types.conf +128 -0
  373. data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
  374. data/lib/ffi/platform/x86_64-windows/types.conf +27 -0
  375. data/lib/ffi/pointer.rb +134 -0
  376. data/lib/ffi/struct.rb +367 -0
  377. data/lib/ffi/struct_layout_builder.rb +222 -0
  378. data/lib/ffi/tools/const_generator.rb +229 -0
  379. data/lib/ffi/tools/generator.rb +60 -0
  380. data/lib/ffi/tools/generator_task.rb +36 -0
  381. data/lib/ffi/tools/struct_generator.rb +194 -0
  382. data/lib/ffi/tools/types_generator.rb +135 -0
  383. data/lib/ffi/types.rb +190 -0
  384. data/lib/ffi/union.rb +43 -0
  385. data/lib/ffi/variadic.rb +78 -0
  386. data/lib/ffi/version.rb +4 -0
  387. data/lib/ffi_c.so +0 -0
  388. data/libtest/Benchmark.c +52 -0
  389. data/libtest/BoolTest.c +34 -0
  390. data/libtest/BufferTest.c +31 -0
  391. data/libtest/ClosureTest.c +190 -0
  392. data/libtest/EnumTest.c +34 -0
  393. data/libtest/FunctionTest.c +58 -0
  394. data/libtest/GNUmakefile +149 -0
  395. data/libtest/GlobalVariable.c +62 -0
  396. data/libtest/LastErrorTest.c +21 -0
  397. data/libtest/NumberTest.c +132 -0
  398. data/libtest/PointerTest.c +63 -0
  399. data/libtest/ReferenceTest.c +23 -0
  400. data/libtest/StringTest.c +34 -0
  401. data/libtest/StructTest.c +243 -0
  402. data/libtest/UnionTest.c +43 -0
  403. data/libtest/VariadicTest.c +62 -0
  404. data/spec/ffi/async_callback_spec.rb +35 -0
  405. data/spec/ffi/bool_spec.rb +29 -0
  406. data/spec/ffi/buffer_spec.rb +251 -0
  407. data/spec/ffi/callback_spec.rb +667 -0
  408. data/spec/ffi/custom_param_type.rb +36 -0
  409. data/spec/ffi/custom_type_spec.rb +74 -0
  410. data/spec/ffi/dup_spec.rb +54 -0
  411. data/spec/ffi/enum_spec.rb +220 -0
  412. data/spec/ffi/errno_spec.rb +18 -0
  413. data/spec/ffi/ffi_spec.rb +29 -0
  414. data/spec/ffi/function_spec.rb +76 -0
  415. data/spec/ffi/library_spec.rb +216 -0
  416. data/spec/ffi/long_double.rb +30 -0
  417. data/spec/ffi/managed_struct_spec.rb +57 -0
  418. data/spec/ffi/number_spec.rb +236 -0
  419. data/spec/ffi/pointer_spec.rb +265 -0
  420. data/spec/ffi/rbx/attach_function_spec.rb +28 -0
  421. data/spec/ffi/rbx/memory_pointer_spec.rb +123 -0
  422. data/spec/ffi/rbx/spec_helper.rb +1 -0
  423. data/spec/ffi/rbx/struct_spec.rb +13 -0
  424. data/spec/ffi/spec_helper.rb +33 -0
  425. data/spec/ffi/string_spec.rb +108 -0
  426. data/spec/ffi/strptr_spec.rb +50 -0
  427. data/spec/ffi/struct_by_ref_spec.rb +43 -0
  428. data/spec/ffi/struct_callback_spec.rb +69 -0
  429. data/spec/ffi/struct_initialize_spec.rb +35 -0
  430. data/spec/ffi/struct_packed_spec.rb +51 -0
  431. data/spec/ffi/struct_spec.rb +748 -0
  432. data/spec/ffi/typedef_spec.rb +78 -0
  433. data/spec/ffi/union_spec.rb +65 -0
  434. data/spec/ffi/variadic_spec.rb +92 -0
  435. data/spec/spec.opts +4 -0
  436. metadata +562 -0
data/COPYING ADDED
@@ -0,0 +1,49 @@
1
+ Copyright (c) 2008-2013, Ruby FFI project contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the Ruby FFI project nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
26
+ libffi, used by this project, is licensed under the MIT license:
27
+
28
+ libffi - Copyright (c) 1996-2011 Anthony Green, Red Hat, Inc and others.
29
+ See source files for details.
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ ``Software''), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
+
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2008-2013, Ruby FFI project contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the Ruby FFI project nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # ruby-ffi https://wiki.github.com/ffi/ffi [![Build Status](https://travis-ci.org/ffi/ffi.png?branch=master)](https://travis-ci.org/ffi/ffi)
2
+
3
+ ## Description
4
+
5
+ Ruby-FFI is a ruby extension for programmatically loading dynamic
6
+ libraries, binding functions within them, and calling those functions
7
+ from Ruby code. Moreover, a Ruby-FFI extension works without changes
8
+ on Ruby and JRuby. [Discover why you should write your next extension
9
+ using Ruby-FFI](https://wiki.github.com/ffi/ffi/why-use-ffi).
10
+
11
+ ## Features/problems
12
+
13
+ * Intuitive DSL
14
+ * Supports all C native types
15
+ * C structs (also nested), enums and global variables
16
+ * Callbacks from C to ruby
17
+ * Automatic garbage collection of native memory
18
+
19
+ ## Synopsis
20
+
21
+ ```ruby
22
+ require 'ffi'
23
+
24
+ module MyLib
25
+ extend FFI::Library
26
+ ffi_lib 'c'
27
+ attach_function :puts, [ :string ], :int
28
+ end
29
+
30
+ MyLib.puts 'Hello, World using libc!'
31
+ ```
32
+
33
+ For less minimalistic and more sane examples you may look at:
34
+
35
+ * the samples/ folder
36
+ * the examples on the [wiki](https://wiki.github.com/ffi/ffi)
37
+ * the projects using FFI listed on this page (https://wiki.github.com/ffi/ffi/projects-using-ffi)
38
+
39
+ ## Requirements
40
+
41
+ You need a sane building environment in order to compile the extension.
42
+ At a minimum, you will need:
43
+ * A C compiler (e.g. Xcode on OSX, gcc on everything else)
44
+ * libffi development library - this is commonly in the libffi-dev or libffi-devel
45
+
46
+ ## Installation
47
+
48
+ From rubygems:
49
+
50
+ [sudo] gem install ffi
51
+
52
+ or from the git repository on github:
53
+
54
+ git clone git://github.com/ffi/ffi.git
55
+ cd ffi
56
+ rake gem:install
57
+
58
+ ## License
59
+
60
+ The ffi library is covered by the BSD license, also see the LICENSE file.
61
+ The specs are shared with Rubyspec and are licensed by the same license
62
+ as Rubyspec, see the LICENSE.SPECS file.
63
+
64
+ ## Credits
65
+
66
+ The following people have submitted code, bug reports, or otherwide contributed to the success of this project:
67
+
68
+ * Alban Peignier <alban.peignier@free.fr>
69
+ * Aman Gupta <aman@tmm1.net>
70
+ * Andrea Fazzi <andrea.fazzi@alcacoop.it>
71
+ * Andreas Niederl <rico32@gmx.net>
72
+ * Andrew Cholakian <andrew@andrewvc.com>
73
+ * Antonio Terceiro <terceiro@softwarelivre.org>
74
+ * Brian Candler <B.Candler@pobox.com>
75
+ * Brian D. Burns <burns180@gmail.com>
76
+ * Bryan Kearney <bkearney@redhat.com>
77
+ * Charlie Savage <cfis@zerista.com>
78
+ * Chikanaga Tomoyuki <nagachika00@gmail.com>
79
+ * Hongli Lai <hongli@phusion.nl>
80
+ * Ian MacLeod <ian@nevir.net>
81
+ * Jake Douglas <jake@shiftedlabs.com>
82
+ * Jean-Dominique Morani <jdmorani@mac.com>
83
+ * Jeremy Hinegardner <jeremy@hinegardner.org>
84
+ * Jesús García Sáez <blaxter@gmail.com>
85
+ * Joe Khoobyar <joe@ankhcraft.com>
86
+ * Jurij Smakov <jurij@wooyd.org>
87
+ * KISHIMOTO, Makoto <ksmakoto@dd.iij4u.or.jp>
88
+ * Kim Burgestrand <kim@burgestrand.se>
89
+ * Lars Kanis <kanis@comcard.de>
90
+ * Luc Heinrich <luc@honk-honk.com>
91
+ * Luis Lavena <luislavena@gmail.com>
92
+ * Matijs van Zuijlen <matijs@matijs.net>
93
+ * Matthew King <automatthew@gmail.com>
94
+ * Mike Dalessio <mike.dalessio@gmail.com>
95
+ * NARUSE, Yui <naruse@airemix.jp>
96
+ * Park Heesob <phasis@gmail.com>
97
+ * Shin Yee <shinyee@speedgocomputing.com>
98
+ * Stephen Bannasch <stephen.bannasch@gmail.com>
99
+ * Suraj N. Kurapati <sunaku@gmail.com>
100
+ * Sylvain Daubert <sylvain.daubert@laposte.net>
101
+ * Victor Costan
102
+ * beoran@gmail.com
103
+ * ctide <christide@christide.com>
104
+ * emboss <Martin.Bosslet@googlemail.com>
105
+ * hobophobe <unusualtears@gmail.com>
106
+ * meh <meh@paranoici.org>
107
+ * postmodern <postmodern.mod3@gmail.com>
108
+ * wycats@gmail.com <wycats@gmail.com>
109
+ * Wayne Meissner <wmeissner@gmail.com>
data/Rakefile ADDED
@@ -0,0 +1,220 @@
1
+ require 'rubygems'
2
+ require 'rubygems/package_task'
3
+ require 'rubygems/tasks'
4
+ require 'rbconfig'
5
+ require 'rake/clean'
6
+
7
+ USE_RAKE_COMPILER = (RUBY_PLATFORM =~ /java/) ? false : true
8
+ if USE_RAKE_COMPILER
9
+ gem 'rake-compiler', '>=0.6.0'
10
+ require 'rake/extensiontask'
11
+ end
12
+
13
+ require 'date'
14
+ require 'fileutils'
15
+ require 'rbconfig'
16
+
17
+
18
+ LIBEXT = case RbConfig::CONFIG['host_os'].downcase
19
+ when /darwin/
20
+ "dylib"
21
+ when /mswin|mingw/
22
+ "dll"
23
+ else
24
+ RbConfig::CONFIG['DLEXT']
25
+ end
26
+
27
+ CPU = case RbConfig::CONFIG['host_cpu'].downcase
28
+ when /i[3456]86/
29
+ # Darwin always reports i686, even when running in 64bit mode
30
+ if RbConfig::CONFIG['host_os'] =~ /darwin/ && 0xfee1deadbeef.is_a?(Fixnum)
31
+ "x86_64"
32
+ else
33
+ "i386"
34
+ end
35
+
36
+ when /amd64|x86_64/
37
+ "x86_64"
38
+
39
+ when /ppc64|powerpc64/
40
+ "powerpc64"
41
+
42
+ when /ppc|powerpc/
43
+ "powerpc"
44
+
45
+ when /^arm/
46
+ "arm"
47
+
48
+ else
49
+ RbConfig::CONFIG['host_cpu']
50
+ end
51
+
52
+ OS = case RbConfig::CONFIG['host_os'].downcase
53
+ when /linux/
54
+ "linux"
55
+ when /darwin/
56
+ "darwin"
57
+ when /freebsd/
58
+ "freebsd"
59
+ when /openbsd/
60
+ "openbsd"
61
+ when /sunos|solaris/
62
+ "solaris"
63
+ when /mswin|mingw/
64
+ "win32"
65
+ else
66
+ RbConfig::CONFIG['host_os'].downcase
67
+ end
68
+
69
+ GMAKE = system('which gmake >/dev/null') && 'gmake' || 'make'
70
+
71
+ LIBTEST = "build/libtest.#{LIBEXT}"
72
+ BUILD_DIR = "build"
73
+ BUILD_EXT_DIR = File.join(BUILD_DIR, "#{RbConfig::CONFIG['arch']}", 'ffi_c', RUBY_VERSION)
74
+
75
+ def gem_spec
76
+ @gem_spec ||= Gem::Specification.load('ffi.gemspec')
77
+ end
78
+
79
+ TEST_DEPS = [ LIBTEST ]
80
+ if RUBY_PLATFORM == "java"
81
+ desc "Run all specs"
82
+ task :specs => TEST_DEPS do
83
+ sh %{#{Gem.ruby} -w -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
84
+ end
85
+ desc "Run rubinius specs"
86
+ task :rbxspecs => TEST_DEPS do
87
+ sh %{#{Gem.ruby} -w -S rspec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
88
+ end
89
+ else
90
+ TEST_DEPS.unshift :compile
91
+ desc "Run all specs"
92
+ task :specs => TEST_DEPS do
93
+ ENV["MRI_FFI"] = "1"
94
+ sh %{#{Gem.ruby} -w -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
95
+ end
96
+ desc "Run rubinius specs"
97
+ task :rbxspecs => TEST_DEPS do
98
+ ENV["MRI_FFI"] = "1"
99
+ sh %{#{Gem.ruby} -w -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
100
+ end
101
+ end
102
+
103
+ desc "Build all packages"
104
+ task :package => 'gem:package'
105
+
106
+
107
+ CLOBBER.include 'build'
108
+ CLOBBER.include FileList['lib/**/ffi_c.so']
109
+ CLOBBER.include FileList["lib/**/ffi_c.#{RbConfig::CONFIG['DLEXT']}"]
110
+ CLOBBER.include 'lib/ffi/types.conf'
111
+ CLOBBER.include 'conftest.dSYM'
112
+ CLOBBER.include 'pkg'
113
+
114
+ task :distclean => :clobber
115
+
116
+ desc "Build the native test lib"
117
+ file "build/libtest.#{LIBEXT}" => FileList['libtest/**/*.[ch]'] do
118
+ sh %{#{GMAKE} -f libtest/GNUmakefile CPU=#{CPU} OS=#{OS} }
119
+ end
120
+
121
+
122
+ desc "Build test helper lib"
123
+ task :libtest => "build/libtest.#{LIBEXT}"
124
+
125
+ desc "Test the extension"
126
+ task :test => [ :specs, :rbxspecs ]
127
+
128
+
129
+ namespace :bench do
130
+ ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000
131
+ bench_libs = "-Ilib -I#{BUILD_DIR}" unless RUBY_PLATFORM == "java"
132
+ bench_files = Dir["bench/bench_*.rb"].reject { |f| f == "bench_helper.rb" }
133
+ bench_files.each do |bench|
134
+ task File.basename(bench, ".rb")[6..-1] => TEST_DEPS do
135
+ sh %{#{Gem.ruby} #{bench_libs} #{bench} #{ITER}}
136
+ end
137
+ end
138
+ task :all => TEST_DEPS do
139
+ bench_files.each do |bench|
140
+ sh %{#{Gem.ruby} #{bench_libs} #{bench}}
141
+ end
142
+ end
143
+ end
144
+
145
+ task 'spec:run' => TEST_DEPS
146
+ task 'spec:specdoc' => TEST_DEPS
147
+
148
+ task :default => :specs
149
+
150
+ task 'gem:win32' do
151
+ sh("rake cross native gem RUBY_CC_VERSION='1.8.7:1.9.3:2.0.0'") || raise("win32 build failed!")
152
+ end
153
+
154
+
155
+ namespace 'java' do
156
+
157
+ java_gem_spec = Gem::Specification.new do |s|
158
+ s.name = gem_spec.name
159
+ s.version = gem_spec.version
160
+ s.author = gem_spec.author
161
+ s.email = gem_spec.email
162
+ s.homepage = gem_spec.homepage
163
+ s.summary = gem_spec.summary
164
+ s.description = gem_spec.description
165
+ s.files = %w(History.txt LICENSE COPYING COPYING.LESSER README.md Rakefile)
166
+ s.has_rdoc = false
167
+ s.license = gem_spec.license
168
+ s.platform = 'java'
169
+ end
170
+
171
+ Gem::PackageTask.new(java_gem_spec) do |pkg|
172
+ pkg.need_zip = true
173
+ pkg.need_tar = true
174
+ pkg.package_dir = 'pkg'
175
+ end
176
+ end
177
+
178
+ task 'gem:java' => 'java:gem'
179
+
180
+
181
+ if USE_RAKE_COMPILER
182
+ Rake::ExtensionTask.new('ffi_c', gem_spec) do |ext|
183
+ ext.name = 'ffi_c' # indicate the name of the extension.
184
+ # ext.lib_dir = BUILD_DIR # put binaries into this folder.
185
+ ext.tmp_dir = BUILD_DIR # temporary folder used during compilation.
186
+ ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
187
+ ext.cross_platform = %w[i386-mingw32 x64-mingw32] # forces the Windows platform instead of the default one
188
+ end
189
+
190
+ ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
191
+ task "copy:ffi_c:i386-mingw32:#{ruby_version}" do |t|
192
+ %w[lib #{BUILD_DIR}/i386-mingw32/stage/lib].each do |dir|
193
+ if File.exists?("#{dir}/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so")
194
+ sh "i686-w64-mingw32-strip -S #{dir}/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
195
+ end
196
+ end
197
+ end
198
+
199
+ task "copy:ffi_c:x64-mingw32:#{ruby_version}" do |t|
200
+ if File.exists?("#{BUILD_DIR}/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so")
201
+ sh "x86_64-w64-mingw32-strip -S #{BUILD_DIR}/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
202
+ end
203
+ end
204
+ end
205
+ end
206
+
207
+ Gem::Tasks.new do |t|
208
+ t.scm.tag.format = '%s'
209
+ end
210
+
211
+ begin
212
+ require 'yard'
213
+
214
+ namespace :doc do
215
+ YARD::Rake::YardocTask.new do |yard|
216
+ end
217
+ end
218
+ rescue LoadError
219
+ warn "[warn] YARD unavailable"
220
+ end
@@ -0,0 +1,1032 @@
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
+
53
+ static inline char* memory_address(VALUE self);
54
+ VALUE rbffi_AbstractMemoryClass = Qnil;
55
+ static VALUE NullPointerErrorClass = Qnil;
56
+ static ID id_to_ptr = 0, id_plus = 0, id_call = 0;
57
+
58
+ static VALUE
59
+ memory_allocate(VALUE klass)
60
+ {
61
+ AbstractMemory* memory;
62
+ VALUE obj;
63
+ obj = Data_Make_Struct(klass, AbstractMemory, NULL, -1, memory);
64
+ memory->flags = MEM_RD | MEM_WR;
65
+
66
+ return obj;
67
+ }
68
+ #define VAL(x, swap) (unlikely(((memory->flags & MEM_SWAP) != 0)) ? swap((x)) : (x))
69
+
70
+ #define NUM_OP(name, type, toNative, fromNative, swap) \
71
+ static void memory_op_put_##name(AbstractMemory* memory, long off, VALUE value); \
72
+ static void \
73
+ memory_op_put_##name(AbstractMemory* memory, long off, VALUE value) \
74
+ { \
75
+ type tmp = (type) VAL(toNative(value), swap); \
76
+ checkWrite(memory); \
77
+ checkBounds(memory, off, sizeof(type)); \
78
+ memcpy(memory->address + off, &tmp, sizeof(tmp)); \
79
+ } \
80
+ static VALUE memory_put_##name(VALUE self, VALUE offset, VALUE value); \
81
+ static VALUE \
82
+ memory_put_##name(VALUE self, VALUE offset, VALUE value) \
83
+ { \
84
+ AbstractMemory* memory; \
85
+ Data_Get_Struct(self, AbstractMemory, memory); \
86
+ memory_op_put_##name(memory, NUM2LONG(offset), value); \
87
+ return self; \
88
+ } \
89
+ static VALUE memory_write_##name(VALUE self, VALUE value); \
90
+ static VALUE \
91
+ memory_write_##name(VALUE self, VALUE value) \
92
+ { \
93
+ AbstractMemory* memory; \
94
+ Data_Get_Struct(self, AbstractMemory, memory); \
95
+ memory_op_put_##name(memory, 0, value); \
96
+ return self; \
97
+ } \
98
+ static VALUE memory_op_get_##name(AbstractMemory* memory, long off); \
99
+ static VALUE \
100
+ memory_op_get_##name(AbstractMemory* memory, long off) \
101
+ { \
102
+ type tmp; \
103
+ checkRead(memory); \
104
+ checkBounds(memory, off, sizeof(type)); \
105
+ memcpy(&tmp, memory->address + off, sizeof(tmp)); \
106
+ return fromNative(VAL(tmp, swap)); \
107
+ } \
108
+ static VALUE memory_get_##name(VALUE self, VALUE offset); \
109
+ static VALUE \
110
+ memory_get_##name(VALUE self, VALUE offset) \
111
+ { \
112
+ AbstractMemory* memory; \
113
+ Data_Get_Struct(self, AbstractMemory, memory); \
114
+ return memory_op_get_##name(memory, NUM2LONG(offset)); \
115
+ } \
116
+ static VALUE memory_read_##name(VALUE self); \
117
+ static VALUE \
118
+ memory_read_##name(VALUE self) \
119
+ { \
120
+ AbstractMemory* memory; \
121
+ Data_Get_Struct(self, AbstractMemory, memory); \
122
+ return memory_op_get_##name(memory, 0); \
123
+ } \
124
+ static MemoryOp memory_op_##name = { memory_op_get_##name, memory_op_put_##name }; \
125
+ \
126
+ static VALUE memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary); \
127
+ static VALUE \
128
+ memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \
129
+ { \
130
+ long count = RARRAY_LEN(ary); \
131
+ long off = NUM2LONG(offset); \
132
+ AbstractMemory* memory = MEMORY(self); \
133
+ long i; \
134
+ checkWrite(memory); \
135
+ checkBounds(memory, off, count * sizeof(type)); \
136
+ for (i = 0; i < count; i++) { \
137
+ type tmp = (type) VAL(toNative(RARRAY_PTR(ary)[i]), swap); \
138
+ memcpy(memory->address + off + (i * sizeof(type)), &tmp, sizeof(tmp)); \
139
+ } \
140
+ return self; \
141
+ } \
142
+ static VALUE memory_write_array_of_##name(VALUE self, VALUE ary); \
143
+ static VALUE \
144
+ memory_write_array_of_##name(VALUE self, VALUE ary) \
145
+ { \
146
+ return memory_put_array_of_##name(self, INT2FIX(0), ary); \
147
+ } \
148
+ static VALUE memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length); \
149
+ static VALUE \
150
+ memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length) \
151
+ { \
152
+ long count = NUM2LONG(length); \
153
+ long off = NUM2LONG(offset); \
154
+ AbstractMemory* memory = MEMORY(self); \
155
+ VALUE retVal = rb_ary_new2(count); \
156
+ long i; \
157
+ checkRead(memory); \
158
+ checkBounds(memory, off, count * sizeof(type)); \
159
+ for (i = 0; i < count; ++i) { \
160
+ type tmp; \
161
+ memcpy(&tmp, memory->address + off + (i * sizeof(type)), sizeof(tmp)); \
162
+ rb_ary_push(retVal, fromNative(VAL(tmp, swap))); \
163
+ } \
164
+ return retVal; \
165
+ } \
166
+ static VALUE memory_read_array_of_##name(VALUE self, VALUE length); \
167
+ static VALUE \
168
+ memory_read_array_of_##name(VALUE self, VALUE length) \
169
+ { \
170
+ return memory_get_array_of_##name(self, INT2FIX(0), length); \
171
+ }
172
+
173
+ #define NOSWAP(x) (x)
174
+ #define bswap16(x) (((x) >> 8) & 0xff) | (((x) << 8) & 0xff00);
175
+ static inline int16_t
176
+ SWAPS16(int16_t x)
177
+ {
178
+ return bswap16(x);
179
+ }
180
+
181
+ static inline uint16_t
182
+ SWAPU16(uint16_t x)
183
+ {
184
+ return bswap16(x);
185
+ }
186
+
187
+ #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
188
+ #define bswap32(x) \
189
+ (((x << 24) & 0xff000000) | \
190
+ ((x << 8) & 0x00ff0000) | \
191
+ ((x >> 8) & 0x0000ff00) | \
192
+ ((x >> 24) & 0x000000ff))
193
+
194
+ #define bswap64(x) \
195
+ (((x << 56) & 0xff00000000000000ULL) | \
196
+ ((x << 40) & 0x00ff000000000000ULL) | \
197
+ ((x << 24) & 0x0000ff0000000000ULL) | \
198
+ ((x << 8) & 0x000000ff00000000ULL) | \
199
+ ((x >> 8) & 0x00000000ff000000ULL) | \
200
+ ((x >> 24) & 0x0000000000ff0000ULL) | \
201
+ ((x >> 40) & 0x000000000000ff00ULL) | \
202
+ ((x >> 56) & 0x00000000000000ffULL))
203
+
204
+ static inline int32_t
205
+ SWAPS32(int32_t x)
206
+ {
207
+ return bswap32(x);
208
+ }
209
+
210
+ static inline uint32_t
211
+ SWAPU32(uint32_t x)
212
+ {
213
+ return bswap32(x);
214
+ }
215
+
216
+ static inline int64_t
217
+ SWAPS64(int64_t x)
218
+ {
219
+ return bswap64(x);
220
+ }
221
+
222
+ static inline uint64_t
223
+ SWAPU64(uint64_t x)
224
+ {
225
+ return bswap64(x);
226
+ }
227
+
228
+ #else
229
+ # define SWAPS32(x) ((int32_t) __builtin_bswap32(x))
230
+ # define SWAPU32(x) ((uint32_t) __builtin_bswap32(x))
231
+ # define SWAPS64(x) ((int64_t) __builtin_bswap64(x))
232
+ # define SWAPU64(x) ((uint64_t) __builtin_bswap64(x))
233
+ #endif
234
+
235
+ #if LONG_MAX > INT_MAX
236
+ # define SWAPSLONG SWAPS64
237
+ # define SWAPULONG SWAPU64
238
+ #else
239
+ # define SWAPSLONG SWAPS32
240
+ # define SWAPULONG SWAPU32
241
+ #endif
242
+
243
+ NUM_OP(int8, int8_t, NUM2INT, INT2NUM, NOSWAP);
244
+ NUM_OP(uint8, uint8_t, NUM2UINT, UINT2NUM, NOSWAP);
245
+ NUM_OP(int16, int16_t, NUM2INT, INT2NUM, SWAPS16);
246
+ NUM_OP(uint16, uint16_t, NUM2UINT, UINT2NUM, SWAPU16);
247
+ NUM_OP(int32, int32_t, NUM2INT, INT2NUM, SWAPS32);
248
+ NUM_OP(uint32, uint32_t, NUM2UINT, UINT2NUM, SWAPU32);
249
+ NUM_OP(int64, int64_t, NUM2LL, LL2NUM, SWAPS64);
250
+ NUM_OP(uint64, uint64_t, NUM2ULL, ULL2NUM, SWAPU64);
251
+ NUM_OP(long, long, NUM2LONG, LONG2NUM, SWAPSLONG);
252
+ NUM_OP(ulong, unsigned long, NUM2ULONG, ULONG2NUM, SWAPULONG);
253
+ NUM_OP(float32, float, NUM2DBL, rb_float_new, NOSWAP);
254
+ NUM_OP(float64, double, NUM2DBL, rb_float_new, NOSWAP);
255
+ NUM_OP(longdouble, long double, rbffi_num2longdouble, rbffi_longdouble_new, NOSWAP);
256
+
257
+ static inline void*
258
+ get_pointer_value(VALUE value)
259
+ {
260
+ const int type = TYPE(value);
261
+ if (type == T_DATA && rb_obj_is_kind_of(value, rbffi_PointerClass)) {
262
+ return memory_address(value);
263
+ } else if (type == T_NIL) {
264
+ return NULL;
265
+ } else if (type == T_FIXNUM) {
266
+ return (void *) (uintptr_t) FIX2ULONG(value);
267
+ } else if (type == T_BIGNUM) {
268
+ return (void *) (uintptr_t) NUM2ULL(value);
269
+ } else if (rb_respond_to(value, id_to_ptr)) {
270
+ return MEMORY_PTR(rb_funcall2(value, id_to_ptr, 0, NULL));
271
+ } else {
272
+ rb_raise(rb_eArgError, "value is not a pointer");
273
+ return NULL;
274
+ }
275
+ }
276
+
277
+ NUM_OP(pointer, void *, get_pointer_value, rbffi_Pointer_NewInstance, NOSWAP);
278
+
279
+ static inline uint8_t
280
+ rbffi_bool_value(VALUE value)
281
+ {
282
+ return RTEST(value);
283
+ }
284
+
285
+ static inline VALUE
286
+ rbffi_bool_new(uint8_t value)
287
+ {
288
+ return (value & 1) != 0 ? Qtrue : Qfalse;
289
+ }
290
+
291
+ NUM_OP(bool, unsigned char, rbffi_bool_value, rbffi_bool_new, NOSWAP);
292
+
293
+
294
+ /*
295
+ * call-seq: memory.clear
296
+ * Set the memory to all-zero.
297
+ * @return [self]
298
+ */
299
+ static VALUE
300
+ memory_clear(VALUE self)
301
+ {
302
+ AbstractMemory* ptr = MEMORY(self);
303
+ memset(ptr->address, 0, ptr->size);
304
+ return self;
305
+ }
306
+
307
+ /*
308
+ * call-seq: memory.size
309
+ * Return memory size in bytes (alias: #total)
310
+ * @return [Numeric]
311
+ */
312
+ static VALUE
313
+ memory_size(VALUE self)
314
+ {
315
+ AbstractMemory* ptr;
316
+
317
+ Data_Get_Struct(self, AbstractMemory, ptr);
318
+
319
+ return LONG2NUM(ptr->size);
320
+ }
321
+
322
+ /*
323
+ * call-seq: memory.get_string(offset, length=nil)
324
+ * Return string contained in memory.
325
+ * @param [Numeric] offset point in buffer to start from
326
+ * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
327
+ * @return [String]
328
+ * @raise {IndexError} if +length+ is too great
329
+ * @raise {NullPointerError} if memory not initialized
330
+ */
331
+ static VALUE
332
+ memory_get_string(int argc, VALUE* argv, VALUE self)
333
+ {
334
+ VALUE length = Qnil, offset = Qnil;
335
+ AbstractMemory* ptr = MEMORY(self);
336
+ long off, len;
337
+ char* end;
338
+ int nargs = rb_scan_args(argc, argv, "11", &offset, &length);
339
+
340
+ off = NUM2LONG(offset);
341
+ len = nargs > 1 && length != Qnil ? NUM2LONG(length) : (ptr->size - off);
342
+ checkRead(ptr);
343
+ checkBounds(ptr, off, len);
344
+
345
+ end = memchr(ptr->address + off, 0, len);
346
+ return rb_tainted_str_new((char *) ptr->address + off,
347
+ (end != NULL ? end - ptr->address - off : len));
348
+ }
349
+
350
+ /*
351
+ * call-seq: memory.get_array_of_string(offset, count=nil)
352
+ * Return an array of strings contained in memory.
353
+ * @param [Numeric] offset point in memory to start from
354
+ * @param [Numeric] count number of strings to get. If nil, return all strings
355
+ * @return [Array<String>]
356
+ * @raise {IndexError} if +offset+ is too great
357
+ * @raise {NullPointerError} if memory not initialized
358
+ */
359
+ static VALUE
360
+ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
361
+ {
362
+ VALUE offset = Qnil, countnum = Qnil, retVal = Qnil;
363
+ AbstractMemory* ptr;
364
+ long off;
365
+ int count;
366
+
367
+ rb_scan_args(argc, argv, "11", &offset, &countnum);
368
+ off = NUM2LONG(offset);
369
+ count = (countnum == Qnil ? 0 : NUM2INT(countnum));
370
+ retVal = rb_ary_new2(count);
371
+
372
+ Data_Get_Struct(self, AbstractMemory, ptr);
373
+ checkRead(ptr);
374
+
375
+ if (countnum != Qnil) {
376
+ int i;
377
+
378
+ checkBounds(ptr, off, count * sizeof (char*));
379
+
380
+ for (i = 0; i < count; ++i) {
381
+ const char* strptr = *((const char**) (ptr->address + off) + i);
382
+ rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_tainted_str_new2(strptr)));
383
+ }
384
+
385
+ } else {
386
+ checkBounds(ptr, off, sizeof (char*));
387
+ for ( ; off < ptr->size - (long) sizeof (void *); off += (long) sizeof (void *)) {
388
+ const char* strptr = *(const char**) (ptr->address + off);
389
+ if (strptr == NULL) {
390
+ break;
391
+ }
392
+ rb_ary_push(retVal, rb_tainted_str_new2(strptr));
393
+ }
394
+ }
395
+
396
+ return retVal;
397
+ }
398
+
399
+ /*
400
+ * call-seq: memory.read_array_of_string(count=nil)
401
+ * Return an array of strings contained in memory. Same as:
402
+ * memory.get_array_of_string(0, count)
403
+ * @param [Numeric] count number of strings to get. If nil, return all strings
404
+ * @return [Array<String>]
405
+ */
406
+ static VALUE
407
+ memory_read_array_of_string(int argc, VALUE* argv, VALUE self)
408
+ {
409
+ VALUE* rargv = ALLOCA_N(VALUE, argc + 1);
410
+ int i;
411
+
412
+ rargv[0] = INT2FIX(0);
413
+ for (i = 0; i < argc; i++) {
414
+ rargv[i + 1] = argv[i];
415
+ }
416
+
417
+ return memory_get_array_of_string(argc + 1, rargv, self);
418
+ }
419
+
420
+
421
+ /*
422
+ * call-seq: memory.put_string(offset, str)
423
+ * @param [Numeric] offset
424
+ * @param [String] str
425
+ * @return [self]
426
+ * @raise {SecurityError} when writing unsafe string to memory
427
+ * @raise {IndexError} if +offset+ is too great
428
+ * @raise {NullPointerError} if memory not initialized
429
+ * Put a string in memory.
430
+ */
431
+ static VALUE
432
+ memory_put_string(VALUE self, VALUE offset, VALUE str)
433
+ {
434
+ AbstractMemory* ptr = MEMORY(self);
435
+ long off, len;
436
+
437
+ Check_Type(str, T_STRING);
438
+ off = NUM2LONG(offset);
439
+ len = RSTRING_LEN(str);
440
+
441
+ checkWrite(ptr);
442
+ checkBounds(ptr, off, len + 1);
443
+
444
+ memcpy(ptr->address + off, RSTRING_PTR(str), len);
445
+ *((char *) ptr->address + off + len) = '\0';
446
+
447
+ return self;
448
+ }
449
+
450
+ /*
451
+ * call-seq: memory.get_bytes(offset, length)
452
+ * Return string contained in memory.
453
+ * @param [Numeric] offset point in buffer to start from
454
+ * @param [Numeric] length string's length in bytes.
455
+ * @return [String]
456
+ * @raise {IndexError} if +length+ is too great
457
+ * @raise {NullPointerError} if memory not initialized
458
+ */
459
+ static VALUE
460
+ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
461
+ {
462
+ AbstractMemory* ptr = MEMORY(self);
463
+ long off, len;
464
+
465
+ off = NUM2LONG(offset);
466
+ len = NUM2LONG(length);
467
+
468
+ checkRead(ptr);
469
+ checkBounds(ptr, off, len);
470
+
471
+ return rb_tainted_str_new((char *) ptr->address + off, len);
472
+ }
473
+
474
+ /*
475
+ * call-seq: memory.put_bytes(offset, str, index=0, length=nil)
476
+ * Put a string in memory.
477
+ * @param [Numeric] offset point in buffer to start from
478
+ * @param [String] str string to put to memory
479
+ * @param [Numeric] index
480
+ * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
481
+ * @return [self]
482
+ * @raise {IndexError} if +length+ is too great
483
+ * @raise {NullPointerError} if memory not initialized
484
+ * @raise {RangeError} if +index+ is negative, or if index+length is greater than size of string
485
+ * @raise {SecurityError} when writing unsafe string to memory
486
+ */
487
+ static VALUE
488
+ memory_put_bytes(int argc, VALUE* argv, VALUE self)
489
+ {
490
+ AbstractMemory* ptr = MEMORY(self);
491
+ VALUE offset = Qnil, str = Qnil, rbIndex = Qnil, rbLength = Qnil;
492
+ long off, len, idx;
493
+ int nargs = rb_scan_args(argc, argv, "22", &offset, &str, &rbIndex, &rbLength);
494
+
495
+ Check_Type(str, T_STRING);
496
+
497
+ off = NUM2LONG(offset);
498
+ idx = nargs > 2 ? NUM2LONG(rbIndex) : 0;
499
+ if (idx < 0) {
500
+ rb_raise(rb_eRangeError, "index canot be less than zero");
501
+ return Qnil;
502
+ }
503
+ len = nargs > 3 ? NUM2LONG(rbLength) : (RSTRING_LEN(str) - idx);
504
+ if ((idx + len) > RSTRING_LEN(str)) {
505
+ rb_raise(rb_eRangeError, "index+length is greater than size of string");
506
+ return Qnil;
507
+ }
508
+
509
+ checkWrite(ptr);
510
+ checkBounds(ptr, off, len);
511
+
512
+ if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
513
+ rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
514
+ return Qnil;
515
+ }
516
+ memcpy(ptr->address + off, RSTRING_PTR(str) + idx, len);
517
+
518
+ return self;
519
+ }
520
+
521
+ /*
522
+ * call-seq: memory.read_bytes(length)
523
+ * @param [Numeric] length of string to return
524
+ * @return [String]
525
+ * equivalent to :
526
+ * memory.get_bytes(0, length)
527
+ */
528
+ static VALUE
529
+ memory_read_bytes(VALUE self, VALUE length)
530
+ {
531
+ return memory_get_bytes(self, INT2FIX(0), length);
532
+ }
533
+
534
+ /*
535
+ * call-seq: memory.write_bytes(str, index=0, length=nil)
536
+ * @param [String] str string to put to memory
537
+ * @param [Numeric] index
538
+ * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
539
+ * @return [self]
540
+ * equivalent to :
541
+ * memory.put_bytes(0, str, index, length)
542
+ */
543
+ static VALUE
544
+ memory_write_bytes(int argc, VALUE* argv, VALUE self)
545
+ {
546
+ VALUE* wargv = ALLOCA_N(VALUE, argc + 1);
547
+ int i;
548
+
549
+ wargv[0] = INT2FIX(0);
550
+ for (i = 0; i < argc; i++) {
551
+ wargv[i + 1] = argv[i];
552
+ }
553
+
554
+ return memory_put_bytes(argc + 1, wargv, self);
555
+ }
556
+
557
+ /*
558
+ * call-seq: memory.type_size
559
+ * @return [Numeric] type size in bytes
560
+ * Get the memory's type size.
561
+ */
562
+ static VALUE
563
+ memory_type_size(VALUE self)
564
+ {
565
+ AbstractMemory* ptr;
566
+
567
+ Data_Get_Struct(self, AbstractMemory, ptr);
568
+
569
+ return INT2NUM(ptr->typeSize);
570
+ }
571
+
572
+ /*
573
+ * Document-method: []
574
+ * call-seq: memory[idx]
575
+ * @param [Numeric] idx index to access in memory
576
+ * @return
577
+ * Memory read accessor.
578
+ */
579
+ static VALUE
580
+ memory_aref(VALUE self, VALUE idx)
581
+ {
582
+ AbstractMemory* ptr;
583
+ VALUE rbOffset = Qnil;
584
+
585
+ Data_Get_Struct(self, AbstractMemory, ptr);
586
+
587
+ rbOffset = ULONG2NUM(NUM2ULONG(idx) * ptr->typeSize);
588
+
589
+ return rb_funcall2(self, id_plus, 1, &rbOffset);
590
+ }
591
+
592
+ static inline char*
593
+ memory_address(VALUE obj)
594
+ {
595
+ return ((AbstractMemory *) DATA_PTR(obj))->address;
596
+ }
597
+
598
+ static VALUE
599
+ memory_copy_from(VALUE self, VALUE rbsrc, VALUE rblen)
600
+ {
601
+ AbstractMemory* dst;
602
+
603
+ Data_Get_Struct(self, AbstractMemory, dst);
604
+
605
+ memcpy(dst->address, rbffi_AbstractMemory_Cast(rbsrc, rbffi_AbstractMemoryClass)->address, NUM2INT(rblen));
606
+
607
+ return self;
608
+ }
609
+
610
+ AbstractMemory*
611
+ rbffi_AbstractMemory_Cast(VALUE obj, VALUE klass)
612
+ {
613
+ if (rb_obj_is_kind_of(obj, klass)) {
614
+ AbstractMemory* memory;
615
+ Data_Get_Struct(obj, AbstractMemory, memory);
616
+ return memory;
617
+ }
618
+
619
+ rb_raise(rb_eArgError, "Invalid Memory object");
620
+ return NULL;
621
+ }
622
+
623
+ void
624
+ rbffi_AbstractMemory_Error(AbstractMemory *mem, int op)
625
+ {
626
+ VALUE rbErrorClass = mem->address == NULL ? NullPointerErrorClass : rb_eRuntimeError;
627
+ if (op == MEM_RD) {
628
+ rb_raise(rbErrorClass, "invalid memory read at address=%p", mem->address);
629
+ } else if (op == MEM_WR) {
630
+ rb_raise(rbErrorClass, "invalid memory write at address=%p", mem->address);
631
+ } else {
632
+ rb_raise(rbErrorClass, "invalid memory access at address=%p", mem->address);
633
+ }
634
+ }
635
+
636
+ static VALUE
637
+ memory_op_get_strptr(AbstractMemory* ptr, long offset)
638
+ {
639
+ void* tmp = NULL;
640
+
641
+ if (ptr != NULL && ptr->address != NULL) {
642
+ checkRead(ptr);
643
+ checkBounds(ptr, offset, sizeof(tmp));
644
+ memcpy(&tmp, ptr->address + offset, sizeof(tmp));
645
+ }
646
+
647
+ return tmp != NULL ? rb_tainted_str_new2(tmp) : Qnil;
648
+ }
649
+
650
+ static void
651
+ memory_op_put_strptr(AbstractMemory* ptr, long offset, VALUE value)
652
+ {
653
+ rb_raise(rb_eArgError, "Cannot set :string fields");
654
+ }
655
+
656
+ static MemoryOp memory_op_strptr = { memory_op_get_strptr, memory_op_put_strptr };
657
+
658
+
659
+ MemoryOps rbffi_AbstractMemoryOps = {
660
+ &memory_op_int8, /*.int8 */
661
+ &memory_op_uint8, /* .uint8 */
662
+ &memory_op_int16, /* .int16 */
663
+ &memory_op_uint16, /* .uint16 */
664
+ &memory_op_int32, /* .int32 */
665
+ &memory_op_uint32, /* .uint32 */
666
+ &memory_op_int64, /* .int64 */
667
+ &memory_op_uint64, /* .uint64 */
668
+ &memory_op_long, /* .slong */
669
+ &memory_op_ulong, /* .uslong */
670
+ &memory_op_float32, /* .float32 */
671
+ &memory_op_float64, /* .float64 */
672
+ &memory_op_longdouble, /* .longdouble */
673
+ &memory_op_pointer, /* .pointer */
674
+ &memory_op_strptr, /* .strptr */
675
+ &memory_op_bool /* .boolOp */
676
+ };
677
+
678
+ void
679
+ rbffi_AbstractMemory_Init(VALUE moduleFFI)
680
+ {
681
+ /*
682
+ * Document-class: FFI::AbstractMemory
683
+ *
684
+ * {AbstractMemory} is the base class for many memory management classes such as {Buffer}.
685
+ *
686
+ * This class has a lot of methods to work with integers :
687
+ * * put_int<i>size</i>(offset, value)
688
+ * * get_int<i>size</i>(offset)
689
+ * * put_uint<i>size</i>(offset, value)
690
+ * * get_uint<i>size</i>(offset)
691
+ * * writeuint<i>size</i>(value)
692
+ * * read_int<i>size</i>
693
+ * * write_uint<i>size</i>(value)
694
+ * * read_uint<i>size</i>
695
+ * * put_array_of_int<i>size</i>(offset, ary)
696
+ * * get_array_of_int<i>size</i>(offset, length)
697
+ * * put_array_of_uint<i>size</i>(offset, ary)
698
+ * * get_array_of_uint<i>size</i>(offset, length)
699
+ * * write_array_of_int<i>size</i>(ary)
700
+ * * read_array_of_int<i>size</i>(length)
701
+ * * write_array_of_uint<i>size</i>(ary)
702
+ * * read_array_of_uint<i>size</i>(length)
703
+ * where _size_ is 8, 16, 32 or 64. Same methods exist for long type.
704
+ *
705
+ * Aliases exist : _char_ for _int8_, _short_ for _int16_, _int_ for _int32_ and <i>long_long</i> for _int64_.
706
+ *
707
+ * Others methods are listed below.
708
+ */
709
+ VALUE classMemory = rb_define_class_under(moduleFFI, "AbstractMemory", rb_cObject);
710
+ rbffi_AbstractMemoryClass = classMemory;
711
+ /*
712
+ * Document-variable: FFI::AbstractMemory
713
+ */
714
+ rb_global_variable(&rbffi_AbstractMemoryClass);
715
+ rb_define_alloc_func(classMemory, memory_allocate);
716
+
717
+ NullPointerErrorClass = rb_define_class_under(moduleFFI, "NullPointerError", rb_eRuntimeError);
718
+ /* Document-variable: NullPointerError */
719
+ rb_global_variable(&NullPointerErrorClass);
720
+
721
+
722
+ #undef INT
723
+ #define INT(type) \
724
+ rb_define_method(classMemory, "put_" #type, memory_put_##type, 2); \
725
+ rb_define_method(classMemory, "get_" #type, memory_get_##type, 1); \
726
+ rb_define_method(classMemory, "put_u" #type, memory_put_u##type, 2); \
727
+ rb_define_method(classMemory, "get_u" #type, memory_get_u##type, 1); \
728
+ rb_define_method(classMemory, "write_" #type, memory_write_##type, 1); \
729
+ rb_define_method(classMemory, "read_" #type, memory_read_##type, 0); \
730
+ rb_define_method(classMemory, "write_u" #type, memory_write_u##type, 1); \
731
+ rb_define_method(classMemory, "read_u" #type, memory_read_u##type, 0); \
732
+ rb_define_method(classMemory, "put_array_of_" #type, memory_put_array_of_##type, 2); \
733
+ rb_define_method(classMemory, "get_array_of_" #type, memory_get_array_of_##type, 2); \
734
+ rb_define_method(classMemory, "put_array_of_u" #type, memory_put_array_of_u##type, 2); \
735
+ rb_define_method(classMemory, "get_array_of_u" #type, memory_get_array_of_u##type, 2); \
736
+ rb_define_method(classMemory, "write_array_of_" #type, memory_write_array_of_##type, 1); \
737
+ rb_define_method(classMemory, "read_array_of_" #type, memory_read_array_of_##type, 1); \
738
+ rb_define_method(classMemory, "write_array_of_u" #type, memory_write_array_of_u##type, 1); \
739
+ rb_define_method(classMemory, "read_array_of_u" #type, memory_read_array_of_u##type, 1);
740
+
741
+ INT(int8);
742
+ INT(int16);
743
+ INT(int32);
744
+ INT(int64);
745
+ INT(long);
746
+
747
+ #define ALIAS(name, old) \
748
+ rb_define_alias(classMemory, "put_" #name, "put_" #old); \
749
+ rb_define_alias(classMemory, "get_" #name, "get_" #old); \
750
+ rb_define_alias(classMemory, "put_u" #name, "put_u" #old); \
751
+ rb_define_alias(classMemory, "get_u" #name, "get_u" #old); \
752
+ rb_define_alias(classMemory, "write_" #name, "write_" #old); \
753
+ rb_define_alias(classMemory, "read_" #name, "read_" #old); \
754
+ rb_define_alias(classMemory, "write_u" #name, "write_u" #old); \
755
+ rb_define_alias(classMemory, "read_u" #name, "read_u" #old); \
756
+ rb_define_alias(classMemory, "put_array_of_" #name, "put_array_of_" #old); \
757
+ rb_define_alias(classMemory, "get_array_of_" #name, "get_array_of_" #old); \
758
+ rb_define_alias(classMemory, "put_array_of_u" #name, "put_array_of_u" #old); \
759
+ rb_define_alias(classMemory, "get_array_of_u" #name, "get_array_of_u" #old); \
760
+ rb_define_alias(classMemory, "write_array_of_" #name, "write_array_of_" #old); \
761
+ rb_define_alias(classMemory, "read_array_of_" #name, "read_array_of_" #old); \
762
+ rb_define_alias(classMemory, "write_array_of_u" #name, "write_array_of_u" #old); \
763
+ rb_define_alias(classMemory, "read_array_of_u" #name, "read_array_of_u" #old);
764
+
765
+ ALIAS(char, int8);
766
+ ALIAS(short, int16);
767
+ ALIAS(int, int32);
768
+ ALIAS(long_long, int64);
769
+
770
+ /*
771
+ * Document-method: put_float32
772
+ * call-seq: memory.put_float32offset, value)
773
+ * @param [Numeric] offset
774
+ * @param [Numeric] value
775
+ * @return [self]
776
+ * Put +value+ as a 32-bit float in memory at offset +offset+ (alias: #put_float).
777
+ */
778
+ rb_define_method(classMemory, "put_float32", memory_put_float32, 2);
779
+ /*
780
+ * Document-method: get_float32
781
+ * call-seq: memory.get_float32(offset)
782
+ * @param [Numeric] offset
783
+ * @return [Float]
784
+ * Get a 32-bit float from memory at offset +offset+ (alias: #get_float).
785
+ */
786
+ rb_define_method(classMemory, "get_float32", memory_get_float32, 1);
787
+ rb_define_alias(classMemory, "put_float", "put_float32");
788
+ rb_define_alias(classMemory, "get_float", "get_float32");
789
+ /*
790
+ * Document-method: write_float
791
+ * call-seq: memory.write_float(value)
792
+ * @param [Numeric] value
793
+ * @return [self]
794
+ * Write +value+ as a 32-bit float in memory.
795
+ *
796
+ * Same as:
797
+ * memory.put_float(0, value)
798
+ */
799
+ rb_define_method(classMemory, "write_float", memory_write_float32, 1);
800
+ /*
801
+ * Document-method: read_float
802
+ * call-seq: memory.read_float
803
+ * @return [Float]
804
+ * Read a 32-bit float from memory.
805
+ *
806
+ * Same as:
807
+ * memory.get_float(0)
808
+ */
809
+ rb_define_method(classMemory, "read_float", memory_read_float32, 0);
810
+ /*
811
+ * Document-method: put_array_of_float32
812
+ * call-seq: memory.put_array_of_float32(offset, ary)
813
+ * @param [Numeric] offset
814
+ * @param [Array<Numeric>] ary
815
+ * @return [self]
816
+ * Put values from +ary+ as 32-bit floats in memory from offset +offset+ (alias: #put_array_of_float).
817
+ */
818
+ rb_define_method(classMemory, "put_array_of_float32", memory_put_array_of_float32, 2);
819
+ /*
820
+ * Document-method: get_array_of_float32
821
+ * call-seq: memory.get_array_of_float32(offset, length)
822
+ * @param [Numeric] offset
823
+ * @param [Numeric] length number of Float to get
824
+ * @return [Array<Float>]
825
+ * Get 32-bit floats in memory from offset +offset+ (alias: #get_array_of_float).
826
+ */
827
+ rb_define_method(classMemory, "get_array_of_float32", memory_get_array_of_float32, 2);
828
+ /*
829
+ * Document-method: write_array_of_float
830
+ * call-seq: memory.write_array_of_float(ary)
831
+ * @param [Array<Numeric>] ary
832
+ * @return [self]
833
+ * Write values from +ary+ as 32-bit floats in memory.
834
+ *
835
+ * Same as:
836
+ * memory.put_array_of_float(0, ary)
837
+ */
838
+ rb_define_method(classMemory, "write_array_of_float", memory_write_array_of_float32, 1);
839
+ /*
840
+ * Document-method: read_array_of_float
841
+ * call-seq: memory.read_array_of_float(length)
842
+ * @param [Numeric] length number of Float to read
843
+ * @return [Array<Float>]
844
+ * Read 32-bit floats from memory.
845
+ *
846
+ * Same as:
847
+ * memory.get_array_of_float(0, ary)
848
+ */
849
+ rb_define_method(classMemory, "read_array_of_float", memory_read_array_of_float32, 1);
850
+ rb_define_alias(classMemory, "put_array_of_float", "put_array_of_float32");
851
+ rb_define_alias(classMemory, "get_array_of_float", "get_array_of_float32");
852
+ /*
853
+ * Document-method: put_float64
854
+ * call-seq: memory.put_float64(offset, value)
855
+ * @param [Numeric] offset
856
+ * @param [Numeric] value
857
+ * @return [self]
858
+ * Put +value+ as a 64-bit float (double) in memory at offset +offset+ (alias: #put_double).
859
+ */
860
+ rb_define_method(classMemory, "put_float64", memory_put_float64, 2);
861
+ /*
862
+ * Document-method: get_float64
863
+ * call-seq: memory.get_float64(offset)
864
+ * @param [Numeric] offset
865
+ * @return [Float]
866
+ * Get a 64-bit float (double) from memory at offset +offset+ (alias: #get_double).
867
+ */
868
+ rb_define_method(classMemory, "get_float64", memory_get_float64, 1);
869
+ rb_define_alias(classMemory, "put_double", "put_float64");
870
+ rb_define_alias(classMemory, "get_double", "get_float64");
871
+ /*
872
+ * Document-method: write_double
873
+ * call-seq: memory.write_double(value)
874
+ * @param [Numeric] value
875
+ * @return [self]
876
+ * Write +value+ as a 64-bit float (double) in memory.
877
+ *
878
+ * Same as:
879
+ * memory.put_double(0, value)
880
+ */
881
+ rb_define_method(classMemory, "write_double", memory_write_float64, 1);
882
+ /*
883
+ * Document-method: read_double
884
+ * call-seq: memory.read_double
885
+ * @return [Float]
886
+ * Read a 64-bit float (double) from memory.
887
+ *
888
+ * Same as:
889
+ * memory.get_double(0)
890
+ */
891
+ rb_define_method(classMemory, "read_double", memory_read_float64, 0);
892
+ /*
893
+ * Document-method: put_array_of_float64
894
+ * call-seq: memory.put_array_of_float64(offset, ary)
895
+ * @param [Numeric] offset
896
+ * @param [Array<Numeric>] ary
897
+ * @return [self]
898
+ * Put values from +ary+ as 64-bit floats (doubles) in memory from offset +offset+ (alias: #put_array_of_double).
899
+ */
900
+ rb_define_method(classMemory, "put_array_of_float64", memory_put_array_of_float64, 2);
901
+ /*
902
+ * Document-method: get_array_of_float64
903
+ * call-seq: memory.get_array_of_float64(offset, length)
904
+ * @param [Numeric] offset
905
+ * @param [Numeric] length number of Float to get
906
+ * @return [Array<Float>]
907
+ * Get 64-bit floats (doubles) in memory from offset +offset+ (alias: #get_array_of_double).
908
+ */
909
+ rb_define_method(classMemory, "get_array_of_float64", memory_get_array_of_float64, 2);
910
+ /*
911
+ * Document-method: write_array_of_double
912
+ * call-seq: memory.write_array_of_double(ary)
913
+ * @param [Array<Numeric>] ary
914
+ * @return [self]
915
+ * Write values from +ary+ as 64-bit floats (doubles) in memory.
916
+ *
917
+ * Same as:
918
+ * memory.put_array_of_double(0, ary)
919
+ */
920
+ rb_define_method(classMemory, "write_array_of_double", memory_write_array_of_float64, 1);
921
+ /*
922
+ * Document-method: read_array_of_double
923
+ * call-seq: memory.read_array_of_double(length)
924
+ * @param [Numeric] length number of Float to read
925
+ * @return [Array<Float>]
926
+ * Read 64-bit floats (doubles) from memory.
927
+ *
928
+ * Same as:
929
+ * memory.get_array_of_double(0, ary)
930
+ */
931
+ rb_define_method(classMemory, "read_array_of_double", memory_read_array_of_float64, 1);
932
+ rb_define_alias(classMemory, "put_array_of_double", "put_array_of_float64");
933
+ rb_define_alias(classMemory, "get_array_of_double", "get_array_of_float64");
934
+ /*
935
+ * Document-method: put_pointer
936
+ * call-seq: memory.put_pointer(offset, value)
937
+ * @param [Numeric] offset
938
+ * @param [nil,Pointer, Integer, #to_ptr] value
939
+ * @return [self]
940
+ * Put +value+ in memory from +offset+..
941
+ */
942
+ rb_define_method(classMemory, "put_pointer", memory_put_pointer, 2);
943
+ /*
944
+ * Document-method: get_pointer
945
+ * call-seq: memory.get_pointer(offset)
946
+ * @param [Numeric] offset
947
+ * @return [Pointer]
948
+ * Get a {Pointer} to the memory from +offset+.
949
+ */
950
+ rb_define_method(classMemory, "get_pointer", memory_get_pointer, 1);
951
+ /*
952
+ * Document-method: write_pointer
953
+ * call-seq: memory.write_pointer(value)
954
+ * @param [nil,Pointer, Integer, #to_ptr] value
955
+ * @return [self]
956
+ * Write +value+ in memory.
957
+ *
958
+ * Equivalent to:
959
+ * memory.put_pointer(0, value)
960
+ */
961
+ rb_define_method(classMemory, "write_pointer", memory_write_pointer, 1);
962
+ /*
963
+ * Document-method: read_pointer
964
+ * call-seq: memory.read_pointer
965
+ * @return [Pointer]
966
+ * Get a {Pointer} to the memory from base address.
967
+ *
968
+ * Equivalent to:
969
+ * memory.get_pointer(0)
970
+ */
971
+ rb_define_method(classMemory, "read_pointer", memory_read_pointer, 0);
972
+ /*
973
+ * Document-method: put_array_of_pointer
974
+ * call-seq: memory.put_array_of_pointer(offset, ary)
975
+ * @param [Numeric] offset
976
+ * @param [Array<#to_ptr>] ary
977
+ * @return [self]
978
+ * Put an array of {Pointer} into memory from +offset+.
979
+ */
980
+ rb_define_method(classMemory, "put_array_of_pointer", memory_put_array_of_pointer, 2);
981
+ /*
982
+ * Document-method: get_array_of_pointer
983
+ * call-seq: memory.get_array_of_pointer(offset, length)
984
+ * @param [Numeric] offset
985
+ * @param [Numeric] length
986
+ * @return [Array<Pointer>]
987
+ * Get an array of {Pointer} of length +length+ from +offset+.
988
+ */
989
+ rb_define_method(classMemory, "get_array_of_pointer", memory_get_array_of_pointer, 2);
990
+ /*
991
+ * Document-method: write_array_of_pointer
992
+ * call-seq: memory.write_array_of_pointer(ary)
993
+ * @param [Array<#to_ptr>] ary
994
+ * @return [self]
995
+ * Write an array of {Pointer} into memory from +offset+.
996
+ *
997
+ * Same as :
998
+ * memory.put_array_of_pointer(0, ary)
999
+ */
1000
+ rb_define_method(classMemory, "write_array_of_pointer", memory_write_array_of_pointer, 1);
1001
+ /*
1002
+ * Document-method: read_array_of_pointer
1003
+ * call-seq: memory.read_array_of_pointer(length)
1004
+ * @param [Numeric] length
1005
+ * @return [Array<Pointer>]
1006
+ * Read an array of {Pointer} of length +length+.
1007
+ *
1008
+ * Same as:
1009
+ * memory.get_array_of_pointer(0, length)
1010
+ */
1011
+ rb_define_method(classMemory, "read_array_of_pointer", memory_read_array_of_pointer, 1);
1012
+
1013
+ rb_define_method(classMemory, "get_string", memory_get_string, -1);
1014
+ rb_define_method(classMemory, "put_string", memory_put_string, 2);
1015
+ rb_define_method(classMemory, "get_bytes", memory_get_bytes, 2);
1016
+ rb_define_method(classMemory, "put_bytes", memory_put_bytes, -1);
1017
+ rb_define_method(classMemory, "read_bytes", memory_read_bytes, 1);
1018
+ rb_define_method(classMemory, "write_bytes", memory_write_bytes, -1);
1019
+ rb_define_method(classMemory, "get_array_of_string", memory_get_array_of_string, -1);
1020
+
1021
+ rb_define_method(classMemory, "clear", memory_clear, 0);
1022
+ rb_define_method(classMemory, "total", memory_size, 0);
1023
+ rb_define_alias(classMemory, "size", "total");
1024
+ rb_define_method(classMemory, "type_size", memory_type_size, 0);
1025
+ rb_define_method(classMemory, "[]", memory_aref, 1);
1026
+ rb_define_method(classMemory, "__copy_from__", memory_copy_from, 2);
1027
+
1028
+ id_to_ptr = rb_intern("to_ptr");
1029
+ id_call = rb_intern("call");
1030
+ id_plus = rb_intern("+");
1031
+ }
1032
+