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