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/libtest/UnionTest.c
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* For licensing, see LICENSE.SPECS
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <stdbool.h>
|
9
|
+
#include <stdint.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <stdlib.h>
|
12
|
+
|
13
|
+
typedef char s8;
|
14
|
+
typedef short s16;
|
15
|
+
typedef int s32;
|
16
|
+
typedef long long s64;
|
17
|
+
typedef float f32;
|
18
|
+
typedef double f64;
|
19
|
+
|
20
|
+
typedef union union_test {
|
21
|
+
char b;
|
22
|
+
short s;
|
23
|
+
int i;
|
24
|
+
long long j;
|
25
|
+
long l;
|
26
|
+
float f;
|
27
|
+
double d;
|
28
|
+
s8 a[10];
|
29
|
+
} union_test_t;
|
30
|
+
|
31
|
+
#define T(x, type) \
|
32
|
+
type union_align_##type(union_test_t* u) { return u->x; } \
|
33
|
+
union_test_t* union_make_union_with_##type(type value) { static union_test_t u; u.x = value; return &u; }
|
34
|
+
|
35
|
+
T(b, s8);
|
36
|
+
T(s, s16);
|
37
|
+
T(i, s32);
|
38
|
+
T(j, s64);
|
39
|
+
T(f, f32);
|
40
|
+
T(d, f64);
|
41
|
+
T(l, long);
|
42
|
+
|
43
|
+
unsigned int union_size() { return sizeof(union_test_t); }
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* For licensing, see LICENSE.SPECS
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <sys/types.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdint.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <stdarg.h>
|
12
|
+
|
13
|
+
typedef int8_t s8;
|
14
|
+
typedef uint8_t u8;
|
15
|
+
typedef int16_t s16;
|
16
|
+
typedef uint16_t u16;
|
17
|
+
typedef int32_t s32;
|
18
|
+
typedef uint32_t u32;
|
19
|
+
typedef int64_t s64;
|
20
|
+
typedef uint64_t u64;
|
21
|
+
typedef signed long sL;
|
22
|
+
typedef unsigned long uL;
|
23
|
+
typedef float F;
|
24
|
+
typedef double D;
|
25
|
+
|
26
|
+
void pack_varargs(s64* buf, const char* fmt, ...)
|
27
|
+
{
|
28
|
+
va_list ap;
|
29
|
+
int c;
|
30
|
+
double d;
|
31
|
+
va_start(ap, fmt);
|
32
|
+
while ((c = *fmt++)) {
|
33
|
+
switch (c) {
|
34
|
+
case 'c':
|
35
|
+
case 's':
|
36
|
+
case 'i':
|
37
|
+
*buf++ = va_arg(ap, s32);
|
38
|
+
break;
|
39
|
+
case 'l':
|
40
|
+
*buf++ = va_arg(ap, long);
|
41
|
+
break;
|
42
|
+
case 'j':
|
43
|
+
*buf++ = va_arg(ap, s64);
|
44
|
+
break;
|
45
|
+
case 'f':
|
46
|
+
case 'd':
|
47
|
+
d = va_arg(ap, double);
|
48
|
+
memcpy(buf++, &d, sizeof(d));
|
49
|
+
break;
|
50
|
+
case 'C':
|
51
|
+
case 'S':
|
52
|
+
case 'I':
|
53
|
+
*buf++ = va_arg(ap, u32);
|
54
|
+
break;
|
55
|
+
case 'L':
|
56
|
+
*buf++ = va_arg(ap, unsigned long);
|
57
|
+
break;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
va_end(ap);
|
61
|
+
}
|
62
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of ruby-ffi.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
4
|
+
#
|
5
|
+
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
7
|
+
|
8
|
+
describe "async callback" do
|
9
|
+
module LibTest
|
10
|
+
extend FFI::Library
|
11
|
+
ffi_lib TestLibrary::PATH
|
12
|
+
AsyncIntCallback = callback [ :int ], :void
|
13
|
+
|
14
|
+
@blocking = true
|
15
|
+
attach_function :testAsyncCallback, [ AsyncIntCallback, :int ], :void
|
16
|
+
end
|
17
|
+
|
18
|
+
it ":int (0x7fffffff) argument" do
|
19
|
+
v = 0xdeadbeef
|
20
|
+
called = false
|
21
|
+
cb = Proc.new {|i| v = i; called = true }
|
22
|
+
LibTest.testAsyncCallback(cb, 0x7fffffff)
|
23
|
+
called.should be_true
|
24
|
+
v.should == 0x7fffffff
|
25
|
+
end
|
26
|
+
|
27
|
+
it "called a second time" do
|
28
|
+
v = 0xdeadbeef
|
29
|
+
called = false
|
30
|
+
cb = Proc.new {|i| v = i; called = true }
|
31
|
+
LibTest.testAsyncCallback(cb, 0x7fffffff)
|
32
|
+
called.should be_true
|
33
|
+
v.should == 0x7fffffff
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of ruby-ffi.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
4
|
+
#
|
5
|
+
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
7
|
+
describe "Function with primitive boolean arguments and return values" do
|
8
|
+
module LibTest
|
9
|
+
extend FFI::Library
|
10
|
+
ffi_lib TestLibrary::PATH
|
11
|
+
attach_function :bool_return_true, [ ], :bool
|
12
|
+
attach_function :bool_return_false, [ ], :bool
|
13
|
+
attach_function :bool_return_val, [ :bool ], :bool
|
14
|
+
attach_function :bool_reverse_val, [ :bool ], :bool
|
15
|
+
end
|
16
|
+
it "bools" do
|
17
|
+
LibTest.bool_return_true.should == true
|
18
|
+
LibTest.bool_return_false.should == false
|
19
|
+
|
20
|
+
LibTest.bool_return_val(true).should == true
|
21
|
+
LibTest.bool_return_val(false).should == false
|
22
|
+
|
23
|
+
LibTest.bool_reverse_val(true).should == false
|
24
|
+
LibTest.bool_reverse_val(false).should == true
|
25
|
+
end
|
26
|
+
it "raise error on invalid types" do
|
27
|
+
lambda { LibTest.bool_return_val(nil) }.should raise_error(::TypeError)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of ruby-ffi.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
4
|
+
#
|
5
|
+
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
7
|
+
|
8
|
+
describe "Buffer#total" do
|
9
|
+
[1,2,3].each do |i|
|
10
|
+
{ :char => 1, :uchar => 1, :short => 2, :ushort => 2, :int => 4,
|
11
|
+
:uint => 4, :long => FFI::Type::LONG.size, :ulong => FFI::Type::ULONG.size,
|
12
|
+
:long_long => 8, :ulong_long => 8, :float => 4, :double => 8
|
13
|
+
}.each_pair do |t, s|
|
14
|
+
it "Buffer.alloc_in(#{t}, #{i}).total == #{i * s}" do
|
15
|
+
FFI::Buffer.alloc_in(t, i).total.should == i * s
|
16
|
+
end
|
17
|
+
it "Buffer.alloc_out(#{t}, #{i}).total == #{i * s}" do
|
18
|
+
FFI::Buffer.alloc_out(t, i).total.should == i * s
|
19
|
+
end
|
20
|
+
it "Buffer.alloc_inout(#{t}, #{i}).total == #{i * s}" do
|
21
|
+
FFI::Buffer.alloc_inout(t, i).total.should == i * s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "Buffer#put_char" do
|
28
|
+
bufsize = 4
|
29
|
+
(0..127).each do |i|
|
30
|
+
(0..bufsize-1).each do |offset|
|
31
|
+
it "put_char(#{offset}, #{i}).get_char(#{offset}) == #{i}" do
|
32
|
+
FFI::Buffer.alloc_in(bufsize).put_char(offset, i).get_char(offset).should == i
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
describe "Buffer#put_uchar" do
|
38
|
+
bufsize = 4
|
39
|
+
(0..255).each do |i|
|
40
|
+
(0..bufsize-1).each do |offset|
|
41
|
+
it "Buffer.put_uchar(#{offset}, #{i}).get_uchar(#{offset}) == #{i}" do
|
42
|
+
FFI::Buffer.alloc_in(bufsize).put_uchar(offset, i).get_uchar(offset).should == i
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
describe "Buffer#put_short" do
|
48
|
+
bufsize = 4
|
49
|
+
[0, 1, 128, 32767].each do |i|
|
50
|
+
(0..bufsize-2).each do |offset|
|
51
|
+
it "put_short(#{offset}, #{i}).get_short(#{offset}) == #{i}" do
|
52
|
+
FFI::Buffer.alloc_in(bufsize).put_short(offset, i).get_short(offset).should == i
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
describe "Buffer#put_ushort" do
|
58
|
+
bufsize = 4
|
59
|
+
[ 0, 1, 128, 32767, 65535, 0xfee1, 0xdead, 0xbeef, 0xcafe ].each do |i|
|
60
|
+
(0..bufsize-2).each do |offset|
|
61
|
+
it "put_ushort(#{offset}, #{i}).get_ushort(#{offset}) == #{i}" do
|
62
|
+
FFI::Buffer.alloc_in(bufsize).put_ushort(offset, i).get_ushort(offset).should == i
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
describe "Buffer#put_int" do
|
68
|
+
bufsize = 8
|
69
|
+
[0, 1, 128, 32767, 0x7ffffff ].each do |i|
|
70
|
+
(0..bufsize-4).each do |offset|
|
71
|
+
it "put_int(#{offset}, #{i}).get_int(#{offset}) == #{i}" do
|
72
|
+
FFI::Buffer.alloc_in(bufsize).put_int(offset, i).get_int(offset).should == i
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
describe "Buffer#put_uint" do
|
78
|
+
bufsize = 8
|
79
|
+
[ 0, 1, 128, 32767, 65535, 0xfee1dead, 0xcafebabe, 0xffffffff ].each do |i|
|
80
|
+
(0..bufsize-4).each do |offset|
|
81
|
+
it "put_uint(#{offset}, #{i}).get_uint(#{offset}) == #{i}" do
|
82
|
+
FFI::Buffer.alloc_in(bufsize).put_uint(offset, i).get_uint(offset).should == i
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
describe "Buffer#put_long" do
|
88
|
+
bufsize = 16
|
89
|
+
[0, 1, 128, 32767, 0x7ffffff ].each do |i|
|
90
|
+
(0..bufsize-FFI::Type::LONG.size).each do |offset|
|
91
|
+
it "put_long(#{offset}, #{i}).get_long(#{offset}) == #{i}" do
|
92
|
+
FFI::Buffer.alloc_in(bufsize).put_long(offset, i).get_long(offset).should == i
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
describe "Buffer#put_ulong" do
|
98
|
+
bufsize = 16
|
99
|
+
[ 0, 1, 128, 32767, 65535, 0xfee1dead, 0xcafebabe, 0xffffffff ].each do |i|
|
100
|
+
(0..bufsize-FFI::Type::LONG.size).each do |offset|
|
101
|
+
it "put_ulong(#{offset}, #{i}).get_ulong(#{offset}) == #{i}" do
|
102
|
+
FFI::Buffer.alloc_in(bufsize).put_ulong(offset, i).get_ulong(offset).should == i
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
describe "Buffer#put_long_long" do
|
108
|
+
bufsize = 16
|
109
|
+
[0, 1, 128, 32767, 0x7ffffffffffffff ].each do |i|
|
110
|
+
(0..bufsize-8).each do |offset|
|
111
|
+
it "put_long_long(#{offset}, #{i}).get_long_long(#{offset}) == #{i}" do
|
112
|
+
FFI::Buffer.alloc_in(bufsize).put_long_long(offset, i).get_long_long(offset).should == i
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
describe "Buffer#put_ulong_long" do
|
118
|
+
bufsize = 16
|
119
|
+
[ 0, 1, 128, 32767, 65535, 0xdeadcafebabe, 0x7fffffffffffffff ].each do |i|
|
120
|
+
(0..bufsize-8).each do |offset|
|
121
|
+
it "put_ulong_long(#{offset}, #{i}).get_ulong_long(#{offset}) == #{i}" do
|
122
|
+
FFI::Buffer.alloc_in(bufsize).put_ulong_long(offset, i).get_ulong_long(offset).should == i
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
describe "Reading/Writing binary strings" do
|
128
|
+
it "Buffer#put_bytes" do
|
129
|
+
str = "hello\0world"
|
130
|
+
buf = FFI::Buffer.new 1024
|
131
|
+
buf.put_bytes(0, str);
|
132
|
+
s2 = buf.get_bytes(0, 11);
|
133
|
+
s2.should == str
|
134
|
+
end
|
135
|
+
it "Buffer#put_bytes with index and length" do
|
136
|
+
str = "hello\0world"
|
137
|
+
buf = FFI::Buffer.new 1024
|
138
|
+
buf.put_bytes(0, str, 5, 6);
|
139
|
+
s2 = buf.get_bytes(0, 6);
|
140
|
+
s2.should == str[5..-1]
|
141
|
+
end
|
142
|
+
it "Buffer#put_bytes with only index" do
|
143
|
+
str = "hello\0world"
|
144
|
+
buf = FFI::Buffer.new 1024
|
145
|
+
buf.put_bytes(0, str, 5);
|
146
|
+
s2 = buf.get_bytes(0, 6);
|
147
|
+
s2.should == str[5..-1]
|
148
|
+
end
|
149
|
+
it "Buffer#put_bytes with index > str.length" do
|
150
|
+
str = "hello\0world"
|
151
|
+
buf = FFI::Buffer.new 1024
|
152
|
+
lambda { buf.put_bytes(0, str, 12); }.should raise_error
|
153
|
+
end
|
154
|
+
it "Buffer#put_bytes with length > str.length" do
|
155
|
+
str = "hello\0world"
|
156
|
+
buf = FFI::Buffer.new 1024
|
157
|
+
lambda { buf.put_bytes(0, str, 0, 12); }.should raise_error
|
158
|
+
end
|
159
|
+
it "Buffer#put_bytes with negative index" do
|
160
|
+
str = "hello\0world"
|
161
|
+
buf = FFI::Buffer.new 1024
|
162
|
+
lambda { buf.put_bytes(0, str, -1, 12); }.should raise_error
|
163
|
+
end
|
164
|
+
|
165
|
+
it "Buffer#write_bytes" do
|
166
|
+
str = "hello\0world"
|
167
|
+
buf = FFI::Buffer.new 1024
|
168
|
+
buf.write_bytes(str)
|
169
|
+
s2 = buf.get_bytes(0, 11)
|
170
|
+
s2.should == str
|
171
|
+
end
|
172
|
+
it "Buffer#write_bytes with index and length" do
|
173
|
+
str = "hello\0world"
|
174
|
+
buf = FFI::Buffer.new 1024
|
175
|
+
buf.write_bytes(str, 5, 6)
|
176
|
+
s2 = buf.get_bytes(0, 6)
|
177
|
+
s2.should == str[5..-1]
|
178
|
+
end
|
179
|
+
it "Buffer#write_bytes with only index" do
|
180
|
+
str = "hello\0world"
|
181
|
+
buf = FFI::Buffer.new 1024
|
182
|
+
buf.write_bytes(str, 5)
|
183
|
+
s2 = buf.get_bytes(0, 6)
|
184
|
+
s2.should == str[5..-1]
|
185
|
+
end
|
186
|
+
it "Buffer#write_bytes with index > str.length" do
|
187
|
+
str = "hello\0world"
|
188
|
+
buf = FFI::Buffer.new 1024
|
189
|
+
lambda { buf.write_bytes(str, 12) }.should raise_error
|
190
|
+
end
|
191
|
+
it "Buffer#put_bytes with length > str.length" do
|
192
|
+
str = "hello\0world"
|
193
|
+
buf = FFI::Buffer.new 1024
|
194
|
+
lambda { buf.put_bytes(0, str, 0, 12) }.should raise_error
|
195
|
+
end
|
196
|
+
it "Buffer#write_bytes with negative index" do
|
197
|
+
str = "hello\0world"
|
198
|
+
buf = FFI::Buffer.new 1024
|
199
|
+
lambda { buf.write_bytes(str, -1, 12) }.should raise_error
|
200
|
+
end
|
201
|
+
end
|
202
|
+
describe "Reading/Writing ascii strings" do
|
203
|
+
it "Buffer#put_string with string containing zero byte" do
|
204
|
+
str = "hello\0world"
|
205
|
+
buf = FFI::Buffer.new 1024
|
206
|
+
buf.put_string(0, str);
|
207
|
+
s2 = buf.get_bytes(0, 11);
|
208
|
+
s2.should == str
|
209
|
+
end
|
210
|
+
it "Buffer#get_string with string containing zero byte" do
|
211
|
+
str = "hello\0world"
|
212
|
+
buf = FFI::Buffer.new 1024
|
213
|
+
buf.put_bytes(0, str);
|
214
|
+
s2 = buf.get_string(0, 11);
|
215
|
+
s2.should == "hello"
|
216
|
+
end
|
217
|
+
it "Buffer#put_string without length should NUL terminate" do
|
218
|
+
str = "hello"
|
219
|
+
buf = FFI::Buffer.new 1024
|
220
|
+
buf.put_string(0, str);
|
221
|
+
s2 = buf.get_bytes(0, 6);
|
222
|
+
s2.should == "hello\0"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
describe "Buffer#put_pointer" do
|
226
|
+
it "put_pointer(0, p).get_pointer(0) == p" do
|
227
|
+
p = FFI::MemoryPointer.new :ulong_long
|
228
|
+
p.put_uint(0, 0xdeadbeef)
|
229
|
+
buf = FFI::Buffer.alloc_inout 8
|
230
|
+
p2 = buf.put_pointer(0, p).get_pointer(0)
|
231
|
+
p2.should_not be_nil
|
232
|
+
p2.should == p
|
233
|
+
p2.get_uint(0).should == 0xdeadbeef
|
234
|
+
end
|
235
|
+
end
|
236
|
+
describe "Buffer#size" do
|
237
|
+
it "should return size" do
|
238
|
+
buf = FFI::Buffer.new 14
|
239
|
+
buf.size.should == 14
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "Buffer#initialize" do
|
244
|
+
it "with block should execute block" do
|
245
|
+
block_executed = false
|
246
|
+
FFI::Buffer.new(:pointer) do |ptr|
|
247
|
+
block_executed = true
|
248
|
+
end
|
249
|
+
block_executed.should be_true
|
250
|
+
end
|
251
|
+
end
|
@@ -0,0 +1,667 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of ruby-ffi.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
4
|
+
#
|
5
|
+
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
7
|
+
|
8
|
+
describe "Callback" do
|
9
|
+
# module LibC
|
10
|
+
# extend FFI::Library
|
11
|
+
# callback :qsort_cmp, [ :pointer, :pointer ], :int
|
12
|
+
# attach_function :qsort, [ :pointer, :int, :int, :qsort_cmp ], :int
|
13
|
+
# end
|
14
|
+
# it "arguments get passed correctly" do
|
15
|
+
# p = MemoryPointer.new(:int, 2)
|
16
|
+
# p.put_array_of_int32(0, [ 1 , 2 ])
|
17
|
+
# args = []
|
18
|
+
# cmp = proc do |p1, p2| args.push(p1.get_int(0)); args.push(p2.get_int(0)); 0; end
|
19
|
+
# # this is a bit dodgey, as it relies on qsort passing the args in order
|
20
|
+
# LibC.qsort(p, 2, 4, cmp)
|
21
|
+
# args.should == [ 1, 2 ]
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# it "Block can be substituted for Callback as last argument" do
|
25
|
+
# p = MemoryPointer.new(:int, 2)
|
26
|
+
# p.put_array_of_int32(0, [ 1 , 2 ])
|
27
|
+
# args = []
|
28
|
+
# # this is a bit dodgey, as it relies on qsort passing the args in order
|
29
|
+
# LibC.qsort(p, 2, 4) do |p1, p2|
|
30
|
+
# args.push(p1.get_int(0))
|
31
|
+
# args.push(p2.get_int(0))
|
32
|
+
# 0
|
33
|
+
# end
|
34
|
+
# args.should == [ 1, 2 ]
|
35
|
+
# end
|
36
|
+
module LibTest
|
37
|
+
extend FFI::Library
|
38
|
+
ffi_lib TestLibrary::PATH
|
39
|
+
class S8F32S32 < FFI::Struct
|
40
|
+
layout :s8, :char, :f32, :float, :s32, :int
|
41
|
+
end
|
42
|
+
|
43
|
+
callback :cbVrS8, [ ], :char
|
44
|
+
callback :cbVrU8, [ ], :uchar
|
45
|
+
callback :cbVrS16, [ ], :short
|
46
|
+
callback :cbVrU16, [ ], :ushort
|
47
|
+
callback :cbVrS32, [ ], :int
|
48
|
+
callback :cbVrU32, [ ], :uint
|
49
|
+
callback :cbVrL, [ ], :long
|
50
|
+
callback :cbVrUL, [ ], :ulong
|
51
|
+
callback :cbVrS64, [ ], :long_long
|
52
|
+
callback :cbVrU64, [ ], :ulong_long
|
53
|
+
callback :cbVrP, [], :pointer
|
54
|
+
callback :cbVrZ, [], :bool
|
55
|
+
callback :cbCrV, [ :char ], :void
|
56
|
+
callback :cbSrV, [ :short ], :void
|
57
|
+
callback :cbIrV, [ :int ], :void
|
58
|
+
callback :cbLrV, [ :long ], :void
|
59
|
+
callback :cbULrV, [ :ulong ], :void
|
60
|
+
callback :cbLrV, [ :long_long ], :void
|
61
|
+
callback :cbVrT, [ ], S8F32S32.by_value
|
62
|
+
callback :cbTrV, [ S8F32S32.by_value ], :void
|
63
|
+
callback :cbYrV, [ S8F32S32.ptr ], :void
|
64
|
+
callback :cbVrY, [ ], S8F32S32.ptr
|
65
|
+
|
66
|
+
attach_function :testCallbackVrS8, :testClosureVrB, [ :cbVrS8 ], :char
|
67
|
+
attach_function :testCallbackVrU8, :testClosureVrB, [ :cbVrU8 ], :uchar
|
68
|
+
attach_function :testCallbackVrS16, :testClosureVrS, [ :cbVrS16 ], :short
|
69
|
+
attach_function :testCallbackVrU16, :testClosureVrS, [ :cbVrU16 ], :ushort
|
70
|
+
attach_function :testCallbackVrS32, :testClosureVrI, [ :cbVrS32 ], :int
|
71
|
+
attach_function :testCallbackVrU32, :testClosureVrI, [ :cbVrU32 ], :uint
|
72
|
+
attach_function :testCallbackVrL, :testClosureVrL, [ :cbVrL ], :long
|
73
|
+
attach_function :testCallbackVrZ, :testClosureVrZ, [ :cbVrZ ], :bool
|
74
|
+
attach_function :testCallbackVrUL, :testClosureVrL, [ :cbVrUL ], :ulong
|
75
|
+
attach_function :testCallbackVrS64, :testClosureVrLL, [ :cbVrS64 ], :long_long
|
76
|
+
attach_function :testCallbackVrU64, :testClosureVrLL, [ :cbVrU64 ], :ulong_long
|
77
|
+
attach_function :testCallbackVrP, :testClosureVrP, [ :cbVrP ], :pointer
|
78
|
+
attach_function :testCallbackVrY, :testClosureVrP, [ :cbVrY ], S8F32S32.ptr
|
79
|
+
attach_function :testCallbackVrT, :testClosureVrT, [ :cbVrT ], S8F32S32.by_value
|
80
|
+
attach_function :testCallbackTrV, :testClosureTrV, [ :cbTrV, S8F32S32.ptr ], :void
|
81
|
+
attach_variable :cbVrS8, :gvar_pointer, :cbVrS8
|
82
|
+
attach_variable :pVrS8, :gvar_pointer, :pointer
|
83
|
+
attach_function :testGVarCallbackVrS8, :testClosureVrB, [ :pointer ], :char
|
84
|
+
attach_function :testOptionalCallbackCrV, :testOptionalClosureBrV, [ :cbCrV, :char ], :void
|
85
|
+
|
86
|
+
end
|
87
|
+
it "returning :char (0)" do
|
88
|
+
LibTest.testCallbackVrS8 { 0 }.should == 0
|
89
|
+
end
|
90
|
+
it "returning :char (127)" do
|
91
|
+
LibTest.testCallbackVrS8 { 127 }.should == 127
|
92
|
+
end
|
93
|
+
it "returning :char (-128)" do
|
94
|
+
LibTest.testCallbackVrS8 { -128 }.should == -128
|
95
|
+
end
|
96
|
+
# test wrap around
|
97
|
+
it "returning :char (128)" do
|
98
|
+
LibTest.testCallbackVrS8 { 128 }.should == -128
|
99
|
+
end
|
100
|
+
it "returning :char (255)" do
|
101
|
+
LibTest.testCallbackVrS8 { 0xff }.should == -1
|
102
|
+
end
|
103
|
+
it "returning :uchar (0)" do
|
104
|
+
LibTest.testCallbackVrU8 { 0 }.should == 0
|
105
|
+
end
|
106
|
+
it "returning :uchar (0xff)" do
|
107
|
+
LibTest.testCallbackVrU8 { 0xff }.should == 0xff
|
108
|
+
end
|
109
|
+
it "returning :uchar (-1)" do
|
110
|
+
LibTest.testCallbackVrU8 { -1 }.should == 0xff
|
111
|
+
end
|
112
|
+
it "returning :uchar (128)" do
|
113
|
+
LibTest.testCallbackVrU8 { 128 }.should == 128
|
114
|
+
end
|
115
|
+
it "returning :uchar (-128)" do
|
116
|
+
LibTest.testCallbackVrU8 { -128 }.should == 128
|
117
|
+
end
|
118
|
+
it "returning :short (0)" do
|
119
|
+
LibTest.testCallbackVrS16 { 0 }.should == 0
|
120
|
+
end
|
121
|
+
it "returning :short (0x7fff)" do
|
122
|
+
LibTest.testCallbackVrS16 { 0x7fff }.should == 0x7fff
|
123
|
+
end
|
124
|
+
# test wrap around
|
125
|
+
it "returning :short (0x8000)" do
|
126
|
+
LibTest.testCallbackVrS16 { 0x8000 }.should == -0x8000
|
127
|
+
end
|
128
|
+
it "returning :short (0xffff)" do
|
129
|
+
LibTest.testCallbackVrS16 { 0xffff }.should == -1
|
130
|
+
end
|
131
|
+
it "returning :ushort (0)" do
|
132
|
+
LibTest.testCallbackVrU16 { 0 }.should == 0
|
133
|
+
end
|
134
|
+
it "returning :ushort (0x7fff)" do
|
135
|
+
LibTest.testCallbackVrU16 { 0x7fff }.should == 0x7fff
|
136
|
+
end
|
137
|
+
it "returning :ushort (0x8000)" do
|
138
|
+
LibTest.testCallbackVrU16 { 0x8000 }.should == 0x8000
|
139
|
+
end
|
140
|
+
it "returning :ushort (0xffff)" do
|
141
|
+
LibTest.testCallbackVrU16 { 0xffff }.should == 0xffff
|
142
|
+
end
|
143
|
+
it "returning :ushort (-1)" do
|
144
|
+
LibTest.testCallbackVrU16 { -1 }.should == 0xffff
|
145
|
+
end
|
146
|
+
it "returning :int (0)" do
|
147
|
+
LibTest.testCallbackVrS32 { 0 }.should == 0
|
148
|
+
end
|
149
|
+
it "returning :int (0x7fffffff)" do
|
150
|
+
LibTest.testCallbackVrS32 { 0x7fffffff }.should == 0x7fffffff
|
151
|
+
end
|
152
|
+
# test wrap around
|
153
|
+
it "returning :int (-0x80000000)" do
|
154
|
+
LibTest.testCallbackVrS32 { -0x80000000 }.should == -0x80000000
|
155
|
+
end
|
156
|
+
it "returning :int (-1)" do
|
157
|
+
LibTest.testCallbackVrS32 { -1 }.should == -1
|
158
|
+
end
|
159
|
+
it "returning :uint (0)" do
|
160
|
+
LibTest.testCallbackVrU32 { 0 }.should == 0
|
161
|
+
end
|
162
|
+
it "returning :uint (0x7fffffff)" do
|
163
|
+
LibTest.testCallbackVrU32 { 0x7fffffff }.should == 0x7fffffff
|
164
|
+
end
|
165
|
+
# test wrap around
|
166
|
+
it "returning :uint (0x80000000)" do
|
167
|
+
LibTest.testCallbackVrU32 { 0x80000000 }.should == 0x80000000
|
168
|
+
end
|
169
|
+
it "returning :uint (0xffffffff)" do
|
170
|
+
LibTest.testCallbackVrU32 { 0xffffffff }.should == 0xffffffff
|
171
|
+
end
|
172
|
+
it "returning :uint (-1)" do
|
173
|
+
LibTest.testCallbackVrU32 { -1 }.should == 0xffffffff
|
174
|
+
end
|
175
|
+
it "returning :long (0)" do
|
176
|
+
LibTest.testCallbackVrL { 0 }.should == 0
|
177
|
+
end
|
178
|
+
it "returning :long (0x7fffffff)" do
|
179
|
+
LibTest.testCallbackVrL { 0x7fffffff }.should == 0x7fffffff
|
180
|
+
end
|
181
|
+
# test wrap around
|
182
|
+
it "returning :long (-0x80000000)" do
|
183
|
+
LibTest.testCallbackVrL { -0x80000000 }.should == -0x80000000
|
184
|
+
end
|
185
|
+
it "returning :long (-1)" do
|
186
|
+
LibTest.testCallbackVrL { -1 }.should == -1
|
187
|
+
end
|
188
|
+
it "returning :ulong (0)" do
|
189
|
+
LibTest.testCallbackVrUL { 0 }.should == 0
|
190
|
+
end
|
191
|
+
it "returning :ulong (0x7fffffff)" do
|
192
|
+
LibTest.testCallbackVrUL { 0x7fffffff }.should == 0x7fffffff
|
193
|
+
end
|
194
|
+
# test wrap around
|
195
|
+
it "returning :ulong (0x80000000)" do
|
196
|
+
LibTest.testCallbackVrUL { 0x80000000 }.should == 0x80000000
|
197
|
+
end
|
198
|
+
it "returning :ulong (0xffffffff)" do
|
199
|
+
LibTest.testCallbackVrUL { 0xffffffff }.should == 0xffffffff
|
200
|
+
end
|
201
|
+
it "Callback returning :ulong (-1)" do
|
202
|
+
if FFI::Platform::LONG_SIZE == 32
|
203
|
+
LibTest.testCallbackVrUL { -1 }.should == 0xffffffff
|
204
|
+
else
|
205
|
+
LibTest.testCallbackVrUL { -1 }.should == 0xffffffffffffffff
|
206
|
+
end
|
207
|
+
end
|
208
|
+
it "returning :long_long (0)" do
|
209
|
+
LibTest.testCallbackVrS64 { 0 }.should == 0
|
210
|
+
end
|
211
|
+
it "returning :long_long (0x7fffffffffffffff)" do
|
212
|
+
LibTest.testCallbackVrS64 { 0x7fffffffffffffff }.should == 0x7fffffffffffffff
|
213
|
+
end
|
214
|
+
# test wrap around
|
215
|
+
it "returning :long_long (-0x8000000000000000)" do
|
216
|
+
LibTest.testCallbackVrS64 { -0x8000000000000000 }.should == -0x8000000000000000
|
217
|
+
end
|
218
|
+
it "returning :long_long (-1)" do
|
219
|
+
LibTest.testCallbackVrS64 { -1 }.should == -1
|
220
|
+
end
|
221
|
+
it "returning bool" do
|
222
|
+
LibTest.testCallbackVrZ { true }.should be_true
|
223
|
+
end
|
224
|
+
it "returning :pointer (nil)" do
|
225
|
+
LibTest.testCallbackVrP { nil }.null?.should be_true
|
226
|
+
end
|
227
|
+
it "returning :pointer (MemoryPointer)" do
|
228
|
+
p = FFI::MemoryPointer.new :long
|
229
|
+
LibTest.testCallbackVrP { p }.should == p
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
it "returning struct by value" do
|
234
|
+
s = LibTest::S8F32S32.new
|
235
|
+
s[:s8] = 0x12
|
236
|
+
s[:s32] = 0x1eefbeef
|
237
|
+
s[:f32] = 1.234567
|
238
|
+
ret = LibTest.testCallbackVrT { s }
|
239
|
+
ret[:s8].should == s[:s8]
|
240
|
+
ret[:f32].should == s[:f32]
|
241
|
+
ret[:s32].should == s[:s32]
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
it "struct by value parameter" do
|
246
|
+
s = LibTest::S8F32S32.new
|
247
|
+
s[:s8] = 0x12
|
248
|
+
s[:s32] = 0x1eefbeef
|
249
|
+
s[:f32] = 1.234567
|
250
|
+
s2 = LibTest::S8F32S32.new
|
251
|
+
LibTest.testCallbackTrV(s) do |struct|
|
252
|
+
s2[:s8] = struct[:s8]
|
253
|
+
s2[:f32] = struct[:f32]
|
254
|
+
s2[:s32] = struct[:s32]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
|
259
|
+
it "global variable" do
|
260
|
+
proc = Proc.new { 0x1e }
|
261
|
+
LibTest.cbVrS8 = proc
|
262
|
+
LibTest.testGVarCallbackVrS8(LibTest.pVrS8).should == 0x1e
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "When the callback is considered optional by the underlying library" do
|
266
|
+
it "should handle receiving 'nil' in place of the closure" do
|
267
|
+
LibTest.testOptionalCallbackCrV(nil, 13)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe 'when inlined' do
|
272
|
+
it 'could be anonymous' do
|
273
|
+
module LibTest
|
274
|
+
extend FFI::Library
|
275
|
+
ffi_lib TestLibrary::PATH
|
276
|
+
attach_function :testAnonymousCallbackVrS8, :testClosureVrB, [ callback([ ], :char) ], :char
|
277
|
+
end
|
278
|
+
LibTest.testAnonymousCallbackVrS8 { 0 }.should == 0
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe "as return value" do
|
283
|
+
|
284
|
+
it "should not blow up when a callback is defined that returns a callback" do
|
285
|
+
module LibTest
|
286
|
+
extend FFI::Library
|
287
|
+
ffi_lib TestLibrary::PATH
|
288
|
+
callback :cb_return_type_1, [ :short ], :short
|
289
|
+
callback :cb_lookup_1, [ :short ], :cb_return_type_1
|
290
|
+
attach_function :testReturnsCallback_1, :testReturnsClosure, [ :cb_lookup_1, :short ], :cb_return_type_1
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
it "should return a callback" do
|
295
|
+
module LibTest
|
296
|
+
extend FFI::Library
|
297
|
+
ffi_lib TestLibrary::PATH
|
298
|
+
callback :cb_return_type, [ :int ], :int
|
299
|
+
callback :cb_lookup, [ ], :cb_return_type
|
300
|
+
attach_function :testReturnsCallback, :testReturnsClosure, [ :cb_lookup, :int ], :int
|
301
|
+
end
|
302
|
+
|
303
|
+
lookup_proc_called = false
|
304
|
+
return_proc_called = false
|
305
|
+
|
306
|
+
return_proc = Proc.new do |a|
|
307
|
+
return_proc_called = true
|
308
|
+
a * 2
|
309
|
+
end
|
310
|
+
lookup_proc = Proc.new do
|
311
|
+
lookup_proc_called = true
|
312
|
+
return_proc
|
313
|
+
end
|
314
|
+
|
315
|
+
val = LibTest.testReturnsCallback(lookup_proc, 0x1234)
|
316
|
+
val.should == 0x1234 * 2
|
317
|
+
lookup_proc_called.should be_true
|
318
|
+
return_proc_called.should be_true
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should return a method callback" do
|
322
|
+
module LibTest
|
323
|
+
extend FFI::Library
|
324
|
+
ffi_lib TestLibrary::PATH
|
325
|
+
callback :cb_return_type, [ :int ], :int
|
326
|
+
callback :cb_lookup, [ ], :cb_return_type
|
327
|
+
attach_function :testReturnsCallback_2, :testReturnsClosure, [ :cb_lookup, :int ], :int
|
328
|
+
end
|
329
|
+
module MethodCallback
|
330
|
+
def self.lookup
|
331
|
+
method(:perform)
|
332
|
+
end
|
333
|
+
def self.perform num
|
334
|
+
num * 2
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
LibTest.testReturnsCallback_2(MethodCallback.method(:lookup), 0x1234).should == 0x2468
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'should not blow up when a callback takes a callback as argument' do
|
342
|
+
module LibTest
|
343
|
+
extend FFI::Library
|
344
|
+
ffi_lib TestLibrary::PATH
|
345
|
+
callback :cb_argument, [ :int ], :int
|
346
|
+
callback :cb_with_cb_argument, [ :cb_argument, :int ], :int
|
347
|
+
attach_function :testCallbackAsArgument_2, :testArgumentClosure, [ :cb_with_cb_argument, :int ], :int
|
348
|
+
end
|
349
|
+
end
|
350
|
+
it 'should be able to use the callback argument' do
|
351
|
+
module LibTest
|
352
|
+
extend FFI::Library
|
353
|
+
ffi_lib TestLibrary::PATH
|
354
|
+
callback :cb_argument, [ :int ], :int
|
355
|
+
callback :cb_with_cb_argument, [ :cb_argument, :int ], :int
|
356
|
+
attach_function :testCallbackAsArgument, :testArgumentClosure, [ :cb_with_cb_argument, :cb_argument, :int ], :int
|
357
|
+
end
|
358
|
+
callback_arg_called = false
|
359
|
+
callback_with_callback_arg_called = false
|
360
|
+
callback_arg = Proc.new do |val|
|
361
|
+
callback_arg_called = true
|
362
|
+
val * 2
|
363
|
+
end
|
364
|
+
callback_with_callback_arg = Proc.new do |cb, val|
|
365
|
+
callback_with_callback_arg_called = true
|
366
|
+
cb.call(val)
|
367
|
+
end
|
368
|
+
val = LibTest.testCallbackAsArgument(callback_with_callback_arg, callback_arg, 0xff1)
|
369
|
+
val.should == 0xff1 * 2
|
370
|
+
callback_arg_called.should be_true
|
371
|
+
callback_with_callback_arg_called.should be_true
|
372
|
+
end
|
373
|
+
it 'function returns callable object' do
|
374
|
+
module LibTest
|
375
|
+
extend FFI::Library
|
376
|
+
ffi_lib TestLibrary::PATH
|
377
|
+
callback :funcptr, [ :int ], :int
|
378
|
+
attach_function :testReturnsFunctionPointer, [ ], :funcptr
|
379
|
+
end
|
380
|
+
f = LibTest.testReturnsFunctionPointer
|
381
|
+
f.call(3).should == 6
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
end
|
386
|
+
|
387
|
+
|
388
|
+
describe "Callback with " do
|
389
|
+
#
|
390
|
+
# Test callbacks that take an argument, returning void
|
391
|
+
#
|
392
|
+
module LibTest
|
393
|
+
extend FFI::Library
|
394
|
+
ffi_lib TestLibrary::PATH
|
395
|
+
|
396
|
+
class S8F32S32 < FFI::Struct
|
397
|
+
layout :s8, :char, :f32, :float, :s32, :int
|
398
|
+
end
|
399
|
+
|
400
|
+
callback :cbS8rV, [ :char ], :void
|
401
|
+
callback :cbU8rV, [ :uchar ], :void
|
402
|
+
callback :cbS16rV, [ :short ], :void
|
403
|
+
callback :cbU16rV, [ :ushort ], :void
|
404
|
+
|
405
|
+
callback :cbZrV, [ :bool ], :void
|
406
|
+
callback :cbS32rV, [ :int ], :void
|
407
|
+
callback :cbU32rV, [ :uint ], :void
|
408
|
+
|
409
|
+
callback :cbLrV, [ :long ], :void
|
410
|
+
callback :cbULrV, [ :ulong ], :void
|
411
|
+
callback :cbArV, [ :string ], :void
|
412
|
+
callback :cbPrV, [ :pointer], :void
|
413
|
+
callback :cbYrV, [ S8F32S32.ptr ], :void
|
414
|
+
|
415
|
+
callback :cbS64rV, [ :long_long ], :void
|
416
|
+
attach_function :testCallbackCrV, :testClosureBrV, [ :cbS8rV, :char ], :void
|
417
|
+
attach_function :testCallbackU8rV, :testClosureBrV, [ :cbU8rV, :uchar ], :void
|
418
|
+
attach_function :testCallbackSrV, :testClosureSrV, [ :cbS16rV, :short ], :void
|
419
|
+
attach_function :testCallbackU16rV, :testClosureSrV, [ :cbU16rV, :ushort ], :void
|
420
|
+
attach_function :testCallbackZrV, :testClosureZrV, [ :cbZrV, :bool ], :void
|
421
|
+
attach_function :testCallbackIrV, :testClosureIrV, [ :cbS32rV, :int ], :void
|
422
|
+
attach_function :testCallbackU32rV, :testClosureIrV, [ :cbU32rV, :uint ], :void
|
423
|
+
|
424
|
+
attach_function :testCallbackLrV, :testClosureLrV, [ :cbLrV, :long ], :void
|
425
|
+
attach_function :testCallbackULrV, :testClosureULrV, [ :cbULrV, :ulong ], :void
|
426
|
+
|
427
|
+
attach_function :testCallbackLLrV, :testClosureLLrV, [ :cbS64rV, :long_long ], :void
|
428
|
+
attach_function :testCallbackArV, :testClosurePrV, [ :cbArV, :string ], :void
|
429
|
+
attach_function :testCallbackPrV, :testClosurePrV, [ :cbPrV, :pointer], :void
|
430
|
+
attach_function :testCallbackYrV, :testClosurePrV, [ :cbYrV, S8F32S32.in ], :void
|
431
|
+
end
|
432
|
+
it "function with Callback plus another arg should raise error if no arg given" do
|
433
|
+
lambda { LibTest.testCallbackCrV { |*a| }}.should raise_error
|
434
|
+
end
|
435
|
+
it ":char (0) argument" do
|
436
|
+
v = 0xdeadbeef
|
437
|
+
LibTest.testCallbackCrV(0) { |i| v = i }
|
438
|
+
v.should == 0
|
439
|
+
end
|
440
|
+
it ":char (127) argument" do
|
441
|
+
v = 0xdeadbeef
|
442
|
+
LibTest.testCallbackCrV(127) { |i| v = i }
|
443
|
+
v.should == 127
|
444
|
+
end
|
445
|
+
it ":char (-128) argument" do
|
446
|
+
v = 0xdeadbeef
|
447
|
+
LibTest.testCallbackCrV(-128) { |i| v = i }
|
448
|
+
v.should == -128
|
449
|
+
end
|
450
|
+
it ":char (-1) argument" do
|
451
|
+
v = 0xdeadbeef
|
452
|
+
LibTest.testCallbackCrV(-1) { |i| v = i }
|
453
|
+
v.should == -1
|
454
|
+
end
|
455
|
+
it ":uchar (0) argument" do
|
456
|
+
v = 0xdeadbeef
|
457
|
+
LibTest.testCallbackU8rV(0) { |i| v = i }
|
458
|
+
v.should == 0
|
459
|
+
end
|
460
|
+
it ":uchar (127) argument" do
|
461
|
+
v = 0xdeadbeef
|
462
|
+
LibTest.testCallbackU8rV(127) { |i| v = i }
|
463
|
+
v.should == 127
|
464
|
+
end
|
465
|
+
it ":uchar (128) argument" do
|
466
|
+
v = 0xdeadbeef
|
467
|
+
LibTest.testCallbackU8rV(128) { |i| v = i }
|
468
|
+
v.should == 128
|
469
|
+
end
|
470
|
+
it ":uchar (255) argument" do
|
471
|
+
v = 0xdeadbeef
|
472
|
+
LibTest.testCallbackU8rV(255) { |i| v = i }
|
473
|
+
v.should == 255
|
474
|
+
end
|
475
|
+
|
476
|
+
it ":short (0) argument" do
|
477
|
+
v = 0xdeadbeef
|
478
|
+
LibTest.testCallbackSrV(0) { |i| v = i }
|
479
|
+
v.should == 0
|
480
|
+
end
|
481
|
+
it ":short (0x7fff) argument" do
|
482
|
+
v = 0xdeadbeef
|
483
|
+
LibTest.testCallbackSrV(0x7fff) { |i| v = i }
|
484
|
+
v.should == 0x7fff
|
485
|
+
end
|
486
|
+
it ":short (-0x8000) argument" do
|
487
|
+
v = 0xdeadbeef
|
488
|
+
LibTest.testCallbackSrV(-0x8000) { |i| v = i }
|
489
|
+
v.should == -0x8000
|
490
|
+
end
|
491
|
+
it ":short (-1) argument" do
|
492
|
+
v = 0xdeadbeef
|
493
|
+
LibTest.testCallbackSrV(-1) { |i| v = i }
|
494
|
+
v.should == -1
|
495
|
+
end
|
496
|
+
it ":ushort (0) argument" do
|
497
|
+
v = 0xdeadbeef
|
498
|
+
LibTest.testCallbackU16rV(0) { |i| v = i }
|
499
|
+
v.should == 0
|
500
|
+
end
|
501
|
+
it ":ushort (0x7fff) argument" do
|
502
|
+
v = 0xdeadbeef
|
503
|
+
LibTest.testCallbackU16rV(0x7fff) { |i| v = i }
|
504
|
+
v.should == 0x7fff
|
505
|
+
end
|
506
|
+
it ":ushort (0x8000) argument" do
|
507
|
+
v = 0xdeadbeef
|
508
|
+
LibTest.testCallbackU16rV(0x8000) { |i| v = i }
|
509
|
+
v.should == 0x8000
|
510
|
+
end
|
511
|
+
it ":ushort (0xffff) argument" do
|
512
|
+
v = 0xdeadbeef
|
513
|
+
LibTest.testCallbackU16rV(0xffff) { |i| v = i }
|
514
|
+
v.should == 0xffff
|
515
|
+
end
|
516
|
+
it ":bool (true) argument" do
|
517
|
+
v = false
|
518
|
+
LibTest.testCallbackZrV(true) { |i| v = i }
|
519
|
+
v.should be_true
|
520
|
+
end
|
521
|
+
it ":int (0) argument" do
|
522
|
+
v = 0xdeadbeef
|
523
|
+
LibTest.testCallbackIrV(0) { |i| v = i }
|
524
|
+
v.should == 0
|
525
|
+
end
|
526
|
+
it ":int (0x7fffffff) argument" do
|
527
|
+
v = 0xdeadbeef
|
528
|
+
LibTest.testCallbackIrV(0x7fffffff) { |i| v = i }
|
529
|
+
v.should == 0x7fffffff
|
530
|
+
end
|
531
|
+
it ":int (-0x80000000) argument" do
|
532
|
+
v = 0xdeadbeef
|
533
|
+
LibTest.testCallbackIrV(-0x80000000) { |i| v = i }
|
534
|
+
v.should == -0x80000000
|
535
|
+
end
|
536
|
+
it ":int (-1) argument" do
|
537
|
+
v = 0xdeadbeef
|
538
|
+
LibTest.testCallbackIrV(-1) { |i| v = i }
|
539
|
+
v.should == -1
|
540
|
+
end
|
541
|
+
it ":uint (0) argument" do
|
542
|
+
v = 0xdeadbeef
|
543
|
+
LibTest.testCallbackU32rV(0) { |i| v = i }
|
544
|
+
v.should == 0
|
545
|
+
end
|
546
|
+
it ":uint (0x7fffffff) argument" do
|
547
|
+
v = 0xdeadbeef
|
548
|
+
LibTest.testCallbackU32rV(0x7fffffff) { |i| v = i }
|
549
|
+
v.should == 0x7fffffff
|
550
|
+
end
|
551
|
+
it ":uint (0x80000000) argument" do
|
552
|
+
v = 0xdeadbeef
|
553
|
+
LibTest.testCallbackU32rV(0x80000000) { |i| v = i }
|
554
|
+
v.should == 0x80000000
|
555
|
+
end
|
556
|
+
it ":uint (0xffffffff) argument" do
|
557
|
+
v = 0xdeadbeef
|
558
|
+
LibTest.testCallbackU32rV(0xffffffff) { |i| v = i }
|
559
|
+
v.should == 0xffffffff
|
560
|
+
end
|
561
|
+
it ":long (0) argument" do
|
562
|
+
v = 0xdeadbeef
|
563
|
+
LibTest.testCallbackLrV(0) { |i| v = i }
|
564
|
+
v.should == 0
|
565
|
+
end
|
566
|
+
it ":long (0x7fffffff) argument" do
|
567
|
+
v = 0xdeadbeef
|
568
|
+
LibTest.testCallbackLrV(0x7fffffff) { |i| v = i }
|
569
|
+
v.should == 0x7fffffff
|
570
|
+
end
|
571
|
+
it ":long (-0x80000000) argument" do
|
572
|
+
v = 0xdeadbeef
|
573
|
+
LibTest.testCallbackLrV(-0x80000000) { |i| v = i }
|
574
|
+
v.should == -0x80000000
|
575
|
+
end
|
576
|
+
it ":long (-1) argument" do
|
577
|
+
v = 0xdeadbeef
|
578
|
+
LibTest.testCallbackLrV(-1) { |i| v = i }
|
579
|
+
v.should == -1
|
580
|
+
end
|
581
|
+
it ":ulong (0) argument" do
|
582
|
+
v = 0xdeadbeef
|
583
|
+
LibTest.testCallbackULrV(0) { |i| v = i }
|
584
|
+
v.should == 0
|
585
|
+
end
|
586
|
+
it ":ulong (0x7fffffff) argument" do
|
587
|
+
v = 0xdeadbeef
|
588
|
+
LibTest.testCallbackULrV(0x7fffffff) { |i| v = i }
|
589
|
+
v.should == 0x7fffffff
|
590
|
+
end
|
591
|
+
it ":ulong (0x80000000) argument" do
|
592
|
+
v = 0xdeadbeef
|
593
|
+
LibTest.testCallbackULrV(0x80000000) { |i| v = i }
|
594
|
+
v.should == 0x80000000
|
595
|
+
end
|
596
|
+
it ":ulong (0xffffffff) argument" do
|
597
|
+
v = 0xdeadbeef
|
598
|
+
LibTest.testCallbackULrV(0xffffffff) { |i| v = i }
|
599
|
+
v.should == 0xffffffff
|
600
|
+
end
|
601
|
+
it ":long_long (0) argument" do
|
602
|
+
v = 0xdeadbeef
|
603
|
+
LibTest.testCallbackLLrV(0) { |i| v = i }
|
604
|
+
v.should == 0
|
605
|
+
end
|
606
|
+
it ":long_long (0x7fffffffffffffff) argument" do
|
607
|
+
v = 0xdeadbeef
|
608
|
+
LibTest.testCallbackLLrV(0x7fffffffffffffff) { |i| v = i }
|
609
|
+
v.should == 0x7fffffffffffffff
|
610
|
+
end
|
611
|
+
it ":long_long (-0x8000000000000000) argument" do
|
612
|
+
v = 0xdeadbeef
|
613
|
+
LibTest.testCallbackLLrV(-0x8000000000000000) { |i| v = i }
|
614
|
+
v.should == -0x8000000000000000
|
615
|
+
end
|
616
|
+
it ":long_long (-1) argument" do
|
617
|
+
v = 0xdeadbeef
|
618
|
+
LibTest.testCallbackLLrV(-1) { |i| v = i }
|
619
|
+
v.should == -1
|
620
|
+
end
|
621
|
+
it ":string argument" do
|
622
|
+
v = nil
|
623
|
+
LibTest.testCallbackArV("Hello, World") { |i| v = i }
|
624
|
+
v.should == "Hello, World"
|
625
|
+
end
|
626
|
+
it ":string (nil) argument" do
|
627
|
+
v = "Hello, World"
|
628
|
+
LibTest.testCallbackArV(nil) { |i| v = i }
|
629
|
+
v.should be_nil
|
630
|
+
end
|
631
|
+
it ":pointer argument" do
|
632
|
+
v = nil
|
633
|
+
magic = FFI::Pointer.new(0xdeadbeef)
|
634
|
+
LibTest.testCallbackPrV(magic) { |i| v = i }
|
635
|
+
v.should == magic
|
636
|
+
end
|
637
|
+
it ":pointer (nil) argument" do
|
638
|
+
v = "Hello, World"
|
639
|
+
LibTest.testCallbackPrV(nil) { |i| v = i }
|
640
|
+
v.should == FFI::Pointer::NULL
|
641
|
+
end
|
642
|
+
it "struct by reference argument" do
|
643
|
+
v = nil
|
644
|
+
magic = LibTest::S8F32S32.new
|
645
|
+
LibTest.testCallbackYrV(magic) { |i| v = i }
|
646
|
+
v.class.should == magic.class
|
647
|
+
v.pointer == magic.pointer
|
648
|
+
end
|
649
|
+
|
650
|
+
it "struct by reference argument with nil value" do
|
651
|
+
v = LibTest::S8F32S32.new
|
652
|
+
LibTest.testCallbackYrV(nil) { |i| v = i }
|
653
|
+
v.is_a?(FFI::Struct).should be_true
|
654
|
+
v.pointer.should == FFI::Pointer::NULL
|
655
|
+
end
|
656
|
+
|
657
|
+
it "varargs parameters are rejected" do
|
658
|
+
lambda {
|
659
|
+
Module.new do
|
660
|
+
extend FFI::Library
|
661
|
+
ffi_lib TestLibrary::PATH
|
662
|
+
callback :cbVrL, [ :varargs ], :long
|
663
|
+
end
|
664
|
+
}.should raise_error(ArgumentError)
|
665
|
+
end
|
666
|
+
|
667
|
+
end
|