ffi 1.9.21-x86-mingw32 → 1.9.22-x86-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 (551) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +22 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +52 -0
  5. data/.yardopts +5 -0
  6. data/Gemfile +15 -0
  7. data/{spec/ffi/LICENSE.SPECS → LICENSE.SPECS} +1 -1
  8. data/README.md +1 -1
  9. data/Rakefile +28 -3
  10. data/appveyor.yml +22 -0
  11. data/ffi.gemspec +14 -1
  12. data/lib/2.0/ffi_c.so +0 -0
  13. data/lib/2.1/ffi_c.so +0 -0
  14. data/lib/2.2/ffi_c.so +0 -0
  15. data/lib/2.3/ffi_c.so +0 -0
  16. data/lib/2.4/ffi_c.so +0 -0
  17. data/lib/2.5/ffi_c.so +0 -0
  18. data/lib/ffi/library.rb +1 -1
  19. data/lib/ffi/version.rb +1 -1
  20. data/samples/getlogin.rb +8 -0
  21. data/samples/getpid.rb +8 -0
  22. data/samples/gettimeofday.rb +18 -0
  23. data/samples/hello.rb +7 -0
  24. data/samples/inotify.rb +60 -0
  25. data/samples/pty.rb +76 -0
  26. data/samples/qsort.rb +21 -0
  27. data/samples/sample_helper.rb +6 -0
  28. metadata +17 -526
  29. data/ext/ffi_c/AbstractMemory.c +0 -1109
  30. data/ext/ffi_c/AbstractMemory.h +0 -175
  31. data/ext/ffi_c/ArrayType.c +0 -162
  32. data/ext/ffi_c/ArrayType.h +0 -59
  33. data/ext/ffi_c/Buffer.c +0 -365
  34. data/ext/ffi_c/Call.c +0 -517
  35. data/ext/ffi_c/Call.h +0 -110
  36. data/ext/ffi_c/ClosurePool.c +0 -283
  37. data/ext/ffi_c/ClosurePool.h +0 -57
  38. data/ext/ffi_c/DataConverter.c +0 -91
  39. data/ext/ffi_c/DynamicLibrary.c +0 -339
  40. data/ext/ffi_c/DynamicLibrary.h +0 -98
  41. data/ext/ffi_c/Function.c +0 -998
  42. data/ext/ffi_c/Function.h +0 -87
  43. data/ext/ffi_c/FunctionInfo.c +0 -271
  44. data/ext/ffi_c/LastError.c +0 -184
  45. data/ext/ffi_c/LastError.h +0 -47
  46. data/ext/ffi_c/LongDouble.c +0 -63
  47. data/ext/ffi_c/LongDouble.h +0 -51
  48. data/ext/ffi_c/MappedType.c +0 -168
  49. data/ext/ffi_c/MappedType.h +0 -59
  50. data/ext/ffi_c/MemoryPointer.c +0 -197
  51. data/ext/ffi_c/MemoryPointer.h +0 -53
  52. data/ext/ffi_c/MethodHandle.c +0 -358
  53. data/ext/ffi_c/MethodHandle.h +0 -55
  54. data/ext/ffi_c/Platform.c +0 -129
  55. data/ext/ffi_c/Platform.h +0 -45
  56. data/ext/ffi_c/Pointer.c +0 -508
  57. data/ext/ffi_c/Pointer.h +0 -63
  58. data/ext/ffi_c/Struct.c +0 -829
  59. data/ext/ffi_c/Struct.h +0 -106
  60. data/ext/ffi_c/StructByReference.c +0 -190
  61. data/ext/ffi_c/StructByReference.h +0 -50
  62. data/ext/ffi_c/StructByValue.c +0 -150
  63. data/ext/ffi_c/StructByValue.h +0 -55
  64. data/ext/ffi_c/StructLayout.c +0 -698
  65. data/ext/ffi_c/Thread.c +0 -352
  66. data/ext/ffi_c/Thread.h +0 -95
  67. data/ext/ffi_c/Type.c +0 -397
  68. data/ext/ffi_c/Type.h +0 -62
  69. data/ext/ffi_c/Types.c +0 -139
  70. data/ext/ffi_c/Types.h +0 -89
  71. data/ext/ffi_c/Variadic.c +0 -304
  72. data/ext/ffi_c/compat.h +0 -78
  73. data/ext/ffi_c/extconf.rb +0 -71
  74. data/ext/ffi_c/ffi.c +0 -98
  75. data/ext/ffi_c/libffi.bsd.mk +0 -40
  76. data/ext/ffi_c/libffi.darwin.mk +0 -105
  77. data/ext/ffi_c/libffi.gnu.mk +0 -32
  78. data/ext/ffi_c/libffi.mk +0 -18
  79. data/ext/ffi_c/libffi.vc.mk +0 -26
  80. data/ext/ffi_c/libffi.vc64.mk +0 -26
  81. data/ext/ffi_c/libffi/ChangeLog.libffi +0 -584
  82. data/ext/ffi_c/libffi/ChangeLog.libffi-3.1 +0 -6000
  83. data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
  84. data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
  85. data/ext/ffi_c/libffi/LICENSE +0 -21
  86. data/ext/ffi_c/libffi/Makefile.am +0 -205
  87. data/ext/ffi_c/libffi/Makefile.in +0 -1805
  88. data/ext/ffi_c/libffi/README +0 -454
  89. data/ext/ffi_c/libffi/acinclude.m4 +0 -473
  90. data/ext/ffi_c/libffi/aclocal.m4 +0 -2134
  91. data/ext/ffi_c/libffi/autogen.sh +0 -2
  92. data/ext/ffi_c/libffi/autom4te.cache/output.0 +0 -21972
  93. data/ext/ffi_c/libffi/autom4te.cache/output.1 +0 -21972
  94. data/ext/ffi_c/libffi/autom4te.cache/output.2 +0 -21972
  95. data/ext/ffi_c/libffi/autom4te.cache/output.3 +0 -21972
  96. data/ext/ffi_c/libffi/autom4te.cache/requests +0 -331
  97. data/ext/ffi_c/libffi/autom4te.cache/traces.0 +0 -4010
  98. data/ext/ffi_c/libffi/autom4te.cache/traces.1 +0 -1005
  99. data/ext/ffi_c/libffi/autom4te.cache/traces.2 +0 -4010
  100. data/ext/ffi_c/libffi/autom4te.cache/traces.3 +0 -4010
  101. data/ext/ffi_c/libffi/compile +0 -347
  102. data/ext/ffi_c/libffi/config.guess +0 -1462
  103. data/ext/ffi_c/libffi/config.sub +0 -1825
  104. data/ext/ffi_c/libffi/configure +0 -21972
  105. data/ext/ffi_c/libffi/configure.ac +0 -388
  106. data/ext/ffi_c/libffi/configure.host +0 -272
  107. data/ext/ffi_c/libffi/depcomp +0 -791
  108. data/ext/ffi_c/libffi/doc/Makefile.am +0 -3
  109. data/ext/ffi_c/libffi/doc/Makefile.in +0 -811
  110. data/ext/ffi_c/libffi/doc/libffi.texi +0 -985
  111. data/ext/ffi_c/libffi/doc/mdate-sh +0 -228
  112. data/ext/ffi_c/libffi/doc/texinfo.tex +0 -10079
  113. data/ext/ffi_c/libffi/doc/version.texi +0 -4
  114. data/ext/ffi_c/libffi/fficonfig.h.in +0 -210
  115. data/ext/ffi_c/libffi/fficonfig.h.in~ +0 -210
  116. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +0 -207
  117. data/ext/ffi_c/libffi/include/Makefile.am +0 -9
  118. data/ext/ffi_c/libffi/include/Makefile.in +0 -604
  119. data/ext/ffi_c/libffi/include/ffi.h.in +0 -484
  120. data/ext/ffi_c/libffi/include/ffi_cfi.h +0 -55
  121. data/ext/ffi_c/libffi/include/ffi_common.h +0 -147
  122. data/ext/ffi_c/libffi/install-sh +0 -508
  123. data/ext/ffi_c/libffi/libffi.map.in +0 -80
  124. data/ext/ffi_c/libffi/libffi.pc.in +0 -11
  125. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +0 -637
  126. data/ext/ffi_c/libffi/libtool-ldflags +0 -106
  127. data/ext/ffi_c/libffi/libtool-version +0 -29
  128. data/ext/ffi_c/libffi/ltmain.sh +0 -11156
  129. data/ext/ffi_c/libffi/m4/asmcfi.m4 +0 -13
  130. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +0 -69
  131. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +0 -181
  132. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +0 -122
  133. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +0 -72
  134. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +0 -84
  135. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +0 -70
  136. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +0 -301
  137. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +0 -225
  138. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +0 -79
  139. data/ext/ffi_c/libffi/m4/libtool.m4 +0 -8387
  140. data/ext/ffi_c/libffi/m4/ltoptions.m4 +0 -437
  141. data/ext/ffi_c/libffi/m4/ltsugar.m4 +0 -124
  142. data/ext/ffi_c/libffi/m4/ltversion.m4 +0 -23
  143. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +0 -99
  144. data/ext/ffi_c/libffi/man/Makefile.am +0 -8
  145. data/ext/ffi_c/libffi/man/Makefile.in +0 -558
  146. data/ext/ffi_c/libffi/man/ffi.3 +0 -41
  147. data/ext/ffi_c/libffi/man/ffi_call.3 +0 -103
  148. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +0 -68
  149. data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +0 -73
  150. data/ext/ffi_c/libffi/missing +0 -215
  151. data/ext/ffi_c/libffi/msvcc.sh +0 -260
  152. data/ext/ffi_c/libffi/src/aarch64/ffi.c +0 -941
  153. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +0 -81
  154. data/ext/ffi_c/libffi/src/aarch64/internal.h +0 -67
  155. data/ext/ffi_c/libffi/src/aarch64/sysv.S +0 -438
  156. data/ext/ffi_c/libffi/src/alpha/ffi.c +0 -521
  157. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +0 -57
  158. data/ext/ffi_c/libffi/src/alpha/internal.h +0 -23
  159. data/ext/ffi_c/libffi/src/alpha/osf.S +0 -282
  160. data/ext/ffi_c/libffi/src/arc/arcompact.S +0 -135
  161. data/ext/ffi_c/libffi/src/arc/ffi.c +0 -266
  162. data/ext/ffi_c/libffi/src/arc/ffitarget.h +0 -53
  163. data/ext/ffi_c/libffi/src/arm/ffi.c +0 -808
  164. data/ext/ffi_c/libffi/src/arm/ffitarget.h +0 -82
  165. data/ext/ffi_c/libffi/src/arm/internal.h +0 -7
  166. data/ext/ffi_c/libffi/src/arm/sysv.S +0 -383
  167. data/ext/ffi_c/libffi/src/avr32/ffi.c +0 -423
  168. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +0 -55
  169. data/ext/ffi_c/libffi/src/avr32/sysv.S +0 -208
  170. data/ext/ffi_c/libffi/src/bfin/ffi.c +0 -196
  171. data/ext/ffi_c/libffi/src/bfin/ffitarget.h +0 -43
  172. data/ext/ffi_c/libffi/src/bfin/sysv.S +0 -179
  173. data/ext/ffi_c/libffi/src/closures.c +0 -890
  174. data/ext/ffi_c/libffi/src/cris/ffi.c +0 -386
  175. data/ext/ffi_c/libffi/src/cris/ffitarget.h +0 -56
  176. data/ext/ffi_c/libffi/src/cris/sysv.S +0 -215
  177. data/ext/ffi_c/libffi/src/debug.c +0 -64
  178. data/ext/ffi_c/libffi/src/dlmalloc.c +0 -5166
  179. data/ext/ffi_c/libffi/src/frv/eabi.S +0 -128
  180. data/ext/ffi_c/libffi/src/frv/ffi.c +0 -292
  181. data/ext/ffi_c/libffi/src/frv/ffitarget.h +0 -62
  182. data/ext/ffi_c/libffi/src/ia64/ffi.c +0 -586
  183. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +0 -55
  184. data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +0 -40
  185. data/ext/ffi_c/libffi/src/ia64/unix.S +0 -560
  186. data/ext/ffi_c/libffi/src/java_raw_api.c +0 -374
  187. data/ext/ffi_c/libffi/src/m32r/ffi.c +0 -232
  188. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +0 -53
  189. data/ext/ffi_c/libffi/src/m32r/sysv.S +0 -121
  190. data/ext/ffi_c/libffi/src/m68k/ffi.c +0 -362
  191. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +0 -54
  192. data/ext/ffi_c/libffi/src/m68k/sysv.S +0 -357
  193. data/ext/ffi_c/libffi/src/m88k/ffi.c +0 -400
  194. data/ext/ffi_c/libffi/src/m88k/ffitarget.h +0 -49
  195. data/ext/ffi_c/libffi/src/m88k/obsd.S +0 -209
  196. data/ext/ffi_c/libffi/src/metag/ffi.c +0 -330
  197. data/ext/ffi_c/libffi/src/metag/ffitarget.h +0 -53
  198. data/ext/ffi_c/libffi/src/metag/sysv.S +0 -311
  199. data/ext/ffi_c/libffi/src/microblaze/ffi.c +0 -321
  200. data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +0 -53
  201. data/ext/ffi_c/libffi/src/microblaze/sysv.S +0 -302
  202. data/ext/ffi_c/libffi/src/mips/ffi.c +0 -1105
  203. data/ext/ffi_c/libffi/src/mips/ffitarget.h +0 -249
  204. data/ext/ffi_c/libffi/src/mips/n32.S +0 -661
  205. data/ext/ffi_c/libffi/src/mips/o32.S +0 -502
  206. data/ext/ffi_c/libffi/src/moxie/eabi.S +0 -101
  207. data/ext/ffi_c/libffi/src/moxie/ffi.c +0 -272
  208. data/ext/ffi_c/libffi/src/moxie/ffitarget.h +0 -52
  209. data/ext/ffi_c/libffi/src/nios2/ffi.c +0 -304
  210. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +0 -52
  211. data/ext/ffi_c/libffi/src/nios2/sysv.S +0 -136
  212. data/ext/ffi_c/libffi/src/or1k/ffi.c +0 -328
  213. data/ext/ffi_c/libffi/src/or1k/ffitarget.h +0 -58
  214. data/ext/ffi_c/libffi/src/or1k/sysv.S +0 -107
  215. data/ext/ffi_c/libffi/src/pa/ffi.c +0 -719
  216. data/ext/ffi_c/libffi/src/pa/ffitarget.h +0 -85
  217. data/ext/ffi_c/libffi/src/pa/hpux32.S +0 -368
  218. data/ext/ffi_c/libffi/src/pa/linux.S +0 -357
  219. data/ext/ffi_c/libffi/src/powerpc/aix.S +0 -328
  220. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +0 -447
  221. data/ext/ffi_c/libffi/src/powerpc/asm.h +0 -125
  222. data/ext/ffi_c/libffi/src/powerpc/darwin.S +0 -378
  223. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +0 -571
  224. data/ext/ffi_c/libffi/src/powerpc/ffi.c +0 -173
  225. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +0 -1359
  226. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +0 -945
  227. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +0 -94
  228. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +0 -923
  229. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +0 -195
  230. data/ext/ffi_c/libffi/src/powerpc/linux64.S +0 -228
  231. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +0 -488
  232. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +0 -397
  233. data/ext/ffi_c/libffi/src/powerpc/sysv.S +0 -175
  234. data/ext/ffi_c/libffi/src/prep_cif.c +0 -261
  235. data/ext/ffi_c/libffi/src/raw_api.c +0 -267
  236. data/ext/ffi_c/libffi/src/s390/ffi.c +0 -756
  237. data/ext/ffi_c/libffi/src/s390/ffitarget.h +0 -70
  238. data/ext/ffi_c/libffi/src/s390/internal.h +0 -11
  239. data/ext/ffi_c/libffi/src/s390/sysv.S +0 -325
  240. data/ext/ffi_c/libffi/src/sh/ffi.c +0 -717
  241. data/ext/ffi_c/libffi/src/sh/ffitarget.h +0 -54
  242. data/ext/ffi_c/libffi/src/sh/sysv.S +0 -850
  243. data/ext/ffi_c/libffi/src/sh64/ffi.c +0 -469
  244. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +0 -58
  245. data/ext/ffi_c/libffi/src/sh64/sysv.S +0 -539
  246. data/ext/ffi_c/libffi/src/sparc/ffi.c +0 -468
  247. data/ext/ffi_c/libffi/src/sparc/ffi64.c +0 -608
  248. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +0 -81
  249. data/ext/ffi_c/libffi/src/sparc/internal.h +0 -26
  250. data/ext/ffi_c/libffi/src/sparc/v8.S +0 -443
  251. data/ext/ffi_c/libffi/src/sparc/v9.S +0 -440
  252. data/ext/ffi_c/libffi/src/tile/ffi.c +0 -355
  253. data/ext/ffi_c/libffi/src/tile/ffitarget.h +0 -65
  254. data/ext/ffi_c/libffi/src/tile/tile.S +0 -360
  255. data/ext/ffi_c/libffi/src/types.c +0 -106
  256. data/ext/ffi_c/libffi/src/vax/elfbsd.S +0 -195
  257. data/ext/ffi_c/libffi/src/vax/ffi.c +0 -276
  258. data/ext/ffi_c/libffi/src/vax/ffitarget.h +0 -49
  259. data/ext/ffi_c/libffi/src/x86/asmnames.h +0 -30
  260. data/ext/ffi_c/libffi/src/x86/ffi.c +0 -733
  261. data/ext/ffi_c/libffi/src/x86/ffi64.c +0 -857
  262. data/ext/ffi_c/libffi/src/x86/ffitarget.h +0 -141
  263. data/ext/ffi_c/libffi/src/x86/ffiw64.c +0 -287
  264. data/ext/ffi_c/libffi/src/x86/internal.h +0 -29
  265. data/ext/ffi_c/libffi/src/x86/internal64.h +0 -22
  266. data/ext/ffi_c/libffi/src/x86/sysv.S +0 -1043
  267. data/ext/ffi_c/libffi/src/x86/unix64.S +0 -525
  268. data/ext/ffi_c/libffi/src/x86/win64.S +0 -232
  269. data/ext/ffi_c/libffi/src/x86/win64_intel.S +0 -237
  270. data/ext/ffi_c/libffi/src/xtensa/ffi.c +0 -298
  271. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +0 -53
  272. data/ext/ffi_c/libffi/src/xtensa/sysv.S +0 -253
  273. data/ext/ffi_c/libffi/stamp-h.in +0 -1
  274. data/ext/ffi_c/libffi/testsuite/Makefile.am +0 -85
  275. data/ext/ffi_c/libffi/testsuite/Makefile.in +0 -607
  276. data/ext/ffi_c/libffi/testsuite/config/default.exp +0 -1
  277. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +0 -445
  278. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +0 -283
  279. data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +0 -45
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +0 -46
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +0 -30
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +0 -89
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +0 -81
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +0 -81
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +0 -82
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +0 -89
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +0 -92
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +0 -90
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +0 -95
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_simple.c +0 -55
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +0 -94
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +0 -95
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +0 -96
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +0 -102
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +0 -89
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +0 -91
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +0 -93
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +0 -113
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +0 -90
  300. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +0 -95
  301. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +0 -90
  302. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +0 -90
  303. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +0 -98
  304. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +0 -90
  305. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +0 -109
  306. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +0 -98
  307. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +0 -124
  308. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +0 -113
  309. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +0 -99
  310. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +0 -117
  311. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +0 -97
  312. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +0 -88
  313. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +0 -90
  314. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +0 -91
  315. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +0 -93
  316. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +0 -91
  317. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +0 -92
  318. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +0 -132
  319. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +0 -115
  320. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +0 -95
  321. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +0 -91
  322. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +0 -91
  323. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +0 -92
  324. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +0 -91
  325. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +0 -91
  326. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +0 -93
  327. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +0 -66
  328. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +0 -43
  329. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +0 -61
  330. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +0 -42
  331. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +0 -105
  332. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +0 -61
  333. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_args.c +0 -70
  334. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_float_double.c +0 -55
  335. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +0 -74
  336. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +0 -74
  337. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +0 -86
  338. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +0 -91
  339. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +0 -74
  340. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +0 -86
  341. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +0 -74
  342. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +0 -142
  343. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +0 -44
  344. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +0 -42
  345. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +0 -42
  346. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_struct_va1.c +0 -114
  347. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +0 -42
  348. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar_va.c +0 -44
  349. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +0 -43
  350. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint_va.c +0 -45
  351. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulong_va.c +0 -45
  352. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +0 -47
  353. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +0 -43
  354. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort_va.c +0 -44
  355. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +0 -36
  356. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +0 -26
  357. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +0 -136
  358. data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +0 -59
  359. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +0 -60
  360. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +0 -60
  361. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +0 -74
  362. data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +0 -62
  363. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +0 -107
  364. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +0 -341
  365. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +0 -59
  366. data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +0 -57
  367. data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +0 -70
  368. data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +0 -78
  369. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +0 -52
  370. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +0 -152
  371. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +0 -161
  372. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +0 -133
  373. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct11.c +0 -121
  374. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +0 -110
  375. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +0 -111
  376. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +0 -111
  377. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +0 -112
  378. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +0 -131
  379. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +0 -111
  380. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +0 -131
  381. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +0 -131
  382. data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +0 -46
  383. data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +0 -127
  384. data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +0 -90
  385. data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +0 -59
  386. data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +0 -114
  387. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +0 -36
  388. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +0 -43
  389. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +0 -42
  390. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +0 -35
  391. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +0 -36
  392. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +0 -49
  393. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +0 -42
  394. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +0 -34
  395. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +0 -41
  396. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +0 -43
  397. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +0 -36
  398. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +0 -38
  399. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +0 -38
  400. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +0 -38
  401. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +0 -145
  402. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +0 -148
  403. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +0 -124
  404. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +0 -125
  405. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +0 -44
  406. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +0 -49
  407. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +0 -49
  408. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +0 -55
  409. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +0 -67
  410. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +0 -67
  411. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +0 -60
  412. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +0 -64
  413. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +0 -66
  414. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +0 -64
  415. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +0 -74
  416. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +0 -81
  417. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +0 -68
  418. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +0 -70
  419. data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +0 -61
  420. data/ext/ffi_c/libffi/testsuite/libffi.call/unwindtest.cc +0 -117
  421. data/ext/ffi_c/libffi/testsuite/libffi.call/unwindtest_ffi_call.cc +0 -54
  422. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +0 -196
  423. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +0 -121
  424. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +0 -123
  425. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +0 -125
  426. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +0 -91
  427. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +0 -10
  428. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +0 -10
  429. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +0 -10
  430. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +0 -42
  431. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +0 -10
  432. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +0 -10
  433. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +0 -10
  434. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +0 -71
  435. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +0 -10
  436. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +0 -10
  437. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +0 -10
  438. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +0 -80
  439. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +0 -10
  440. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +0 -16
  441. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +0 -10
  442. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.exp +0 -36
  443. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +0 -51
  444. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +0 -7
  445. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +0 -7
  446. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +0 -7
  447. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +0 -10
  448. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +0 -10
  449. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +0 -86
  450. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +0 -10
  451. data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +0 -1
  452. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +0 -78
  453. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +0 -10
  454. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +0 -10
  455. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +0 -10
  456. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +0 -37
  457. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +0 -41
  458. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +0 -10
  459. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +0 -10
  460. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +0 -10
  461. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +0 -44
  462. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +0 -10
  463. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +0 -10
  464. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +0 -10
  465. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +0 -10
  466. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +0 -10
  467. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +0 -10
  468. data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +0 -34
  469. data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +0 -28
  470. data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +0 -1
  471. data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +0 -36
  472. data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +0 -19
  473. data/ext/ffi_c/rbffi.h +0 -57
  474. data/ext/ffi_c/rbffi_endian.h +0 -59
  475. data/ext/ffi_c/win32/stdbool.h +0 -8
  476. data/ext/ffi_c/win32/stdint.h +0 -201
  477. data/gen/Rakefile +0 -30
  478. data/libtest/Benchmark.c +0 -52
  479. data/libtest/BoolTest.c +0 -34
  480. data/libtest/BufferTest.c +0 -31
  481. data/libtest/ClosureTest.c +0 -205
  482. data/libtest/EnumTest.c +0 -51
  483. data/libtest/FunctionTest.c +0 -70
  484. data/libtest/GNUmakefile +0 -149
  485. data/libtest/GlobalVariable.c +0 -62
  486. data/libtest/LastErrorTest.c +0 -21
  487. data/libtest/NumberTest.c +0 -132
  488. data/libtest/PointerTest.c +0 -63
  489. data/libtest/ReferenceTest.c +0 -23
  490. data/libtest/StringTest.c +0 -34
  491. data/libtest/StructTest.c +0 -243
  492. data/libtest/UnionTest.c +0 -43
  493. data/libtest/VariadicTest.c +0 -99
  494. data/spec/ffi/async_callback_spec.rb +0 -35
  495. data/spec/ffi/bitmask_spec.rb +0 -575
  496. data/spec/ffi/bool_spec.rb +0 -32
  497. data/spec/ffi/buffer_spec.rb +0 -279
  498. data/spec/ffi/callback_spec.rb +0 -773
  499. data/spec/ffi/custom_param_type.rb +0 -37
  500. data/spec/ffi/custom_type_spec.rb +0 -74
  501. data/spec/ffi/dup_spec.rb +0 -52
  502. data/spec/ffi/embed-test/ext/Makefile +0 -242
  503. data/spec/ffi/enum_spec.rb +0 -423
  504. data/spec/ffi/errno_spec.rb +0 -20
  505. data/spec/ffi/ffi_spec.rb +0 -28
  506. data/spec/ffi/fixtures/Benchmark.c +0 -52
  507. data/spec/ffi/fixtures/BitmaskTest.c +0 -51
  508. data/spec/ffi/fixtures/BoolTest.c +0 -34
  509. data/spec/ffi/fixtures/BufferTest.c +0 -31
  510. data/spec/ffi/fixtures/ClosureTest.c +0 -205
  511. data/spec/ffi/fixtures/EnumTest.c +0 -51
  512. data/spec/ffi/fixtures/FunctionTest.c +0 -142
  513. data/spec/ffi/fixtures/GNUmakefile +0 -149
  514. data/spec/ffi/fixtures/GlobalVariable.c +0 -62
  515. data/spec/ffi/fixtures/LastErrorTest.c +0 -21
  516. data/spec/ffi/fixtures/NumberTest.c +0 -132
  517. data/spec/ffi/fixtures/PipeHelper.h +0 -21
  518. data/spec/ffi/fixtures/PipeHelperPosix.c +0 -41
  519. data/spec/ffi/fixtures/PipeHelperWindows.c +0 -72
  520. data/spec/ffi/fixtures/PointerTest.c +0 -63
  521. data/spec/ffi/fixtures/ReferenceTest.c +0 -23
  522. data/spec/ffi/fixtures/StringTest.c +0 -34
  523. data/spec/ffi/fixtures/StructTest.c +0 -243
  524. data/spec/ffi/fixtures/UnionTest.c +0 -43
  525. data/spec/ffi/fixtures/VariadicTest.c +0 -99
  526. data/spec/ffi/fixtures/classes.rb +0 -438
  527. data/spec/ffi/function_spec.rb +0 -97
  528. data/spec/ffi/io_spec.rb +0 -16
  529. data/spec/ffi/library_spec.rb +0 -286
  530. data/spec/ffi/long_double.rb +0 -30
  531. data/spec/ffi/managed_struct_spec.rb +0 -68
  532. data/spec/ffi/memorypointer_spec.rb +0 -78
  533. data/spec/ffi/number_spec.rb +0 -247
  534. data/spec/ffi/platform_spec.rb +0 -114
  535. data/spec/ffi/pointer_spec.rb +0 -285
  536. data/spec/ffi/rbx/attach_function_spec.rb +0 -34
  537. data/spec/ffi/rbx/memory_pointer_spec.rb +0 -198
  538. data/spec/ffi/rbx/spec_helper.rb +0 -6
  539. data/spec/ffi/rbx/struct_spec.rb +0 -18
  540. data/spec/ffi/spec_helper.rb +0 -93
  541. data/spec/ffi/string_spec.rb +0 -118
  542. data/spec/ffi/strptr_spec.rb +0 -50
  543. data/spec/ffi/struct_by_ref_spec.rb +0 -43
  544. data/spec/ffi/struct_callback_spec.rb +0 -69
  545. data/spec/ffi/struct_initialize_spec.rb +0 -35
  546. data/spec/ffi/struct_packed_spec.rb +0 -50
  547. data/spec/ffi/struct_spec.rb +0 -882
  548. data/spec/ffi/typedef_spec.rb +0 -91
  549. data/spec/ffi/union_spec.rb +0 -67
  550. data/spec/ffi/variadic_spec.rb +0 -132
  551. data/spec/spec.opts +0 -4
@@ -1,1109 +0,0 @@
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
-