ffi 0.5.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ffi might be problematic. Click here for more details.
- data/LICENSE +51 -0
- data/README.rdoc +69 -0
- data/Rakefile +191 -0
- data/ext/ffi_c/AbstractMemory.c +489 -0
- data/ext/ffi_c/AbstractMemory.h +160 -0
- data/ext/ffi_c/ArrayType.c +129 -0
- data/ext/ffi_c/ArrayType.h +58 -0
- data/ext/ffi_c/AutoPointer.c +61 -0
- data/ext/ffi_c/AutoPointer.h +18 -0
- data/ext/ffi_c/Buffer.c +187 -0
- data/ext/ffi_c/Call.c +853 -0
- data/ext/ffi_c/Call.h +86 -0
- data/ext/ffi_c/ClosurePool.c +302 -0
- data/ext/ffi_c/ClosurePool.h +29 -0
- data/ext/ffi_c/DynamicLibrary.c +216 -0
- data/ext/ffi_c/DynamicLibrary.h +22 -0
- data/ext/ffi_c/Function.c +478 -0
- data/ext/ffi_c/Function.h +80 -0
- data/ext/ffi_c/FunctionInfo.c +221 -0
- data/ext/ffi_c/LastError.c +159 -0
- data/ext/ffi_c/LastError.h +18 -0
- data/ext/ffi_c/MemoryPointer.c +178 -0
- data/ext/ffi_c/MemoryPointer.h +20 -0
- data/ext/ffi_c/MethodHandle.c +346 -0
- data/ext/ffi_c/MethodHandle.h +53 -0
- data/ext/ffi_c/Platform.c +59 -0
- data/ext/ffi_c/Platform.h +16 -0
- data/ext/ffi_c/Pointer.c +224 -0
- data/ext/ffi_c/Pointer.h +49 -0
- data/ext/ffi_c/Struct.c +770 -0
- data/ext/ffi_c/Struct.h +80 -0
- data/ext/ffi_c/StructByValue.c +140 -0
- data/ext/ffi_c/StructByValue.h +53 -0
- data/ext/ffi_c/StructLayout.c +450 -0
- data/ext/ffi_c/Type.c +329 -0
- data/ext/ffi_c/Type.h +57 -0
- data/ext/ffi_c/Types.c +103 -0
- data/ext/ffi_c/Types.h +85 -0
- data/ext/ffi_c/Variadic.c +260 -0
- data/ext/ffi_c/compat.h +72 -0
- data/ext/ffi_c/endian.h +40 -0
- data/ext/ffi_c/extconf.rb +30 -0
- data/ext/ffi_c/ffi.c +82 -0
- data/ext/ffi_c/libffi.bsd.mk +34 -0
- data/ext/ffi_c/libffi.darwin.mk +75 -0
- data/ext/ffi_c/libffi.gnu.mk +29 -0
- data/ext/ffi_c/libffi.mk +13 -0
- data/ext/ffi_c/libffi/ChangeLog +3243 -0
- data/ext/ffi_c/libffi/ChangeLog.libffi +347 -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 +177 -0
- data/ext/ffi_c/libffi/Makefile.in +1640 -0
- data/ext/ffi_c/libffi/README +328 -0
- data/ext/ffi_c/libffi/TODO +1 -0
- data/ext/ffi_c/libffi/acinclude.m4 +92 -0
- data/ext/ffi_c/libffi/aclocal.m4 +7516 -0
- data/ext/ffi_c/libffi/compile +142 -0
- data/ext/ffi_c/libffi/config.guess +1516 -0
- data/ext/ffi_c/libffi/config.sub +1626 -0
- data/ext/ffi_c/libffi/configure +24414 -0
- data/ext/ffi_c/libffi/configure.ac +365 -0
- data/ext/ffi_c/libffi/configure.host +11 -0
- data/ext/ffi_c/libffi/depcomp +584 -0
- data/ext/ffi_c/libffi/doc/libffi.info +533 -0
- data/ext/ffi_c/libffi/doc/libffi.texi +541 -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 +160 -0
- data/ext/ffi_c/libffi/include/Makefile.am +9 -0
- data/ext/ffi_c/libffi/include/Makefile.in +422 -0
- data/ext/ffi_c/libffi/include/ffi.h.in +393 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +98 -0
- data/ext/ffi_c/libffi/install-sh +323 -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/ltcf-c.sh +861 -0
- data/ext/ffi_c/libffi/ltcf-cxx.sh +1069 -0
- data/ext/ffi_c/libffi/ltcf-gcj.sh +700 -0
- data/ext/ffi_c/libffi/ltconfig +2862 -0
- data/ext/ffi_c/libffi/ltmain.sh +6930 -0
- data/ext/ffi_c/libffi/man/Makefile.am +8 -0
- data/ext/ffi_c/libffi/man/Makefile.in +395 -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 +353 -0
- data/ext/ffi_c/libffi/mkinstalldirs +158 -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 +366 -0
- data/ext/ffi_c/libffi/src/arm/ffi.c +309 -0
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +49 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +299 -0
- data/ext/ffi_c/libffi/src/closures.c +596 -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 +5099 -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 +61 -0
- data/ext/ffi_c/libffi/src/ia64/ffi.c +580 -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 +359 -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 +278 -0
- data/ext/ffi_c/libffi/src/m68k/ffitarget.h +49 -0
- data/ext/ffi_c/libffi/src/m68k/sysv.S +234 -0
- data/ext/ffi_c/libffi/src/mips/ffi.c +926 -0
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +202 -0
- data/ext/ffi_c/libffi/src/mips/n32.S +534 -0
- data/ext/ffi_c/libffi/src/mips/o32.S +381 -0
- data/ext/ffi_c/libffi/src/pa/ffi.c +709 -0
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +77 -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 +225 -0
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +247 -0
- data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
- data/ext/ffi_c/libffi/src/powerpc/darwin.S +245 -0
- data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +317 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +1429 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +800 -0
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +118 -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 +230 -0
- data/ext/ffi_c/libffi/src/prep_cif.c +174 -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 +60 -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 +453 -0
- data/ext/ffi_c/libffi/src/sh64/ffitarget.h +53 -0
- data/ext/ffi_c/libffi/src/sh64/sysv.S +530 -0
- data/ext/ffi_c/libffi/src/sparc/ffi.c +610 -0
- data/ext/ffi_c/libffi/src/sparc/ffitarget.h +66 -0
- data/ext/ffi_c/libffi/src/sparc/v8.S +272 -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 +443 -0
- data/ext/ffi_c/libffi/src/x86/darwin64.S +416 -0
- data/ext/ffi_c/libffi/src/x86/ffi.c +475 -0
- data/ext/ffi_c/libffi/src/x86/ffi64.c +572 -0
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +90 -0
- data/ext/ffi_c/libffi/src/x86/freebsd.S +458 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +437 -0
- data/ext/ffi_c/libffi/src/x86/unix64.S +418 -0
- data/ext/ffi_c/libffi/src/x86/win32.S +391 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.am +71 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.in +447 -0
- data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
- data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +289 -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 +36 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +97 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +89 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +89 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +97 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +98 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_stdcall.c +72 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +102 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +103 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +104 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +110 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +97 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +101 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +121 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +98 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +103 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +98 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +98 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +106 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +98 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +117 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +106 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +132 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +121 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +107 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +125 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +105 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +96 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +98 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +101 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +100 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +101 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +100 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +51 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +51 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +82 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +82 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +94 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +82 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +94 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +52 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +50 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +50 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +50 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +51 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +54 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +51 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +86 -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 +57 -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/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 +160 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +169 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +141 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +118 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +119 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +119 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +120 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +139 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +119 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +139 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +139 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +98 -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 +42 -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/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.special/ffitestcxx.h +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +38 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +123 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc +53 -0
- data/ext/ffi_c/libffi/texinfo.tex +7482 -0
- data/ext/ffi_c/rbffi.h +26 -0
- data/gen/Rakefile +12 -0
- data/lib/1.8/ffi_c.so +0 -0
- data/lib/1.9/ffi_c.so +0 -0
- data/lib/ffi.rb +11 -0
- data/lib/ffi/autopointer.rb +61 -0
- data/lib/ffi/buffer.rb +0 -0
- data/lib/ffi/callback.rb +10 -0
- data/lib/ffi/enum.rb +78 -0
- data/lib/ffi/errno.rb +8 -0
- data/lib/ffi/ffi.rb +99 -0
- data/lib/ffi/io.rb +21 -0
- data/lib/ffi/library.rb +218 -0
- data/lib/ffi/managedstruct.rb +55 -0
- data/lib/ffi/memorypointer.rb +73 -0
- data/lib/ffi/platform.rb +88 -0
- data/lib/ffi/pointer.rb +119 -0
- data/lib/ffi/struct.rb +183 -0
- data/lib/ffi/tools/const_generator.rb +177 -0
- data/lib/ffi/tools/generator.rb +58 -0
- data/lib/ffi/tools/generator_task.rb +35 -0
- data/lib/ffi/tools/struct_generator.rb +194 -0
- data/lib/ffi/tools/types_generator.rb +123 -0
- data/lib/ffi/types.rb +153 -0
- data/lib/ffi/union.rb +12 -0
- data/lib/ffi/variadic.rb +25 -0
- data/spec/ffi/bool_spec.rb +24 -0
- data/spec/ffi/buffer_spec.rb +202 -0
- data/spec/ffi/callback_spec.rb +591 -0
- data/spec/ffi/enum_spec.rb +164 -0
- data/spec/ffi/errno_spec.rb +13 -0
- data/spec/ffi/function_spec.rb +73 -0
- data/spec/ffi/library_spec.rb +148 -0
- data/spec/ffi/managed_struct_spec.rb +56 -0
- data/spec/ffi/number_spec.rb +231 -0
- data/spec/ffi/pointer_spec.rb +195 -0
- data/spec/ffi/rbx/attach_function_spec.rb +27 -0
- data/spec/ffi/rbx/memory_pointer_spec.rb +102 -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 +17 -0
- data/spec/ffi/string_spec.rb +103 -0
- data/spec/ffi/struct_callback_spec.rb +64 -0
- data/spec/ffi/struct_initialize_spec.rb +30 -0
- data/spec/ffi/struct_spec.rb +529 -0
- data/spec/ffi/typedef_spec.rb +48 -0
- data/spec/ffi/union_spec.rb +60 -0
- data/spec/ffi/variadic_spec.rb +84 -0
- data/spec/spec.opts +4 -0
- metadata +396 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
2
|
+
|
3
|
+
module TestEnum0
|
4
|
+
extend FFI::Library
|
5
|
+
end
|
6
|
+
|
7
|
+
module TestEnum1
|
8
|
+
extend FFI::Library
|
9
|
+
ffi_lib TestLibrary::PATH
|
10
|
+
|
11
|
+
enum [:c1, :c2, :c3, :c4]
|
12
|
+
enum [:c5, 42, :c6, :c7, :c8]
|
13
|
+
enum [:c9, 42, :c10, :c11, 4242, :c12]
|
14
|
+
enum [:c13, 42, :c14, 4242, :c15, 424242, :c16, 42424242]
|
15
|
+
|
16
|
+
attach_function :test_untagged_enum, [:int], :int
|
17
|
+
end
|
18
|
+
|
19
|
+
module TestEnum3
|
20
|
+
extend FFI::Library
|
21
|
+
ffi_lib TestLibrary::PATH
|
22
|
+
|
23
|
+
enum :enum_type1, [:c1, :c2, :c3, :c4]
|
24
|
+
enum :enum_type2, [:c5, 42, :c6, :c7, :c8]
|
25
|
+
enum :enum_type3, [:c9, 42, :c10, :c11, 4242, :c12]
|
26
|
+
enum :enum_type4, [:c13, 42, :c14, 4242, :c15, 424242, :c16, 42424242]
|
27
|
+
|
28
|
+
attach_function :test_tagged_typedef_enum1, [:enum_type1], :enum_type1
|
29
|
+
attach_function :test_tagged_typedef_enum2, [:enum_type2], :enum_type2
|
30
|
+
attach_function :test_tagged_typedef_enum3, [:enum_type3], :enum_type3
|
31
|
+
attach_function :test_tagged_typedef_enum4, [:enum_type4], :enum_type4
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "A library with no enum defined" do
|
35
|
+
it "returns nil when asked for an enum" do
|
36
|
+
TestEnum0.enum_type(:foo).should == nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "An untagged enum" do
|
41
|
+
it "constants can be used as function parameters and return value" do
|
42
|
+
TestEnum1.test_untagged_enum(:c1).should == 0
|
43
|
+
TestEnum1.test_untagged_enum(:c2).should == 1
|
44
|
+
TestEnum1.test_untagged_enum(:c3).should == 2
|
45
|
+
TestEnum1.test_untagged_enum(:c4).should == 3
|
46
|
+
TestEnum1.test_untagged_enum(:c5).should == 42
|
47
|
+
TestEnum1.test_untagged_enum(:c6).should == 43
|
48
|
+
TestEnum1.test_untagged_enum(:c7).should == 44
|
49
|
+
TestEnum1.test_untagged_enum(:c8).should == 45
|
50
|
+
TestEnum1.test_untagged_enum(:c9).should == 42
|
51
|
+
TestEnum1.test_untagged_enum(:c10).should == 43
|
52
|
+
TestEnum1.test_untagged_enum(:c11).should == 4242
|
53
|
+
TestEnum1.test_untagged_enum(:c12).should == 4243
|
54
|
+
TestEnum1.test_untagged_enum(:c13).should == 42
|
55
|
+
TestEnum1.test_untagged_enum(:c14).should == 4242
|
56
|
+
TestEnum1.test_untagged_enum(:c15).should == 424242
|
57
|
+
TestEnum1.test_untagged_enum(:c16).should == 42424242
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "A tagged typedef enum" do
|
62
|
+
it "is accessible through its tag" do
|
63
|
+
TestEnum3.enum_type(:enum_type1).should_not == nil
|
64
|
+
TestEnum3.enum_type(:enum_type2).should_not == nil
|
65
|
+
TestEnum3.enum_type(:enum_type3).should_not == nil
|
66
|
+
TestEnum3.enum_type(:enum_type4).should_not == nil
|
67
|
+
end
|
68
|
+
it "contains enum constants" do
|
69
|
+
TestEnum3.enum_type(:enum_type1).symbols.length.should == 4
|
70
|
+
TestEnum3.enum_type(:enum_type2).symbols.length.should == 4
|
71
|
+
TestEnum3.enum_type(:enum_type3).symbols.length.should == 4
|
72
|
+
TestEnum3.enum_type(:enum_type4).symbols.length.should == 4
|
73
|
+
end
|
74
|
+
it "constants can be used as function parameters and return value" do
|
75
|
+
TestEnum3.test_tagged_typedef_enum1(:c1).should == :c1
|
76
|
+
TestEnum3.test_tagged_typedef_enum1(:c2).should == :c2
|
77
|
+
TestEnum3.test_tagged_typedef_enum1(:c3).should == :c3
|
78
|
+
TestEnum3.test_tagged_typedef_enum1(:c4).should == :c4
|
79
|
+
TestEnum3.test_tagged_typedef_enum2(:c5).should == :c5
|
80
|
+
TestEnum3.test_tagged_typedef_enum2(:c6).should == :c6
|
81
|
+
TestEnum3.test_tagged_typedef_enum2(:c7).should == :c7
|
82
|
+
TestEnum3.test_tagged_typedef_enum2(:c8).should == :c8
|
83
|
+
TestEnum3.test_tagged_typedef_enum3(:c9).should == :c9
|
84
|
+
TestEnum3.test_tagged_typedef_enum3(:c10).should == :c10
|
85
|
+
TestEnum3.test_tagged_typedef_enum3(:c11).should == :c11
|
86
|
+
TestEnum3.test_tagged_typedef_enum3(:c12).should == :c12
|
87
|
+
TestEnum3.test_tagged_typedef_enum4(:c13).should == :c13
|
88
|
+
TestEnum3.test_tagged_typedef_enum4(:c14).should == :c14
|
89
|
+
TestEnum3.test_tagged_typedef_enum4(:c15).should == :c15
|
90
|
+
TestEnum3.test_tagged_typedef_enum4(:c16).should == :c16
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "All enums" do
|
95
|
+
it "have autonumbered constants when defined with names only" do
|
96
|
+
TestEnum1.enum_value(:c1).should == 0
|
97
|
+
TestEnum1.enum_value(:c2).should == 1
|
98
|
+
TestEnum1.enum_value(:c3).should == 2
|
99
|
+
TestEnum1.enum_value(:c4).should == 3
|
100
|
+
|
101
|
+
TestEnum3.enum_value(:c1).should == 0
|
102
|
+
TestEnum3.enum_value(:c2).should == 1
|
103
|
+
TestEnum3.enum_value(:c3).should == 2
|
104
|
+
TestEnum3.enum_value(:c4).should == 3
|
105
|
+
end
|
106
|
+
it "can have an explicit first constant and autonumbered subsequent constants" do
|
107
|
+
TestEnum1.enum_value(:c5).should == 42
|
108
|
+
TestEnum1.enum_value(:c6).should == 43
|
109
|
+
TestEnum1.enum_value(:c7).should == 44
|
110
|
+
TestEnum1.enum_value(:c8).should == 45
|
111
|
+
|
112
|
+
TestEnum3.enum_value(:c5).should == 42
|
113
|
+
TestEnum3.enum_value(:c6).should == 43
|
114
|
+
TestEnum3.enum_value(:c7).should == 44
|
115
|
+
TestEnum3.enum_value(:c8).should == 45
|
116
|
+
end
|
117
|
+
it "can have a mix of explicit and autonumbered constants" do
|
118
|
+
TestEnum1.enum_value(:c9).should == 42
|
119
|
+
TestEnum1.enum_value(:c10).should == 43
|
120
|
+
TestEnum1.enum_value(:c11).should == 4242
|
121
|
+
TestEnum1.enum_value(:c12).should == 4243
|
122
|
+
|
123
|
+
TestEnum3.enum_value(:c9).should == 42
|
124
|
+
TestEnum3.enum_value(:c10).should == 43
|
125
|
+
TestEnum3.enum_value(:c11).should == 4242
|
126
|
+
TestEnum3.enum_value(:c12).should == 4243
|
127
|
+
end
|
128
|
+
it "can have all its constants explicitely valued" do
|
129
|
+
TestEnum1.enum_value(:c13).should == 42
|
130
|
+
TestEnum1.enum_value(:c14).should == 4242
|
131
|
+
TestEnum1.enum_value(:c15).should == 424242
|
132
|
+
TestEnum1.enum_value(:c16).should == 42424242
|
133
|
+
|
134
|
+
TestEnum3.enum_value(:c13).should == 42
|
135
|
+
TestEnum3.enum_value(:c14).should == 4242
|
136
|
+
TestEnum3.enum_value(:c15).should == 424242
|
137
|
+
TestEnum3.enum_value(:c16).should == 42424242
|
138
|
+
end
|
139
|
+
it "return the constant corresponding to a specific value" do
|
140
|
+
enum = TestEnum3.enum_type(:enum_type1)
|
141
|
+
enum[0].should == :c1
|
142
|
+
enum[1].should == :c2
|
143
|
+
enum[2].should == :c3
|
144
|
+
enum[3].should == :c4
|
145
|
+
|
146
|
+
enum = TestEnum3.enum_type(:enum_type2)
|
147
|
+
enum[42].should == :c5
|
148
|
+
enum[43].should == :c6
|
149
|
+
enum[44].should == :c7
|
150
|
+
enum[45].should == :c8
|
151
|
+
|
152
|
+
enum = TestEnum3.enum_type(:enum_type3)
|
153
|
+
enum[42].should == :c9
|
154
|
+
enum[43].should == :c10
|
155
|
+
enum[4242].should == :c11
|
156
|
+
enum[4243].should == :c12
|
157
|
+
|
158
|
+
enum = TestEnum3.enum_type(:enum_type4)
|
159
|
+
enum[42].should == :c13
|
160
|
+
enum[4242].should == :c14
|
161
|
+
enum[424242].should == :c15
|
162
|
+
enum[42424242].should == :c16
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
2
|
+
describe "FFI.errno" do
|
3
|
+
module LibTest
|
4
|
+
extend FFI::Library
|
5
|
+
ffi_lib TestLibrary::PATH
|
6
|
+
attach_function :setLastError, [ :int ], :void
|
7
|
+
end
|
8
|
+
it "FFI.errno contains errno from last function" do
|
9
|
+
LibTest.setLastError(0)
|
10
|
+
LibTest.setLastError(0x12345678)
|
11
|
+
FFI.errno.should == 0x12345678
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
2
|
+
|
3
|
+
describe FFI::Function do
|
4
|
+
before do
|
5
|
+
module LibTest
|
6
|
+
extend FFI::Library
|
7
|
+
ffi_lib TestLibrary::PATH
|
8
|
+
attach_function :testFunctionAdd, [:int, :int, :pointer], :int
|
9
|
+
end
|
10
|
+
@libtest = FFI::DynamicLibrary.open(TestLibrary::PATH,
|
11
|
+
FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_GLOBAL)
|
12
|
+
end
|
13
|
+
it 'is initialized with a signature and a block' do
|
14
|
+
FFI::Function.new(:int, []) { }
|
15
|
+
end
|
16
|
+
it 'raises an error when passing a wrong signature' do
|
17
|
+
lambda { FFI::Function.new([], :int).new { } }.should raise_error TypeError
|
18
|
+
end
|
19
|
+
it 'returns a native pointer' do
|
20
|
+
FFI::Function.new(:int, []) { }.kind_of? FFI::Pointer
|
21
|
+
end
|
22
|
+
it 'can be used as callback from C passing to it a block' do
|
23
|
+
function_add = FFI::Function.new(:int, [:int, :int]) { |a, b| a + b }
|
24
|
+
LibTest.testFunctionAdd(10, 10, function_add).should == 20
|
25
|
+
end
|
26
|
+
it 'can be used as callback from C passing to it a Proc object' do
|
27
|
+
function_add = FFI::Function.new(:int, [:int, :int], Proc.new { |a, b| a + b })
|
28
|
+
LibTest.testFunctionAdd(10, 10, function_add).should == 20
|
29
|
+
end
|
30
|
+
it 'can be used to wrap an existing function pointer' do
|
31
|
+
FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd')).call(10, 10).should == 20
|
32
|
+
end
|
33
|
+
it 'can be attached to a module' do
|
34
|
+
module Foo; end
|
35
|
+
fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd'))
|
36
|
+
fp.attach(Foo, 'add')
|
37
|
+
Foo.add(10, 10).should == 20
|
38
|
+
end
|
39
|
+
it 'can be used to extend an object' do
|
40
|
+
fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd'))
|
41
|
+
foo = Object.new
|
42
|
+
class << foo
|
43
|
+
def singleton_class
|
44
|
+
class << self; self; end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
fp.attach(foo.singleton_class, 'add')
|
48
|
+
foo.add(10, 10).should == 20
|
49
|
+
end
|
50
|
+
it 'can wrap a blocking function' do
|
51
|
+
unless RUBY_VERSION =~ /1.8/
|
52
|
+
fp = FFI::Function.new(:void, [ :int ], @libtest.find_function('testBlocking'), :blocking => true)
|
53
|
+
time = Time.now
|
54
|
+
threads = []
|
55
|
+
threads << Thread.new { fp.call(2) }
|
56
|
+
threads << Thread.new(time) { (Time.now - time).should < 1 }
|
57
|
+
threads.each { |t| t.join }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
it 'autorelease flag is set to true by default' do
|
61
|
+
fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd'))
|
62
|
+
fp.autorelease?.should be_true
|
63
|
+
end
|
64
|
+
it 'can explicity free itself' do
|
65
|
+
fp = FFI::Function.new(:int, []) { }
|
66
|
+
fp.free
|
67
|
+
lambda { fp.free }.should raise_error RuntimeError
|
68
|
+
end
|
69
|
+
it 'can\'t explicity free itself if not previously allocated' do
|
70
|
+
fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd'))
|
71
|
+
lambda { fp.free }.should raise_error RuntimeError
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
2
|
+
describe "Library" do
|
3
|
+
|
4
|
+
unless Config::CONFIG['target_os'] =~ /mingw/ || Config::CONFIG['target_os'] =~ /win/
|
5
|
+
it "attach_function with no library specified" do
|
6
|
+
lambda {
|
7
|
+
Module.new do |m|
|
8
|
+
m.extend FFI::Library
|
9
|
+
attach_function :getpid, [ ], :uint
|
10
|
+
end
|
11
|
+
}.should_not raise_error
|
12
|
+
end
|
13
|
+
it "attach_function :getpid from this process" do
|
14
|
+
lambda {
|
15
|
+
Module.new do |m|
|
16
|
+
m.extend FFI::Library
|
17
|
+
attach_function :getpid, [ ], :uint
|
18
|
+
end.getpid.should == Process.pid
|
19
|
+
}.should_not raise_error
|
20
|
+
end
|
21
|
+
it "attach_function :getpid from [ 'c', 'libc.so.6'] " do
|
22
|
+
lambda {
|
23
|
+
Module.new do |m|
|
24
|
+
m.extend FFI::Library
|
25
|
+
ffi_lib 'c', 'libc.so.6'
|
26
|
+
attach_function :getpid, [ ], :uint
|
27
|
+
end.getpid.should == Process.pid
|
28
|
+
}.should_not raise_error
|
29
|
+
end
|
30
|
+
it "attach_function :getpid from [ 'libc.so.6', 'c' ] " do
|
31
|
+
lambda {
|
32
|
+
Module.new do |m|
|
33
|
+
m.extend FFI::Library
|
34
|
+
ffi_lib 'libc.so.6', 'c'
|
35
|
+
attach_function :getpid, [ ], :uint
|
36
|
+
end.getpid.should == Process.pid
|
37
|
+
}.should_not raise_error
|
38
|
+
end
|
39
|
+
it "attach_function :getpid from [ 'libfubar.so.0xdeadbeef', nil, 'c' ] " do
|
40
|
+
lambda {
|
41
|
+
Module.new do |m|
|
42
|
+
m.extend FFI::Library
|
43
|
+
ffi_lib 'libfubar.so.0xdeadbeef', nil, 'c'
|
44
|
+
attach_function :getpid, [ ], :uint
|
45
|
+
end.getpid.should == Process.pid
|
46
|
+
}.should_not raise_error
|
47
|
+
end
|
48
|
+
it "attach_function :getpid from [ 'libfubar.so.0xdeadbeef' ] " do
|
49
|
+
lambda {
|
50
|
+
Module.new do |m|
|
51
|
+
m.extend FFI::Library
|
52
|
+
ffi_lib 'libfubar.so.0xdeadbeef'
|
53
|
+
attach_function :getpid, [ ], :uint
|
54
|
+
end.getpid.should == Process.pid
|
55
|
+
}.should raise_error(LoadError)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def gvar_lib(name, type)
|
60
|
+
Module.new do |m|
|
61
|
+
m.extend FFI::Library
|
62
|
+
ffi_lib TestLibrary::PATH
|
63
|
+
attach_variable :gvar, "gvar_#{name}", type
|
64
|
+
attach_function :get, "gvar_#{name}_get", [], type
|
65
|
+
attach_function :set, "gvar_#{name}_set", [ type ], :void
|
66
|
+
end
|
67
|
+
end
|
68
|
+
def gvar_test(name, type, val)
|
69
|
+
lib = gvar_lib(name, type)
|
70
|
+
lib.set(val)
|
71
|
+
lib.gvar.should == val
|
72
|
+
lib.set(0)
|
73
|
+
lib.gvar = val
|
74
|
+
lib.get.should == val
|
75
|
+
end
|
76
|
+
[ 0, 127, -128, -1 ].each do |i|
|
77
|
+
it ":char variable" do
|
78
|
+
gvar_test("s8", :char, i)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
[ 0, 0x7f, 0x80, 0xff ].each do |i|
|
82
|
+
it ":uchar variable" do
|
83
|
+
gvar_test("u8", :uchar, i)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
[ 0, 0x7fff, -0x8000, -1 ].each do |i|
|
87
|
+
it ":short variable" do
|
88
|
+
gvar_test("s16", :short, i)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
[ 0, 0x7fff, 0x8000, 0xffff ].each do |i|
|
92
|
+
it ":ushort variable" do
|
93
|
+
gvar_test("u16", :ushort, i)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
[ 0, 0x7fffffff, -0x80000000, -1 ].each do |i|
|
97
|
+
it ":int variable" do
|
98
|
+
gvar_test("s32", :int, i)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
[ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i|
|
102
|
+
it ":uint variable" do
|
103
|
+
gvar_test("u32", :uint, i)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
[ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i|
|
107
|
+
it ":long_long variable" do
|
108
|
+
gvar_test("s64", :long_long, i)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
[ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i|
|
112
|
+
it ":ulong_long variable" do
|
113
|
+
gvar_test("u64", :ulong_long, i)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
if FFI::Platform::LONG_SIZE == 32
|
117
|
+
[ 0, 0x7fffffff, -0x80000000, -1 ].each do |i|
|
118
|
+
it ":long variable" do
|
119
|
+
gvar_test("long", :long, i)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
[ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i|
|
123
|
+
it ":ulong variable" do
|
124
|
+
gvar_test("ulong", :ulong, i)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
else
|
128
|
+
[ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i|
|
129
|
+
it ":long variable" do
|
130
|
+
gvar_test("long", :long, i)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
[ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i|
|
134
|
+
it ":ulong variable" do
|
135
|
+
gvar_test("ulong", :ulong, i)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
it "Pointer variable" do
|
140
|
+
lib = gvar_lib("pointer", :pointer)
|
141
|
+
val = FFI::MemoryPointer.new :long
|
142
|
+
lib.set(val)
|
143
|
+
lib.gvar.should == val
|
144
|
+
lib.set(nil)
|
145
|
+
lib.gvar = val
|
146
|
+
lib.get.should == val
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
2
|
+
require 'java' if RUBY_PLATFORM =~ /java/
|
3
|
+
|
4
|
+
describe "Managed Struct" do
|
5
|
+
include FFI
|
6
|
+
module LibTest
|
7
|
+
extend FFI::Library
|
8
|
+
ffi_lib TestLibrary::PATH
|
9
|
+
attach_function :ptr_from_address, [ FFI::Platform::ADDRESS_SIZE == 32 ? :uint : :ulong_long ], :pointer
|
10
|
+
end
|
11
|
+
it "should raise an error if release() is not defined" do
|
12
|
+
class NoRelease < FFI::ManagedStruct ; layout :i, :int; end
|
13
|
+
lambda { NoRelease.new(LibTest.ptr_from_address(0x12345678)) }.should raise_error(NoMethodError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be the right class" do
|
17
|
+
class WhatClassAmI < FFI::ManagedStruct
|
18
|
+
layout :i, :int
|
19
|
+
def self.release
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
WhatClassAmI.new(LibTest.ptr_from_address(0x12345678)).class.should == WhatClassAmI
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should release memory properly" do
|
27
|
+
class PleaseReleaseMe < FFI::ManagedStruct
|
28
|
+
layout :i, :int
|
29
|
+
@@count = 0
|
30
|
+
def self.release
|
31
|
+
@@count += 1
|
32
|
+
end
|
33
|
+
def self.wait_gc(count)
|
34
|
+
loop = 5
|
35
|
+
while loop > 0 && @@count < count
|
36
|
+
loop -= 1
|
37
|
+
if RUBY_PLATFORM =~ /java/
|
38
|
+
java.lang.System.gc
|
39
|
+
else
|
40
|
+
GC.start
|
41
|
+
end
|
42
|
+
sleep 0.05 if @@count < count
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
loop_count = 30
|
48
|
+
wiggle_room = 2
|
49
|
+
|
50
|
+
PleaseReleaseMe.should_receive(:release).at_least(loop_count-wiggle_room).times
|
51
|
+
loop_count.times do
|
52
|
+
s = PleaseReleaseMe.new(LibTest.ptr_from_address(0x12345678))
|
53
|
+
end
|
54
|
+
PleaseReleaseMe.wait_gc loop_count
|
55
|
+
end
|
56
|
+
end
|