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
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010 Wayne Meissner
|
3
|
+
#
|
4
|
+
# This file is part of ruby-ffi.
|
5
|
+
#
|
6
|
+
# All rights reserved.
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions are met:
|
10
|
+
#
|
11
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
12
|
+
# list of conditions and the following disclaimer.
|
13
|
+
# * Redistributions in binary form must reproduce the above copyright notice
|
14
|
+
# this list of conditions and the following disclaimer in the documentation
|
15
|
+
# and/or other materials provided with the distribution.
|
16
|
+
# * Neither the name of the Ruby FFI project nor the names of its contributors
|
17
|
+
# may be used to endorse or promote products derived from this software
|
18
|
+
# without specific prior written permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
24
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
|
30
|
+
|
31
|
+
module FFI
|
32
|
+
# This class includes the {FFI::DataConverter} module.
|
33
|
+
class StructByReference
|
34
|
+
include DataConverter
|
35
|
+
|
36
|
+
attr_reader :struct_class
|
37
|
+
|
38
|
+
# @param [Struct] struct_class
|
39
|
+
def initialize(struct_class)
|
40
|
+
unless Class === struct_class and struct_class < FFI::Struct
|
41
|
+
raise TypeError, 'wrong type (expected subclass of FFI::Struct)'
|
42
|
+
end
|
43
|
+
@struct_class = struct_class
|
44
|
+
end
|
45
|
+
|
46
|
+
# Always get {FFI::Type}::POINTER.
|
47
|
+
def native_type
|
48
|
+
FFI::Type::POINTER
|
49
|
+
end
|
50
|
+
|
51
|
+
# @param [nil, Struct] value
|
52
|
+
# @param [nil] ctx
|
53
|
+
# @return [AbstractMemory] Pointer on +value+.
|
54
|
+
def to_native(value, ctx)
|
55
|
+
return Pointer::NULL if value.nil?
|
56
|
+
|
57
|
+
unless @struct_class === value
|
58
|
+
raise TypeError, "wrong argument type #{value.class} (expected #{@struct_class})"
|
59
|
+
end
|
60
|
+
|
61
|
+
value.pointer
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param [AbstractMemory] value
|
65
|
+
# @param [nil] ctx
|
66
|
+
# @return [Struct]
|
67
|
+
# Create a struct from content of memory +value+.
|
68
|
+
def from_native(value, ctx)
|
69
|
+
@struct_class.new(value)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2008-2010 Wayne Meissner
|
3
|
+
# Copyright (C) 2008, 2009 Andrea Fazzi
|
4
|
+
# Copyright (C) 2008, 2009 Luc Heinrich
|
5
|
+
#
|
6
|
+
# This file is part of ruby-ffi.
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
14
|
+
# list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the Ruby FFI project nor the names of its contributors
|
19
|
+
# may be used to endorse or promote products derived from this software
|
20
|
+
# without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
25
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
26
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
27
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
28
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
29
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
30
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
31
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
|
34
|
+
module FFI
|
35
|
+
|
36
|
+
class StructLayout
|
37
|
+
|
38
|
+
# @return [Array<Array(Symbol, Numeric)>
|
39
|
+
# Get an array of tuples (field name, offset of the field).
|
40
|
+
def offsets
|
41
|
+
members.map { |m| [ m, self[m].offset ] }
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Numeric]
|
45
|
+
# Get the offset of a field.
|
46
|
+
def offset_of(field_name)
|
47
|
+
self[field_name].offset
|
48
|
+
end
|
49
|
+
|
50
|
+
# An enum {Field} in a {StructLayout}.
|
51
|
+
class Enum < Field
|
52
|
+
|
53
|
+
# @param [AbstractMemory] ptr pointer on a {Struct}
|
54
|
+
# @return [Object]
|
55
|
+
# Get an object of type {#type} from memory pointed by +ptr+.
|
56
|
+
def get(ptr)
|
57
|
+
type.find(ptr.get_int(offset))
|
58
|
+
end
|
59
|
+
|
60
|
+
# @param [AbstractMemory] ptr pointer on a {Struct}
|
61
|
+
# @param value
|
62
|
+
# @return [nil]
|
63
|
+
# Set +value+ into memory pointed by +ptr+.
|
64
|
+
def put(ptr, value)
|
65
|
+
ptr.put_int(offset, type.find(value))
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
class InnerStruct < Field
|
71
|
+
def get(ptr)
|
72
|
+
type.struct_class.new(ptr.slice(self.offset, self.size))
|
73
|
+
end
|
74
|
+
|
75
|
+
def put(ptr, value)
|
76
|
+
raise TypeError, "wrong value type (expected #{type.struct_class})" unless value.is_a?(type.struct_class)
|
77
|
+
ptr.slice(self.offset, self.size).__copy_from__(value.pointer, self.size)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class Mapped < Field
|
82
|
+
def initialize(name, offset, type, orig_field)
|
83
|
+
super(name, offset, type)
|
84
|
+
@orig_field = orig_field
|
85
|
+
end
|
86
|
+
|
87
|
+
def get(ptr)
|
88
|
+
type.from_native(@orig_field.get(ptr), nil)
|
89
|
+
end
|
90
|
+
|
91
|
+
def put(ptr, value)
|
92
|
+
@orig_field.put(ptr, type.to_native(value, nil))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,227 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2008-2010 Wayne Meissner
|
3
|
+
#
|
4
|
+
# This file is part of ruby-ffi.
|
5
|
+
#
|
6
|
+
# All rights reserved.
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions are met:
|
10
|
+
#
|
11
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
12
|
+
# list of conditions and the following disclaimer.
|
13
|
+
# * Redistributions in binary form must reproduce the above copyright notice
|
14
|
+
# this list of conditions and the following disclaimer in the documentation
|
15
|
+
# and/or other materials provided with the distribution.
|
16
|
+
# * Neither the name of the Ruby FFI project nor the names of its contributors
|
17
|
+
# may be used to endorse or promote products derived from this software
|
18
|
+
# without specific prior written permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
24
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
#
|
31
|
+
|
32
|
+
module FFI
|
33
|
+
|
34
|
+
# Build a {StructLayout struct layout}.
|
35
|
+
class StructLayoutBuilder
|
36
|
+
attr_reader :size
|
37
|
+
attr_reader :alignment
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
@size = 0
|
41
|
+
@alignment = 1
|
42
|
+
@min_alignment = 1
|
43
|
+
@packed = false
|
44
|
+
@union = false
|
45
|
+
@fields = Array.new
|
46
|
+
end
|
47
|
+
|
48
|
+
# Set size attribute with +size+ only if +size+ is greater than attribute value.
|
49
|
+
# @param [Numeric] size
|
50
|
+
def size=(size)
|
51
|
+
@size = size if size > @size
|
52
|
+
end
|
53
|
+
|
54
|
+
# Set alignment attribute with +align+ only if it is greater than attribute value.
|
55
|
+
# @param [Numeric] align
|
56
|
+
def alignment=(align)
|
57
|
+
@alignment = align if align > @alignment
|
58
|
+
@min_alignment = align
|
59
|
+
end
|
60
|
+
|
61
|
+
# Set union attribute.
|
62
|
+
# Set to +true+ to build a {Union} instead of a {Struct}.
|
63
|
+
# @param [Boolean] is_union
|
64
|
+
# @return [is_union]
|
65
|
+
def union=(is_union)
|
66
|
+
@union = is_union
|
67
|
+
end
|
68
|
+
|
69
|
+
# Building a {Union} or a {Struct} ?
|
70
|
+
#
|
71
|
+
# @return [Boolean]
|
72
|
+
#
|
73
|
+
def union?
|
74
|
+
@union
|
75
|
+
end
|
76
|
+
|
77
|
+
# Set packed attribute
|
78
|
+
# @overload packed=(packed) Set alignment and packed attributes to
|
79
|
+
# +packed+.
|
80
|
+
#
|
81
|
+
# @param [Fixnum] packed
|
82
|
+
#
|
83
|
+
# @return [packed]
|
84
|
+
# @overload packed=(packed) Set packed attribute.
|
85
|
+
# @param packed
|
86
|
+
#
|
87
|
+
# @return [0,1]
|
88
|
+
#
|
89
|
+
def packed=(packed)
|
90
|
+
if packed.is_a?(0.class)
|
91
|
+
@alignment = packed
|
92
|
+
@packed = packed
|
93
|
+
else
|
94
|
+
@packed = packed ? 1 : 0
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
# List of number types
|
100
|
+
NUMBER_TYPES = [
|
101
|
+
Type::INT8,
|
102
|
+
Type::UINT8,
|
103
|
+
Type::INT16,
|
104
|
+
Type::UINT16,
|
105
|
+
Type::INT32,
|
106
|
+
Type::UINT32,
|
107
|
+
Type::LONG,
|
108
|
+
Type::ULONG,
|
109
|
+
Type::INT64,
|
110
|
+
Type::UINT64,
|
111
|
+
Type::FLOAT32,
|
112
|
+
Type::FLOAT64,
|
113
|
+
Type::LONGDOUBLE,
|
114
|
+
Type::BOOL,
|
115
|
+
]
|
116
|
+
|
117
|
+
# @param [String, Symbol] name name of the field
|
118
|
+
# @param [Array, DataConverter, Struct, StructLayout::Field, Symbol, Type] type type of the field
|
119
|
+
# @param [Numeric, nil] offset
|
120
|
+
# @return [self]
|
121
|
+
# Add a field to the builder.
|
122
|
+
# @note Setting +offset+ to +nil+ or +-1+ is equivalent to +0+.
|
123
|
+
def add(name, type, offset = nil)
|
124
|
+
|
125
|
+
if offset.nil? || offset == -1
|
126
|
+
offset = @union ? 0 : align(@size, @packed ? [ @packed, type.alignment ].min : [ @min_alignment, type.alignment ].max)
|
127
|
+
end
|
128
|
+
|
129
|
+
#
|
130
|
+
# If a FFI::Type type was passed in as the field arg, try and convert to a StructLayout::Field instance
|
131
|
+
#
|
132
|
+
field = type.is_a?(StructLayout::Field) ? type : field_for_type(name, offset, type)
|
133
|
+
@fields << field
|
134
|
+
@alignment = [ @alignment, field.alignment ].max unless @packed
|
135
|
+
@size = [ @size, field.size + (@union ? 0 : field.offset) ].max
|
136
|
+
|
137
|
+
return self
|
138
|
+
end
|
139
|
+
|
140
|
+
# @param (see #add)
|
141
|
+
# @return (see #add)
|
142
|
+
# Same as {#add}.
|
143
|
+
# @see #add
|
144
|
+
def add_field(name, type, offset = nil)
|
145
|
+
add(name, type, offset)
|
146
|
+
end
|
147
|
+
|
148
|
+
# @param (see #add)
|
149
|
+
# @return (see #add)
|
150
|
+
# Add a struct as a field to the builder.
|
151
|
+
def add_struct(name, type, offset = nil)
|
152
|
+
add(name, Type::Struct.new(type), offset)
|
153
|
+
end
|
154
|
+
|
155
|
+
# @param name (see #add)
|
156
|
+
# @param type (see #add)
|
157
|
+
# @param [Numeric] count array length
|
158
|
+
# @param offset (see #add)
|
159
|
+
# @return (see #add)
|
160
|
+
# Add an array as a field to the builder.
|
161
|
+
def add_array(name, type, count, offset = nil)
|
162
|
+
add(name, Type::Array.new(type, count), offset)
|
163
|
+
end
|
164
|
+
|
165
|
+
# @return [StructLayout]
|
166
|
+
# Build and return the struct layout.
|
167
|
+
def build
|
168
|
+
# Add tail padding if the struct is not packed
|
169
|
+
size = @packed ? @size : align(@size, @alignment)
|
170
|
+
|
171
|
+
layout = StructLayout.new(@fields, size, @alignment)
|
172
|
+
layout.__union! if @union
|
173
|
+
layout
|
174
|
+
end
|
175
|
+
|
176
|
+
private
|
177
|
+
|
178
|
+
# @param [Numeric] offset
|
179
|
+
# @param [Numeric] align
|
180
|
+
# @return [Numeric]
|
181
|
+
def align(offset, align)
|
182
|
+
align + ((offset - 1) & ~(align - 1));
|
183
|
+
end
|
184
|
+
|
185
|
+
# @param (see #add)
|
186
|
+
# @return [StructLayout::Field]
|
187
|
+
def field_for_type(name, offset, type)
|
188
|
+
field_class = case
|
189
|
+
when type.is_a?(Type::Function)
|
190
|
+
StructLayout::Function
|
191
|
+
|
192
|
+
when type.is_a?(Type::Struct)
|
193
|
+
StructLayout::InnerStruct
|
194
|
+
|
195
|
+
when type.is_a?(Type::Array)
|
196
|
+
StructLayout::Array
|
197
|
+
|
198
|
+
when type.is_a?(FFI::Enum)
|
199
|
+
StructLayout::Enum
|
200
|
+
|
201
|
+
when NUMBER_TYPES.include?(type)
|
202
|
+
StructLayout::Number
|
203
|
+
|
204
|
+
when type == Type::POINTER
|
205
|
+
StructLayout::Pointer
|
206
|
+
|
207
|
+
when type == Type::STRING
|
208
|
+
StructLayout::String
|
209
|
+
|
210
|
+
when type.is_a?(Class) && type < StructLayout::Field
|
211
|
+
type
|
212
|
+
|
213
|
+
when type.is_a?(DataConverter)
|
214
|
+
return StructLayout::Mapped.new(name, offset, Type::Mapped.new(type), field_for_type(name, offset, type.native_type))
|
215
|
+
|
216
|
+
when type.is_a?(Type::Mapped)
|
217
|
+
return StructLayout::Mapped.new(name, offset, type, field_for_type(name, offset, type.native_type))
|
218
|
+
|
219
|
+
else
|
220
|
+
raise TypeError, "invalid struct field type #{type.inspect}"
|
221
|
+
end
|
222
|
+
|
223
|
+
field_class.new(name, offset, type)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
module FFI
|
5
|
+
|
6
|
+
# ConstGenerator turns C constants into ruby values.
|
7
|
+
#
|
8
|
+
# @example a simple example for stdio
|
9
|
+
# require 'ffi/tools/const_generator'
|
10
|
+
# cg = FFI::ConstGenerator.new('stdio') do |gen|
|
11
|
+
# gen.const(:SEEK_SET)
|
12
|
+
# gen.const('SEEK_CUR')
|
13
|
+
# gen.const('seek_end') # this constant does not exist
|
14
|
+
# end # #calculate called automatically at the end of the block
|
15
|
+
#
|
16
|
+
# cg['SEEK_SET'] # => 0
|
17
|
+
# cg['SEEK_CUR'] # => 1
|
18
|
+
# cg['seek_end'] # => nil
|
19
|
+
# cg.to_ruby # => "SEEK_SET = 0\nSEEK_CUR = 1\n# seek_end not available"
|
20
|
+
class ConstGenerator
|
21
|
+
@options = {}
|
22
|
+
attr_reader :constants
|
23
|
+
|
24
|
+
# Creates a new constant generator that uses +prefix+ as a name, and an
|
25
|
+
# options hash.
|
26
|
+
#
|
27
|
+
# The only option is +:required+, which if set to +true+ raises an error if a
|
28
|
+
# constant you have requested was not found.
|
29
|
+
#
|
30
|
+
# @param [#to_s] prefix
|
31
|
+
# @param [Hash] options
|
32
|
+
# @return
|
33
|
+
# @option options [Boolean] :required
|
34
|
+
# @overload initialize(prefix, options)
|
35
|
+
# @overload initialize(prefix, options) { |gen| ... }
|
36
|
+
# @yieldparam [ConstGenerator] gen new generator is passed to the block
|
37
|
+
# When passed a block, {#calculate} is automatically called at the end of
|
38
|
+
# the block, otherwise you must call it yourself.
|
39
|
+
def initialize(prefix = nil, options = {})
|
40
|
+
@includes = ['stdio.h', 'stddef.h']
|
41
|
+
@constants = {}
|
42
|
+
@prefix = prefix
|
43
|
+
|
44
|
+
@required = options[:required]
|
45
|
+
@options = options
|
46
|
+
|
47
|
+
if block_given? then
|
48
|
+
yield self
|
49
|
+
calculate self.class.options.merge(options)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
# Set class options
|
53
|
+
# These options are merged with {#initialize} options when it is called with a block.
|
54
|
+
# @param [Hash] options
|
55
|
+
# @return [Hash] class options
|
56
|
+
def self.options=(options)
|
57
|
+
@options = options
|
58
|
+
end
|
59
|
+
# Get class options.
|
60
|
+
# @return [Hash] class options
|
61
|
+
def self.options
|
62
|
+
@options
|
63
|
+
end
|
64
|
+
# @param [String] name
|
65
|
+
# @return constant value (converted if a +converter+ was defined).
|
66
|
+
# Access a constant by name.
|
67
|
+
def [](name)
|
68
|
+
@constants[name].converted_value
|
69
|
+
end
|
70
|
+
|
71
|
+
# Request the value for C constant +name+.
|
72
|
+
#
|
73
|
+
# @param [#to_s] name C constant name
|
74
|
+
# @param [String] format a printf format string to print the value out
|
75
|
+
# @param [String] cast a C cast for the value
|
76
|
+
# @param ruby_name alternate ruby name for {#to_ruby}
|
77
|
+
#
|
78
|
+
# @overload const(name, format=nil, cast='', ruby_name=nil, converter=nil)
|
79
|
+
# +converter+ is a Method or a Proc.
|
80
|
+
# @param [#call] converter convert the value from a string to the appropriate
|
81
|
+
# type for {#to_ruby}.
|
82
|
+
# @overload const(name, format=nil, cast='', ruby_name=nil) { |value| ... }
|
83
|
+
# Use a converter block. This block convert the value from a string to the
|
84
|
+
# appropriate type for {#to_ruby}.
|
85
|
+
# @yieldparam value constant value
|
86
|
+
def const(name, format = nil, cast = '', ruby_name = nil, converter = nil,
|
87
|
+
&converter_proc)
|
88
|
+
format ||= '%d'
|
89
|
+
cast ||= ''
|
90
|
+
|
91
|
+
if converter_proc and converter then
|
92
|
+
raise ArgumentError, "Supply only converter or converter block"
|
93
|
+
end
|
94
|
+
|
95
|
+
converter = converter_proc if converter.nil?
|
96
|
+
|
97
|
+
const = Constant.new name, format, cast, ruby_name, converter
|
98
|
+
@constants[name.to_s] = const
|
99
|
+
return const
|
100
|
+
end
|
101
|
+
|
102
|
+
# Calculate constants values.
|
103
|
+
# @param [Hash] options
|
104
|
+
# @option options [String] :cppflags flags for C compiler
|
105
|
+
# @return [nil]
|
106
|
+
# @raise if a constant is missing and +:required+ was set to +true+ (see {#initialize})
|
107
|
+
def calculate(options = {})
|
108
|
+
binary = File.join Dir.tmpdir, "rb_const_gen_bin_#{Process.pid}"
|
109
|
+
|
110
|
+
Tempfile.open("#{@prefix}.const_generator") do |f|
|
111
|
+
@includes.each do |inc|
|
112
|
+
f.puts "#include <#{inc}>"
|
113
|
+
end
|
114
|
+
f.puts "\nint main(int argc, char **argv)\n{"
|
115
|
+
|
116
|
+
@constants.each_value do |const|
|
117
|
+
f.puts <<-EOF
|
118
|
+
#ifdef #{const.name}
|
119
|
+
printf("#{const.name} #{const.format}\\n", #{const.cast}#{const.name});
|
120
|
+
#endif
|
121
|
+
EOF
|
122
|
+
end
|
123
|
+
|
124
|
+
f.puts "\n\treturn 0;\n}"
|
125
|
+
f.flush
|
126
|
+
|
127
|
+
output = `gcc #{options[:cppflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -x c -Wall -Werror #{f.path} -o #{binary} 2>&1`
|
128
|
+
|
129
|
+
unless $?.success? then
|
130
|
+
output = output.split("\n").map { |l| "\t#{l}" }.join "\n"
|
131
|
+
raise "Compilation error generating constants #{@prefix}:\n#{output}"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
output = `#{binary}`
|
136
|
+
File.unlink(binary + (FFI::Platform.windows? ? ".exe" : ""))
|
137
|
+
output.each_line do |line|
|
138
|
+
line =~ /^(\S+)\s(.*)$/
|
139
|
+
const = @constants[$1]
|
140
|
+
const.value = $2
|
141
|
+
end
|
142
|
+
|
143
|
+
missing_constants = @constants.select do |name, constant|
|
144
|
+
constant.value.nil?
|
145
|
+
end.map { |name,| name }
|
146
|
+
|
147
|
+
if @required and not missing_constants.empty? then
|
148
|
+
raise "Missing required constants for #{@prefix}: #{missing_constants.join ', '}"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# Dump constants to +io+.
|
153
|
+
# @param [#puts] io
|
154
|
+
# @return [nil]
|
155
|
+
def dump_constants(io)
|
156
|
+
@constants.each do |name, constant|
|
157
|
+
name = [@prefix, name].join '.' if @prefix
|
158
|
+
io.puts "#{name} = #{constant.converted_value}"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Outputs values for discovered constants. If the constant's value was
|
163
|
+
# not discovered it is not omitted.
|
164
|
+
# @return [String]
|
165
|
+
def to_ruby
|
166
|
+
@constants.sort_by { |name,| name }.map do |name, constant|
|
167
|
+
if constant.value.nil? then
|
168
|
+
"# #{name} not available"
|
169
|
+
else
|
170
|
+
constant.to_ruby
|
171
|
+
end
|
172
|
+
end.join "\n"
|
173
|
+
end
|
174
|
+
|
175
|
+
# Add additional C include file(s) to calculate constants from.
|
176
|
+
# @note +stdio.h+ and +stddef.h+ automatically included
|
177
|
+
# @param [List<String>, Array<String>] i include file(s)
|
178
|
+
# @return [Array<String>] array of include files
|
179
|
+
def include(*i)
|
180
|
+
@includes |= i.flatten
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
# This class hold constants for {ConstGenerator}
|
186
|
+
class ConstGenerator::Constant
|
187
|
+
|
188
|
+
attr_reader :name, :format, :cast
|
189
|
+
attr_accessor :value
|
190
|
+
|
191
|
+
# @param [#to_s] name
|
192
|
+
# @param [String] format a printf format string to print the value out
|
193
|
+
# @param [String] cast a C cast for the value
|
194
|
+
# @param ruby_name alternate ruby name for {#to_ruby}
|
195
|
+
# @param [#call] converter convert the value from a string to the appropriate
|
196
|
+
# type for {#to_ruby}.
|
197
|
+
def initialize(name, format, cast, ruby_name = nil, converter=nil)
|
198
|
+
@name = name
|
199
|
+
@format = format
|
200
|
+
@cast = cast
|
201
|
+
@ruby_name = ruby_name
|
202
|
+
@converter = converter
|
203
|
+
@value = nil
|
204
|
+
end
|
205
|
+
|
206
|
+
# Return constant value (converted if a +converter+ was defined).
|
207
|
+
# @return constant value.
|
208
|
+
def converted_value
|
209
|
+
if @converter
|
210
|
+
@converter.call(@value)
|
211
|
+
else
|
212
|
+
@value
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# get constant ruby name
|
217
|
+
# @return [String]
|
218
|
+
def ruby_name
|
219
|
+
@ruby_name || @name
|
220
|
+
end
|
221
|
+
|
222
|
+
# Get an evaluable string from constant.
|
223
|
+
# @return [String]
|
224
|
+
def to_ruby
|
225
|
+
"#{ruby_name} = #{converted_value}"
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|