ffi 1.9.3-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ffi might be problematic. Click here for more details.
- data/COPYING +49 -0
- data/LICENSE +24 -0
- data/README.md +109 -0
- data/Rakefile +220 -0
- data/ext/ffi_c/AbstractMemory.c +1032 -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 +465 -0
- data/ext/ffi_c/Call.h +93 -0
- data/ext/ffi_c/ClosurePool.c +283 -0
- data/ext/ffi_c/ClosurePool.h +57 -0
- data/ext/ffi_c/DataConverter.c +91 -0
- data/ext/ffi_c/DynamicLibrary.c +333 -0
- data/ext/ffi_c/DynamicLibrary.h +49 -0
- data/ext/ffi_c/Function.c +999 -0
- data/ext/ffi_c/Function.h +87 -0
- data/ext/ffi_c/FunctionInfo.c +271 -0
- data/ext/ffi_c/LastError.c +184 -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 +360 -0
- data/ext/ffi_c/MethodHandle.h +55 -0
- data/ext/ffi_c/Platform.c +121 -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 +828 -0
- data/ext/ffi_c/Struct.h +106 -0
- data/ext/ffi_c/StructByReference.c +190 -0
- data/ext/ffi_c/StructByReference.h +50 -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 +352 -0
- data/ext/ffi_c/Thread.h +95 -0
- data/ext/ffi_c/Type.c +397 -0
- data/ext/ffi_c/Type.h +62 -0
- data/ext/ffi_c/Types.c +139 -0
- data/ext/ffi_c/Types.h +89 -0
- data/ext/ffi_c/Variadic.c +276 -0
- data/ext/ffi_c/compat.h +83 -0
- data/ext/ffi_c/extconf.rb +64 -0
- data/ext/ffi_c/ffi.c +98 -0
- data/ext/ffi_c/libffi.bsd.mk +34 -0
- data/ext/ffi_c/libffi.darwin.mk +95 -0
- data/ext/ffi_c/libffi.gnu.mk +31 -0
- data/ext/ffi_c/libffi.mk +13 -0
- data/ext/ffi_c/libffi.vc.mk +26 -0
- data/ext/ffi_c/libffi.vc64.mk +26 -0
- data/ext/ffi_c/libffi/ChangeLog +4600 -0
- data/ext/ffi_c/libffi/ChangeLog.libffi +584 -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/Makefile.am +196 -0
- data/ext/ffi_c/libffi/Makefile.in +1820 -0
- data/ext/ffi_c/libffi/Makefile.vc +141 -0
- data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
- data/ext/ffi_c/libffi/README +342 -0
- data/ext/ffi_c/libffi/acinclude.m4 +92 -0
- data/ext/ffi_c/libffi/aclocal.m4 +1873 -0
- data/ext/ffi_c/libffi/build-ios.sh +67 -0
- data/ext/ffi_c/libffi/compile +143 -0
- data/ext/ffi_c/libffi/config.guess +1501 -0
- data/ext/ffi_c/libffi/config.sub +1705 -0
- data/ext/ffi_c/libffi/configure +17191 -0
- data/ext/ffi_c/libffi/configure.ac +496 -0
- data/ext/ffi_c/libffi/configure.host +11 -0
- data/ext/ffi_c/libffi/depcomp +630 -0
- data/ext/ffi_c/libffi/doc/libffi.info +593 -0
- data/ext/ffi_c/libffi/doc/libffi.texi +600 -0
- data/ext/ffi_c/libffi/doc/stamp-vti +4 -0
- data/ext/ffi_c/libffi/doc/version.texi +4 -0
- data/ext/ffi_c/libffi/fficonfig.h.in +199 -0
- data/ext/ffi_c/libffi/fficonfig.hw +57 -0
- data/ext/ffi_c/libffi/include/Makefile.am +9 -0
- data/ext/ffi_c/libffi/include/Makefile.in +487 -0
- data/ext/ffi_c/libffi/include/ffi.h.in +427 -0
- data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
- data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +126 -0
- data/ext/ffi_c/libffi/install-sh +520 -0
- data/ext/ffi_c/libffi/libffi.pc.in +10 -0
- data/ext/ffi_c/libffi/libtool-version +29 -0
- data/ext/ffi_c/libffi/ltmain.sh +9636 -0
- data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
- data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
- data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
- data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
- data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
- data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
- data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
- data/ext/ffi_c/libffi/m4/libtool.m4 +7831 -0
- data/ext/ffi_c/libffi/m4/ltoptions.m4 +369 -0
- data/ext/ffi_c/libffi/m4/ltsugar.m4 +123 -0
- data/ext/ffi_c/libffi/m4/ltversion.m4 +23 -0
- data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +98 -0
- data/ext/ffi_c/libffi/man/Makefile.am +8 -0
- data/ext/ffi_c/libffi/man/Makefile.in +466 -0
- data/ext/ffi_c/libffi/man/ffi.3 +31 -0
- data/ext/ffi_c/libffi/man/ffi_call.3 +103 -0
- data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +66 -0
- data/ext/ffi_c/libffi/mdate-sh +201 -0
- data/ext/ffi_c/libffi/missing +376 -0
- data/ext/ffi_c/libffi/msvcc.sh +197 -0
- data/ext/ffi_c/libffi/src/alpha/ffi.c +284 -0
- data/ext/ffi_c/libffi/src/alpha/ffitarget.h +48 -0
- data/ext/ffi_c/libffi/src/alpha/osf.S +387 -0
- data/ext/ffi_c/libffi/src/arm/ffi.c +728 -0
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +65 -0
- data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +497 -0
- data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
- data/ext/ffi_c/libffi/src/avr32/ffi.c +423 -0
- data/ext/ffi_c/libffi/src/avr32/ffitarget.h +50 -0
- data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
- data/ext/ffi_c/libffi/src/closures.c +615 -0
- data/ext/ffi_c/libffi/src/cris/ffi.c +383 -0
- data/ext/ffi_c/libffi/src/cris/ffitarget.h +51 -0
- data/ext/ffi_c/libffi/src/cris/sysv.S +215 -0
- data/ext/ffi_c/libffi/src/debug.c +59 -0
- data/ext/ffi_c/libffi/src/dlmalloc.c +5161 -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 +57 -0
- data/ext/ffi_c/libffi/src/ia64/ffi.c +582 -0
- data/ext/ffi_c/libffi/src/ia64/ffitarget.h +50 -0
- data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +40 -0
- data/ext/ffi_c/libffi/src/ia64/unix.S +560 -0
- data/ext/ffi_c/libffi/src/java_raw_api.c +356 -0
- data/ext/ffi_c/libffi/src/m32r/ffi.c +232 -0
- data/ext/ffi_c/libffi/src/m32r/ffitarget.h +48 -0
- data/ext/ffi_c/libffi/src/m32r/sysv.S +121 -0
- data/ext/ffi_c/libffi/src/m68k/ffi.c +288 -0
- data/ext/ffi_c/libffi/src/m68k/ffitarget.h +49 -0
- data/ext/ffi_c/libffi/src/m68k/sysv.S +270 -0
- data/ext/ffi_c/libffi/src/mips/ffi.c +1036 -0
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +242 -0
- data/ext/ffi_c/libffi/src/mips/n32.S +591 -0
- data/ext/ffi_c/libffi/src/mips/o32.S +381 -0
- data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
- data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
- data/ext/ffi_c/libffi/src/pa/ffi.c +719 -0
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +78 -0
- data/ext/ffi_c/libffi/src/pa/hpux32.S +368 -0
- data/ext/ffi_c/libffi/src/pa/linux.S +357 -0
- data/ext/ffi_c/libffi/src/powerpc/aix.S +328 -0
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +445 -0
- data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
- data/ext/ffi_c/libffi/src/powerpc/darwin.S +383 -0
- data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +575 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +1448 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +1359 -0
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +139 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +187 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +236 -0
- data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +327 -0
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +219 -0
- data/ext/ffi_c/libffi/src/prep_cif.c +177 -0
- data/ext/ffi_c/libffi/src/raw_api.c +254 -0
- data/ext/ffi_c/libffi/src/s390/ffi.c +780 -0
- data/ext/ffi_c/libffi/src/s390/ffitarget.h +62 -0
- data/ext/ffi_c/libffi/src/s390/sysv.S +434 -0
- data/ext/ffi_c/libffi/src/sh/ffi.c +716 -0
- data/ext/ffi_c/libffi/src/sh/ffitarget.h +49 -0
- data/ext/ffi_c/libffi/src/sh/sysv.S +850 -0
- data/ext/ffi_c/libffi/src/sh64/ffi.c +468 -0
- data/ext/ffi_c/libffi/src/sh64/ffitarget.h +53 -0
- data/ext/ffi_c/libffi/src/sh64/sysv.S +539 -0
- data/ext/ffi_c/libffi/src/sparc/ffi.c +669 -0
- data/ext/ffi_c/libffi/src/sparc/ffitarget.h +68 -0
- data/ext/ffi_c/libffi/src/sparc/v8.S +313 -0
- data/ext/ffi_c/libffi/src/sparc/v9.S +307 -0
- data/ext/ffi_c/libffi/src/types.c +77 -0
- data/ext/ffi_c/libffi/src/x86/darwin.S +444 -0
- data/ext/ffi_c/libffi/src/x86/darwin64.S +416 -0
- data/ext/ffi_c/libffi/src/x86/ffi.c +644 -0
- data/ext/ffi_c/libffi/src/x86/ffi64.c +635 -0
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +121 -0
- data/ext/ffi_c/libffi/src/x86/freebsd.S +458 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +468 -0
- data/ext/ffi_c/libffi/src/x86/unix64.S +426 -0
- data/ext/ffi_c/libffi/src/x86/win32.S +1065 -0
- data/ext/ffi_c/libffi/src/x86/win64.S +468 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.am +80 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.in +500 -0
- data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
- data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +300 -0
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
- data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +263 -0
- data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +45 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +32 -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_stdcall.c +64 -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_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 +134 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +117 -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 +60 -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 +60 -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 +140 -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_uchar.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +43 -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/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 +153 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +59 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +58 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +58 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +72 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +62 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +342 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +69 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +53 -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 +133 -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/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 +35 -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/strlen_win32.c +44 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +59 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +65 -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 +80 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +96 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +35 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc +53 -0
- data/ext/ffi_c/libffi/texinfo.tex +7210 -0
- data/ext/ffi_c/rbffi.h +57 -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 +22 -0
- data/gen/Rakefile +30 -0
- data/lib/ffi.rb +28 -0
- data/lib/ffi/autopointer.rb +194 -0
- data/lib/ffi/buffer.rb +4 -0
- data/lib/ffi/callback.rb +4 -0
- data/lib/ffi/enum.rb +173 -0
- data/lib/ffi/errno.rb +43 -0
- data/lib/ffi/ffi.rb +44 -0
- data/lib/ffi/io.rb +62 -0
- data/lib/ffi/library.rb +499 -0
- data/lib/ffi/managedstruct.rb +84 -0
- data/lib/ffi/memorypointer.rb +1 -0
- data/lib/ffi/platform.rb +148 -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-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/mipsel-linux/types.conf +102 -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/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/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 +100 -0
- data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
- data/lib/ffi/platform/x86_64-linux/types.conf +102 -0
- data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
- data/lib/ffi/platform/x86_64-openbsd/types.conf +128 -0
- data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
- data/lib/ffi/platform/x86_64-windows/types.conf +27 -0
- data/lib/ffi/pointer.rb +134 -0
- data/lib/ffi/struct.rb +367 -0
- data/lib/ffi/struct_layout_builder.rb +222 -0
- data/lib/ffi/tools/const_generator.rb +229 -0
- data/lib/ffi/tools/generator.rb +60 -0
- data/lib/ffi/tools/generator_task.rb +36 -0
- data/lib/ffi/tools/struct_generator.rb +194 -0
- data/lib/ffi/tools/types_generator.rb +135 -0
- data/lib/ffi/types.rb +190 -0
- data/lib/ffi/union.rb +43 -0
- data/lib/ffi/variadic.rb +78 -0
- data/lib/ffi/version.rb +4 -0
- data/lib/ffi_c.so +0 -0
- data/libtest/Benchmark.c +52 -0
- data/libtest/BoolTest.c +34 -0
- data/libtest/BufferTest.c +31 -0
- data/libtest/ClosureTest.c +190 -0
- data/libtest/EnumTest.c +34 -0
- data/libtest/FunctionTest.c +58 -0
- data/libtest/GNUmakefile +149 -0
- data/libtest/GlobalVariable.c +62 -0
- data/libtest/LastErrorTest.c +21 -0
- data/libtest/NumberTest.c +132 -0
- data/libtest/PointerTest.c +63 -0
- data/libtest/ReferenceTest.c +23 -0
- data/libtest/StringTest.c +34 -0
- data/libtest/StructTest.c +243 -0
- data/libtest/UnionTest.c +43 -0
- data/libtest/VariadicTest.c +62 -0
- data/spec/ffi/async_callback_spec.rb +35 -0
- data/spec/ffi/bool_spec.rb +29 -0
- data/spec/ffi/buffer_spec.rb +251 -0
- data/spec/ffi/callback_spec.rb +667 -0
- data/spec/ffi/custom_param_type.rb +36 -0
- data/spec/ffi/custom_type_spec.rb +74 -0
- data/spec/ffi/dup_spec.rb +54 -0
- data/spec/ffi/enum_spec.rb +220 -0
- data/spec/ffi/errno_spec.rb +18 -0
- data/spec/ffi/ffi_spec.rb +29 -0
- data/spec/ffi/function_spec.rb +76 -0
- data/spec/ffi/library_spec.rb +216 -0
- data/spec/ffi/long_double.rb +30 -0
- data/spec/ffi/managed_struct_spec.rb +57 -0
- data/spec/ffi/number_spec.rb +236 -0
- data/spec/ffi/pointer_spec.rb +265 -0
- data/spec/ffi/rbx/attach_function_spec.rb +28 -0
- data/spec/ffi/rbx/memory_pointer_spec.rb +123 -0
- data/spec/ffi/rbx/spec_helper.rb +1 -0
- data/spec/ffi/rbx/struct_spec.rb +13 -0
- data/spec/ffi/spec_helper.rb +33 -0
- data/spec/ffi/string_spec.rb +108 -0
- data/spec/ffi/strptr_spec.rb +50 -0
- data/spec/ffi/struct_by_ref_spec.rb +43 -0
- data/spec/ffi/struct_callback_spec.rb +69 -0
- data/spec/ffi/struct_initialize_spec.rb +35 -0
- data/spec/ffi/struct_packed_spec.rb +51 -0
- data/spec/ffi/struct_spec.rb +748 -0
- data/spec/ffi/typedef_spec.rb +78 -0
- data/spec/ffi/union_spec.rb +65 -0
- data/spec/ffi/variadic_spec.rb +92 -0
- data/spec/spec.opts +4 -0
- metadata +562 -0
data/lib/ffi/buffer.rb
ADDED
data/lib/ffi/callback.rb
ADDED
data/lib/ffi/enum.rb
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2009, 2010 Wayne Meissner
|
3
|
+
# Copyright (C) 2009 Luc Heinrich
|
4
|
+
#
|
5
|
+
# This file is part of ruby-ffi.
|
6
|
+
#
|
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
|
+
#
|
12
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
13
|
+
# list of conditions and the following disclaimer.
|
14
|
+
# * Redistributions in binary form must reproduce the above copyright notice
|
15
|
+
# this list of conditions and the following disclaimer in the documentation
|
16
|
+
# and/or other materials provided with the distribution.
|
17
|
+
# * Neither the name of the Ruby FFI project nor the names of its contributors
|
18
|
+
# may be used to endorse or promote products derived from this software
|
19
|
+
# without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
22
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
25
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
29
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
#
|
32
|
+
|
33
|
+
module FFI
|
34
|
+
|
35
|
+
# An instance of this class permits to manage {Enum}s. In fact, Enums is a collection of {Enum}s.
|
36
|
+
class Enums
|
37
|
+
|
38
|
+
# @return [nil]
|
39
|
+
def initialize
|
40
|
+
@all_enums = Array.new
|
41
|
+
@tagged_enums = Hash.new
|
42
|
+
@symbol_map = Hash.new
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param [Enum] enum
|
46
|
+
# Add an {Enum} to the collection.
|
47
|
+
def <<(enum)
|
48
|
+
@all_enums << enum
|
49
|
+
@tagged_enums[enum.tag] = enum unless enum.tag.nil?
|
50
|
+
@symbol_map.merge!(enum.symbol_map)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @param query enum tag or part of an enum name
|
54
|
+
# @return [Enum]
|
55
|
+
# Find a {Enum} in collection.
|
56
|
+
def find(query)
|
57
|
+
if @tagged_enums.has_key?(query)
|
58
|
+
@tagged_enums[query]
|
59
|
+
else
|
60
|
+
@all_enums.detect { |enum| enum.symbols.include?(query) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param symbol a symbol to find in merge symbol maps of all enums.
|
65
|
+
# @return a symbol
|
66
|
+
def __map_symbol(symbol)
|
67
|
+
@symbol_map[symbol]
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
# Represents a C enum.
|
73
|
+
#
|
74
|
+
# For a C enum:
|
75
|
+
# enum fruits {
|
76
|
+
# apple,
|
77
|
+
# banana,
|
78
|
+
# orange,
|
79
|
+
# pineapple
|
80
|
+
# };
|
81
|
+
# are defined this vocabulary:
|
82
|
+
# * a _symbol_ is a word from the enumeration (ie. _apple_, by example);
|
83
|
+
# * a _value_ is the value of a symbol in the enumeration (by example, apple has value _0_ and banana _1_).
|
84
|
+
class Enum
|
85
|
+
include DataConverter
|
86
|
+
|
87
|
+
attr_reader :tag
|
88
|
+
|
89
|
+
# @param [nil, Enumerable] info
|
90
|
+
# @param tag enum tag
|
91
|
+
def initialize(info, tag=nil)
|
92
|
+
@tag = tag
|
93
|
+
@kv_map = Hash.new
|
94
|
+
unless info.nil?
|
95
|
+
last_cst = nil
|
96
|
+
value = 0
|
97
|
+
info.each do |i|
|
98
|
+
case i
|
99
|
+
when Symbol
|
100
|
+
raise ArgumentError, "duplicate enum key" if @kv_map.has_key?(i)
|
101
|
+
@kv_map[i] = value
|
102
|
+
last_cst = i
|
103
|
+
value += 1
|
104
|
+
when Integer
|
105
|
+
@kv_map[last_cst] = i
|
106
|
+
value = i+1
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
@vk_map = @kv_map.invert
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [Array] enum symbol names
|
114
|
+
def symbols
|
115
|
+
@kv_map.keys
|
116
|
+
end
|
117
|
+
|
118
|
+
# Get a symbol or a value from the enum.
|
119
|
+
# @overload [](query)
|
120
|
+
# Get enum value from symbol.
|
121
|
+
# @param [Symbol] query
|
122
|
+
# @return [Integer]
|
123
|
+
# @overload [](query)
|
124
|
+
# Get enum symbol from value.
|
125
|
+
# @param [Integer] query
|
126
|
+
# @return [Symbol]
|
127
|
+
def [](query)
|
128
|
+
case query
|
129
|
+
when Symbol
|
130
|
+
@kv_map[query]
|
131
|
+
when Integer
|
132
|
+
@vk_map[query]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
alias find []
|
136
|
+
|
137
|
+
# Get the symbol map.
|
138
|
+
# @return [Hash]
|
139
|
+
def symbol_map
|
140
|
+
@kv_map
|
141
|
+
end
|
142
|
+
|
143
|
+
alias to_h symbol_map
|
144
|
+
alias to_hash symbol_map
|
145
|
+
|
146
|
+
# Get native type of Enum
|
147
|
+
# @return [Type::INT]
|
148
|
+
def native_type
|
149
|
+
Type::INT
|
150
|
+
end
|
151
|
+
|
152
|
+
# @param [Symbol, Integer, #to_int] val
|
153
|
+
# @param ctx unused
|
154
|
+
# @return [Integer] value of a enum symbol
|
155
|
+
def to_native(val, ctx)
|
156
|
+
@kv_map[val] || if val.is_a?(Integer)
|
157
|
+
val
|
158
|
+
elsif val.respond_to?(:to_int)
|
159
|
+
val.to_int
|
160
|
+
else
|
161
|
+
raise ArgumentError, "invalid enum value, #{val.inspect}"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# @param val
|
166
|
+
# @return symbol name if it exists for +val+.
|
167
|
+
def from_native(val, ctx)
|
168
|
+
@vk_map[val] || val
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
data/lib/ffi/errno.rb
ADDED
@@ -0,0 +1,43 @@
|
|
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
|
+
module FFI
|
32
|
+
# @return (see FFI::LastError.error)
|
33
|
+
# @see FFI::LastError.error
|
34
|
+
def self.errno
|
35
|
+
FFI::LastError.error
|
36
|
+
end
|
37
|
+
# @param error (see FFI::LastError.error=)
|
38
|
+
# @return (see FFI::LastError.error=)
|
39
|
+
# @see FFI::LastError.error=
|
40
|
+
def self.errno=(error)
|
41
|
+
FFI::LastError.error = error
|
42
|
+
end
|
43
|
+
end
|
data/lib/ffi/ffi.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2008-2010 JRuby project
|
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
|
+
require 'ffi/platform'
|
32
|
+
require 'ffi/types'
|
33
|
+
require 'ffi/library'
|
34
|
+
require 'ffi/errno'
|
35
|
+
require 'ffi/pointer'
|
36
|
+
require 'ffi/memorypointer'
|
37
|
+
require 'ffi/struct'
|
38
|
+
require 'ffi/union'
|
39
|
+
require 'ffi/managedstruct'
|
40
|
+
require 'ffi/callback'
|
41
|
+
require 'ffi/io'
|
42
|
+
require 'ffi/autopointer'
|
43
|
+
require 'ffi/variadic'
|
44
|
+
require 'ffi/enum'
|
data/lib/ffi/io.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2008, 2009 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
|
+
|
33
|
+
# This module implements a couple of class methods to play with IO.
|
34
|
+
module IO
|
35
|
+
# @param [Integer] fd file decriptor
|
36
|
+
# @param [String] mode mode string
|
37
|
+
# @return [::IO]
|
38
|
+
# Synonym for IO::for_fd.
|
39
|
+
def self.for_fd(fd, mode = "r")
|
40
|
+
::IO.for_fd(fd, mode)
|
41
|
+
end
|
42
|
+
|
43
|
+
# @param [#read] io io to read from
|
44
|
+
# @param [AbstractMemory] buf destination for data read from +io+
|
45
|
+
# @param [nil, Numeric] len maximul number of bytes to read from +io+. If +nil+,
|
46
|
+
# read until end of file.
|
47
|
+
# @return [Numeric] length really read, in bytes
|
48
|
+
#
|
49
|
+
# A version of IO#read that reads data from an IO and put then into a native buffer.
|
50
|
+
#
|
51
|
+
# This will be optimized at some future time to eliminate the double copy.
|
52
|
+
#
|
53
|
+
def self.native_read(io, buf, len)
|
54
|
+
tmp = io.read(len)
|
55
|
+
return -1 unless tmp
|
56
|
+
buf.put_bytes(0, tmp)
|
57
|
+
tmp.length
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/ffi/library.rb
ADDED
@@ -0,0 +1,499 @@
|
|
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
|
+
module FFI
|
32
|
+
CURRENT_PROCESS = USE_THIS_PROCESS_AS_LIBRARY = Object.new
|
33
|
+
|
34
|
+
# @param [#to_s] lib library name
|
35
|
+
# @return [String] library name formatted for current platform
|
36
|
+
# Transform a generic library name to a platform library name
|
37
|
+
# @example
|
38
|
+
# # Linux
|
39
|
+
# FFI.map_library_name 'c' # -> "libc.so.6"
|
40
|
+
# FFI.map_library_name 'jpeg' # -> "libjpeg.so"
|
41
|
+
# # Windows
|
42
|
+
# FFI.map_library_name 'c' # -> "msvcrt.dll"
|
43
|
+
# FFI.map_library_name 'jpeg' # -> "jpeg.dll"
|
44
|
+
def self.map_library_name(lib)
|
45
|
+
# Mangle the library name to reflect the native library naming conventions
|
46
|
+
lib = lib.to_s unless lib.kind_of?(String)
|
47
|
+
lib = Library::LIBC if lib == 'c'
|
48
|
+
|
49
|
+
if lib && File.basename(lib) == lib
|
50
|
+
lib = Platform::LIBPREFIX + lib unless lib =~ /^#{Platform::LIBPREFIX}/
|
51
|
+
r = Platform::IS_GNU ? "\\.so($|\\.[1234567890]+)" : "\\.#{Platform::LIBSUFFIX}$"
|
52
|
+
lib += ".#{Platform::LIBSUFFIX}" unless lib =~ /#{r}/
|
53
|
+
end
|
54
|
+
|
55
|
+
lib
|
56
|
+
end
|
57
|
+
|
58
|
+
# Exception raised when a function is not found in libraries
|
59
|
+
class NotFoundError < LoadError
|
60
|
+
def initialize(function, *libraries)
|
61
|
+
super("Function '#{function}' not found in [#{libraries[0].nil? ? 'current process' : libraries.join(", ")}]")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# This module is the base to use native functions.
|
66
|
+
#
|
67
|
+
# A basic usage may be:
|
68
|
+
# require 'ffi'
|
69
|
+
#
|
70
|
+
# module Hello
|
71
|
+
# extend FFI::Library
|
72
|
+
# ffi_lib FFI::Library::LIBC
|
73
|
+
# attach_function 'puts', [ :string ], :int
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# Hello.puts("Hello, World")
|
77
|
+
#
|
78
|
+
#
|
79
|
+
module Library
|
80
|
+
CURRENT_PROCESS = FFI::CURRENT_PROCESS
|
81
|
+
LIBC = FFI::Platform::LIBC
|
82
|
+
|
83
|
+
# @param mod extended object
|
84
|
+
# @return [nil]
|
85
|
+
# @raise {RuntimeError} if +mod+ is not a Module
|
86
|
+
# Test if extended object is a Module. If not, raise RuntimeError.
|
87
|
+
def self.extended(mod)
|
88
|
+
raise RuntimeError.new("must only be extended by module") unless mod.kind_of?(Module)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# @param [Array] names names of libraries to load
|
93
|
+
# @return [Array<DynamicLibrary>]
|
94
|
+
# @raise {LoadError} if a library cannot be opened
|
95
|
+
# Load native libraries.
|
96
|
+
def ffi_lib(*names)
|
97
|
+
raise LoadError.new("library names list must not be empty") if names.empty?
|
98
|
+
|
99
|
+
lib_flags = defined?(@ffi_lib_flags) ? @ffi_lib_flags : FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL
|
100
|
+
ffi_libs = names.map do |name|
|
101
|
+
|
102
|
+
if name == FFI::CURRENT_PROCESS
|
103
|
+
FFI::DynamicLibrary.open(nil, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL)
|
104
|
+
|
105
|
+
else
|
106
|
+
libnames = (name.is_a?(::Array) ? name : [ name ]).map { |n| [ n, FFI.map_library_name(n) ].uniq }.flatten.compact
|
107
|
+
lib = nil
|
108
|
+
errors = {}
|
109
|
+
|
110
|
+
libnames.each do |libname|
|
111
|
+
begin
|
112
|
+
lib = FFI::DynamicLibrary.open(libname, lib_flags)
|
113
|
+
break if lib
|
114
|
+
|
115
|
+
rescue Exception => ex
|
116
|
+
ldscript = false
|
117
|
+
if ex.message =~ /(([^ \t()])+\.so([^ \t:()])*):([ \t])*invalid ELF header/
|
118
|
+
if File.read($1) =~ /GROUP *\( *([^ \)]+) *\)/
|
119
|
+
libname = $1
|
120
|
+
ldscript = true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
if ldscript
|
125
|
+
retry
|
126
|
+
else
|
127
|
+
errors[libname] = ex
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
if lib.nil?
|
133
|
+
raise LoadError.new(errors.values.join(".\n"))
|
134
|
+
end
|
135
|
+
|
136
|
+
# return the found lib
|
137
|
+
lib
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
@ffi_libs = ffi_libs
|
142
|
+
end
|
143
|
+
|
144
|
+
# Set the calling convention for {#attach_function} and {#callback}
|
145
|
+
#
|
146
|
+
# @see http://en.wikipedia.org/wiki/Stdcall#stdcall
|
147
|
+
# @note +:stdcall+ is typically used for attaching Windows API functions
|
148
|
+
#
|
149
|
+
# @param [Symbol] convention one of +:default+, +:stdcall+
|
150
|
+
# @return [Symbol] the new calling convention
|
151
|
+
def ffi_convention(convention = nil)
|
152
|
+
@ffi_convention ||= :default
|
153
|
+
@ffi_convention = convention if convention
|
154
|
+
@ffi_convention
|
155
|
+
end
|
156
|
+
|
157
|
+
# @see #ffi_lib
|
158
|
+
# @return [Array<FFI::DynamicLibrary>] array of currently loaded FFI libraries
|
159
|
+
# @raise [LoadError] if no libraries have been loaded (using {#ffi_lib})
|
160
|
+
# Get FFI libraries loaded using {#ffi_lib}.
|
161
|
+
def ffi_libraries
|
162
|
+
raise LoadError.new("no library specified") if !defined?(@ffi_libs) || @ffi_libs.empty?
|
163
|
+
@ffi_libs
|
164
|
+
end
|
165
|
+
|
166
|
+
# Flags used in {#ffi_lib}.
|
167
|
+
#
|
168
|
+
# This map allows you to supply symbols to {#ffi_lib_flags} instead of
|
169
|
+
# the actual constants.
|
170
|
+
FlagsMap = {
|
171
|
+
:global => DynamicLibrary::RTLD_GLOBAL,
|
172
|
+
:local => DynamicLibrary::RTLD_LOCAL,
|
173
|
+
:lazy => DynamicLibrary::RTLD_LAZY,
|
174
|
+
:now => DynamicLibrary::RTLD_NOW
|
175
|
+
}
|
176
|
+
|
177
|
+
# Sets library flags for {#ffi_lib}.
|
178
|
+
#
|
179
|
+
# @example
|
180
|
+
# ffi_lib_flags(:lazy, :local) # => 5
|
181
|
+
#
|
182
|
+
# @param [Symbol, …] flags (see {FlagsMap})
|
183
|
+
# @return [Fixnum] the new value
|
184
|
+
def ffi_lib_flags(*flags)
|
185
|
+
@ffi_lib_flags = flags.inject(0) { |result, f| result | FlagsMap[f] }
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
##
|
190
|
+
# @overload attach_function(func, args, returns, options = {})
|
191
|
+
# @example attach function without an explicit name
|
192
|
+
# module Foo
|
193
|
+
# extend FFI::Library
|
194
|
+
# ffi_lib FFI::Library::LIBC
|
195
|
+
# attach_function :malloc, [:size_t], :pointer
|
196
|
+
# end
|
197
|
+
# # now callable via Foo.malloc
|
198
|
+
# @overload attach_function(name, func, args, returns, options = {})
|
199
|
+
# @example attach function with an explicit name
|
200
|
+
# module Bar
|
201
|
+
# extend FFI::Library
|
202
|
+
# ffi_lib FFI::Library::LIBC
|
203
|
+
# attach_function :c_malloc, :malloc, [:size_t], :pointer
|
204
|
+
# end
|
205
|
+
# # now callable via Bar.c_malloc
|
206
|
+
#
|
207
|
+
# Attach C function +func+ to this module.
|
208
|
+
#
|
209
|
+
#
|
210
|
+
# @param [#to_s] name name of ruby method to attach as
|
211
|
+
# @param [#to_s] func name of C function to attach
|
212
|
+
# @param [Array<Symbol>] args an array of types
|
213
|
+
# @param [Symbol] returns type of return value
|
214
|
+
# @option options [Boolean] :blocking (@blocking) set to true if the C function is a blocking call
|
215
|
+
# @option options [Symbol] :convention (:default) calling convention (see {#ffi_convention})
|
216
|
+
# @option options [FFI::Enums] :enums
|
217
|
+
# @option options [Hash] :type_map
|
218
|
+
#
|
219
|
+
# @return [FFI::VariadicInvoker]
|
220
|
+
#
|
221
|
+
# @raise [FFI::NotFoundError] if +func+ cannot be found in the attached libraries (see {#ffi_lib})
|
222
|
+
def attach_function(name, func, args, returns = nil, options = nil)
|
223
|
+
mname, a2, a3, a4, a5 = name, func, args, returns, options
|
224
|
+
cname, arg_types, ret_type, opts = (a4 && (a2.is_a?(String) || a2.is_a?(Symbol))) ? [ a2, a3, a4, a5 ] : [ mname.to_s, a2, a3, a4 ]
|
225
|
+
|
226
|
+
# Convert :foo to the native type
|
227
|
+
arg_types = arg_types.map { |e| find_type(e) }
|
228
|
+
options = {
|
229
|
+
:convention => ffi_convention,
|
230
|
+
:type_map => defined?(@ffi_typedefs) ? @ffi_typedefs : nil,
|
231
|
+
:blocking => defined?(@blocking) && @blocking,
|
232
|
+
:enums => defined?(@ffi_enums) ? @ffi_enums : nil,
|
233
|
+
}
|
234
|
+
|
235
|
+
@blocking = false
|
236
|
+
options.merge!(opts) if opts && opts.is_a?(Hash)
|
237
|
+
|
238
|
+
# Try to locate the function in any of the libraries
|
239
|
+
invokers = []
|
240
|
+
ffi_libraries.each do |lib|
|
241
|
+
if invokers.empty?
|
242
|
+
begin
|
243
|
+
function = nil
|
244
|
+
function_names(cname, arg_types).find do |fname|
|
245
|
+
function = lib.find_function(fname)
|
246
|
+
end
|
247
|
+
raise LoadError unless function
|
248
|
+
|
249
|
+
invokers << if arg_types.length > 0 && arg_types[arg_types.length - 1] == FFI::NativeType::VARARGS
|
250
|
+
VariadicInvoker.new(function, arg_types, find_type(ret_type), options)
|
251
|
+
|
252
|
+
else
|
253
|
+
Function.new(find_type(ret_type), arg_types, function, options)
|
254
|
+
end
|
255
|
+
|
256
|
+
rescue LoadError
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
invoker = invokers.compact.shift
|
261
|
+
raise FFI::NotFoundError.new(cname.to_s, ffi_libraries.map { |lib| lib.name }) unless invoker
|
262
|
+
|
263
|
+
invoker.attach(self, mname.to_s)
|
264
|
+
invoker
|
265
|
+
end
|
266
|
+
|
267
|
+
# @param [#to_s] name function name
|
268
|
+
# @param [Array] arg_types function's argument types
|
269
|
+
# @return [Array<String>]
|
270
|
+
# This function returns a list of possible names to lookup.
|
271
|
+
# @note Function names on windows may be decorated if they are using stdcall. See
|
272
|
+
# * http://en.wikipedia.org/wiki/Name_mangling#C_name_decoration_in_Microsoft_Windows
|
273
|
+
# * http://msdn.microsoft.com/en-us/library/zxk0tw93%28v=VS.100%29.aspx
|
274
|
+
# * http://en.wikibooks.org/wiki/X86_Disassembly/Calling_Conventions#STDCALL
|
275
|
+
# Note that decorated names can be overridden via def files. Also note that the
|
276
|
+
# windows api, although using, doesn't have decorated names.
|
277
|
+
def function_names(name, arg_types)
|
278
|
+
result = [name.to_s]
|
279
|
+
if ffi_convention == :stdcall
|
280
|
+
# Get the size of each parameter
|
281
|
+
size = arg_types.inject(0) do |mem, arg|
|
282
|
+
mem + arg.size
|
283
|
+
end
|
284
|
+
|
285
|
+
# Next, the size must be a multiple of 4
|
286
|
+
size += (4 - size) % 4
|
287
|
+
|
288
|
+
result << "_#{name.to_s}@#{size}" # win32
|
289
|
+
result << "#{name.to_s}@#{size}" # win64
|
290
|
+
end
|
291
|
+
result
|
292
|
+
end
|
293
|
+
|
294
|
+
# @overload attach_variable(mname, cname, type)
|
295
|
+
# @example
|
296
|
+
# module Bar
|
297
|
+
# extend FFI::Library
|
298
|
+
# ffi_lib 'my_lib'
|
299
|
+
# attach_variable :c_myvar, :myvar, :long
|
300
|
+
# end
|
301
|
+
# # now callable via Bar.c_myvar
|
302
|
+
# @overload attach_variable(cname, type)
|
303
|
+
# @example
|
304
|
+
# module Bar
|
305
|
+
# extend FFI::Library
|
306
|
+
# ffi_lib 'my_lib'
|
307
|
+
# attach_variable :myvar, :long
|
308
|
+
# end
|
309
|
+
# # now callable via Bar.myvar
|
310
|
+
# @param [#to_s] mname name of ruby method to attach as
|
311
|
+
# @param [#to_s] cname name of C variable to attach
|
312
|
+
# @param [DataConverter, Struct, Symbol, Type] type C varaible's type
|
313
|
+
# @return [DynamicLibrary::Symbol]
|
314
|
+
# @raise {FFI::NotFoundError} if +cname+ cannot be found in libraries
|
315
|
+
#
|
316
|
+
# Attach C variable +cname+ to this module.
|
317
|
+
def attach_variable(mname, a1, a2 = nil)
|
318
|
+
cname, type = a2 ? [ a1, a2 ] : [ mname.to_s, a1 ]
|
319
|
+
address = nil
|
320
|
+
ffi_libraries.each do |lib|
|
321
|
+
begin
|
322
|
+
address = lib.find_variable(cname.to_s)
|
323
|
+
break unless address.nil?
|
324
|
+
rescue LoadError
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
raise FFI::NotFoundError.new(cname, ffi_libraries) if address.nil? || address.null?
|
329
|
+
if type.is_a?(Class) && type < FFI::Struct
|
330
|
+
# If it is a global struct, just attach directly to the pointer
|
331
|
+
s = type.new(address)
|
332
|
+
self.module_eval <<-code, __FILE__, __LINE__
|
333
|
+
@@ffi_gvar_#{mname} = s
|
334
|
+
def self.#{mname}
|
335
|
+
@@ffi_gvar_#{mname}
|
336
|
+
end
|
337
|
+
code
|
338
|
+
|
339
|
+
else
|
340
|
+
sc = Class.new(FFI::Struct)
|
341
|
+
sc.layout :gvar, find_type(type)
|
342
|
+
s = sc.new(address)
|
343
|
+
#
|
344
|
+
# Attach to this module as mname/mname=
|
345
|
+
#
|
346
|
+
self.module_eval <<-code, __FILE__, __LINE__
|
347
|
+
@@ffi_gvar_#{mname} = s
|
348
|
+
def self.#{mname}
|
349
|
+
@@ffi_gvar_#{mname}[:gvar]
|
350
|
+
end
|
351
|
+
def self.#{mname}=(value)
|
352
|
+
@@ffi_gvar_#{mname}[:gvar] = value
|
353
|
+
end
|
354
|
+
code
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
address
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
# @overload callback(name, params, ret)
|
363
|
+
# @overload callback(params, ret)
|
364
|
+
# @param name callback name to add to type map
|
365
|
+
# @param [Array] params array of parameters' types
|
366
|
+
# @param [DataConverter, Struct, Symbol, Type] ret callback return type
|
367
|
+
# @return [FFI::CallbackInfo]
|
368
|
+
def callback(*args)
|
369
|
+
raise ArgumentError, "wrong number of arguments" if args.length < 2 || args.length > 3
|
370
|
+
name, params, ret = if args.length == 3
|
371
|
+
args
|
372
|
+
else
|
373
|
+
[ nil, args[0], args[1] ]
|
374
|
+
end
|
375
|
+
|
376
|
+
native_params = params.map { |e| find_type(e) }
|
377
|
+
raise ArgumentError, "callbacks cannot have variadic parameters" if native_params.include?(FFI::Type::VARARGS)
|
378
|
+
options = Hash.new
|
379
|
+
options[:convention] = ffi_convention
|
380
|
+
options[:enums] = @ffi_enums if defined?(@ffi_enums)
|
381
|
+
cb = FFI::CallbackInfo.new(find_type(ret), native_params, options)
|
382
|
+
|
383
|
+
# Add to the symbol -> type map (unless there was no name)
|
384
|
+
unless name.nil?
|
385
|
+
typedef cb, name
|
386
|
+
end
|
387
|
+
|
388
|
+
cb
|
389
|
+
end
|
390
|
+
|
391
|
+
# @param [DataConverter, Symbol, Type] old
|
392
|
+
# @param add
|
393
|
+
# @param [] info
|
394
|
+
# @return [FFI::Enum, FFI::Type]
|
395
|
+
# Register or get an already registered type definition.
|
396
|
+
#
|
397
|
+
# To register a new type definition, +old+ should be a {FFI::Type}. +add+
|
398
|
+
# is in this case the type definition.
|
399
|
+
#
|
400
|
+
# If +old+ is a {DataConverter}, a {Type::Mapped} is returned.
|
401
|
+
#
|
402
|
+
# If +old+ is +:enum+
|
403
|
+
# * and +add+ is an +Array+, a call to {#enum} is made with +add+ as single parameter;
|
404
|
+
# * in others cases, +info+ is used to create a named enum.
|
405
|
+
#
|
406
|
+
# If +old+ is a key for type map, #typedef get +old+ type definition.
|
407
|
+
def typedef(old, add, info=nil)
|
408
|
+
@ffi_typedefs = Hash.new unless defined?(@ffi_typedefs)
|
409
|
+
|
410
|
+
@ffi_typedefs[add] = if old.kind_of?(FFI::Type)
|
411
|
+
old
|
412
|
+
|
413
|
+
elsif @ffi_typedefs.has_key?(old)
|
414
|
+
@ffi_typedefs[old]
|
415
|
+
|
416
|
+
elsif old.is_a?(DataConverter)
|
417
|
+
FFI::Type::Mapped.new(old)
|
418
|
+
|
419
|
+
elsif old == :enum
|
420
|
+
if add.kind_of?(Array)
|
421
|
+
self.enum(add)
|
422
|
+
else
|
423
|
+
self.enum(info, add)
|
424
|
+
end
|
425
|
+
|
426
|
+
else
|
427
|
+
FFI.find_type(old)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
# @overload enum(name, values)
|
432
|
+
# Create a named enum.
|
433
|
+
# @example
|
434
|
+
# enum :foo, [:zero, :one, :two] # named enum
|
435
|
+
# @param [Symbol] name name for new enum
|
436
|
+
# @param [Array] values values for enum
|
437
|
+
# @overload enum(*args)
|
438
|
+
# Create an unnamed enum.
|
439
|
+
# @example
|
440
|
+
# enum :zero, :one, :two # unnamed enum
|
441
|
+
# @param args values for enum
|
442
|
+
# @overload enum(values)
|
443
|
+
# Create an unnamed enum.
|
444
|
+
# @example
|
445
|
+
# enum [:zero, :one, :two] # unnamed enum, equivalent to above example
|
446
|
+
# @param [Array] values values for enum
|
447
|
+
# @return [FFI::Enum]
|
448
|
+
# Create a new {FFI::Enum}.
|
449
|
+
def enum(*args)
|
450
|
+
name, values = if args[0].kind_of?(Symbol) && args[1].kind_of?(Array)
|
451
|
+
[ args[0], args[1] ]
|
452
|
+
elsif args[0].kind_of?(Array)
|
453
|
+
[ nil, args[0] ]
|
454
|
+
else
|
455
|
+
[ nil, args ]
|
456
|
+
end
|
457
|
+
@ffi_enums = FFI::Enums.new unless defined?(@ffi_enums)
|
458
|
+
@ffi_enums << (e = FFI::Enum.new(values, name))
|
459
|
+
|
460
|
+
# If called as enum :foo, [ :zero, :one, :two ], add a typedef alias
|
461
|
+
typedef(e, name) if name
|
462
|
+
e
|
463
|
+
end
|
464
|
+
|
465
|
+
# @param name
|
466
|
+
# @return [FFI::Enum]
|
467
|
+
# Find an enum by name.
|
468
|
+
def enum_type(name)
|
469
|
+
@ffi_enums.find(name) if defined?(@ffi_enums)
|
470
|
+
end
|
471
|
+
|
472
|
+
# @param symbol
|
473
|
+
# @return [FFI::Enum]
|
474
|
+
# Find an enum by a symbol it contains.
|
475
|
+
def enum_value(symbol)
|
476
|
+
@ffi_enums.__map_symbol(symbol)
|
477
|
+
end
|
478
|
+
|
479
|
+
# @param [DataConverter, Type, Struct, Symbol] t type to find
|
480
|
+
# @return [Type]
|
481
|
+
# Find a type definition.
|
482
|
+
def find_type(t)
|
483
|
+
if t.kind_of?(Type)
|
484
|
+
t
|
485
|
+
|
486
|
+
elsif defined?(@ffi_typedefs) && @ffi_typedefs.has_key?(t)
|
487
|
+
@ffi_typedefs[t]
|
488
|
+
|
489
|
+
elsif t.is_a?(Class) && t < Struct
|
490
|
+
Type::POINTER
|
491
|
+
|
492
|
+
elsif t.is_a?(DataConverter)
|
493
|
+
# Add a typedef so next time the converter is used, it hits the cache
|
494
|
+
typedef Type::Mapped.new(t), t
|
495
|
+
|
496
|
+
end || FFI.find_type(t)
|
497
|
+
end
|
498
|
+
end
|
499
|
+
end
|