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
@@ -0,0 +1,600 @@
|
|
1
|
+
\input texinfo @c -*-texinfo-*-
|
2
|
+
@c %**start of header
|
3
|
+
@setfilename libffi.info
|
4
|
+
@settitle libffi
|
5
|
+
@setchapternewpage off
|
6
|
+
@c %**end of header
|
7
|
+
|
8
|
+
@c Merge the standard indexes into a single one.
|
9
|
+
@syncodeindex fn cp
|
10
|
+
@syncodeindex vr cp
|
11
|
+
@syncodeindex ky cp
|
12
|
+
@syncodeindex pg cp
|
13
|
+
@syncodeindex tp cp
|
14
|
+
|
15
|
+
@include version.texi
|
16
|
+
|
17
|
+
@copying
|
18
|
+
|
19
|
+
This manual is for Libffi, a portable foreign-function interface
|
20
|
+
library.
|
21
|
+
|
22
|
+
Copyright @copyright{} 2008, 2010 Red Hat, Inc.
|
23
|
+
|
24
|
+
@quotation
|
25
|
+
Permission is granted to copy, distribute and/or modify this document
|
26
|
+
under the terms of the GNU General Public License as published by the
|
27
|
+
Free Software Foundation; either version 2, or (at your option) any
|
28
|
+
later version. A copy of the license is included in the
|
29
|
+
section entitled ``GNU General Public License''.
|
30
|
+
|
31
|
+
@end quotation
|
32
|
+
@end copying
|
33
|
+
|
34
|
+
@dircategory Development
|
35
|
+
@direntry
|
36
|
+
* libffi: (libffi). Portable foreign-function interface library.
|
37
|
+
@end direntry
|
38
|
+
|
39
|
+
@titlepage
|
40
|
+
@title Libffi
|
41
|
+
@page
|
42
|
+
@vskip 0pt plus 1filll
|
43
|
+
@insertcopying
|
44
|
+
@end titlepage
|
45
|
+
|
46
|
+
|
47
|
+
@ifnottex
|
48
|
+
@node Top
|
49
|
+
@top libffi
|
50
|
+
|
51
|
+
@insertcopying
|
52
|
+
|
53
|
+
@menu
|
54
|
+
* Introduction:: What is libffi?
|
55
|
+
* Using libffi:: How to use libffi.
|
56
|
+
* Missing Features:: Things libffi can't do.
|
57
|
+
* Index:: Index.
|
58
|
+
@end menu
|
59
|
+
|
60
|
+
@end ifnottex
|
61
|
+
|
62
|
+
|
63
|
+
@node Introduction
|
64
|
+
@chapter What is libffi?
|
65
|
+
|
66
|
+
Compilers for high level languages generate code that follow certain
|
67
|
+
conventions. These conventions are necessary, in part, for separate
|
68
|
+
compilation to work. One such convention is the @dfn{calling
|
69
|
+
convention}. The calling convention is a set of assumptions made by
|
70
|
+
the compiler about where function arguments will be found on entry to
|
71
|
+
a function. A calling convention also specifies where the return
|
72
|
+
value for a function is found. The calling convention is also
|
73
|
+
sometimes called the @dfn{ABI} or @dfn{Application Binary Interface}.
|
74
|
+
@cindex calling convention
|
75
|
+
@cindex ABI
|
76
|
+
@cindex Application Binary Interface
|
77
|
+
|
78
|
+
Some programs may not know at the time of compilation what arguments
|
79
|
+
are to be passed to a function. For instance, an interpreter may be
|
80
|
+
told at run-time about the number and types of arguments used to call
|
81
|
+
a given function. @samp{Libffi} can be used in such programs to
|
82
|
+
provide a bridge from the interpreter program to compiled code.
|
83
|
+
|
84
|
+
The @samp{libffi} library provides a portable, high level programming
|
85
|
+
interface to various calling conventions. This allows a programmer to
|
86
|
+
call any function specified by a call interface description at run
|
87
|
+
time.
|
88
|
+
|
89
|
+
@acronym{FFI} stands for Foreign Function Interface. A foreign
|
90
|
+
function interface is the popular name for the interface that allows
|
91
|
+
code written in one language to call code written in another language.
|
92
|
+
The @samp{libffi} library really only provides the lowest, machine
|
93
|
+
dependent layer of a fully featured foreign function interface. A
|
94
|
+
layer must exist above @samp{libffi} that handles type conversions for
|
95
|
+
values passed between the two languages.
|
96
|
+
@cindex FFI
|
97
|
+
@cindex Foreign Function Interface
|
98
|
+
|
99
|
+
|
100
|
+
@node Using libffi
|
101
|
+
@chapter Using libffi
|
102
|
+
|
103
|
+
@menu
|
104
|
+
* The Basics:: The basic libffi API.
|
105
|
+
* Simple Example:: A simple example.
|
106
|
+
* Types:: libffi type descriptions.
|
107
|
+
* Multiple ABIs:: Different passing styles on one platform.
|
108
|
+
* The Closure API:: Writing a generic function.
|
109
|
+
* Closure Example:: A closure example.
|
110
|
+
@end menu
|
111
|
+
|
112
|
+
|
113
|
+
@node The Basics
|
114
|
+
@section The Basics
|
115
|
+
|
116
|
+
@samp{Libffi} assumes that you have a pointer to the function you wish
|
117
|
+
to call and that you know the number and types of arguments to pass
|
118
|
+
it, as well as the return type of the function.
|
119
|
+
|
120
|
+
The first thing you must do is create an @code{ffi_cif} object that
|
121
|
+
matches the signature of the function you wish to call. This is a
|
122
|
+
separate step because it is common to make multiple calls using a
|
123
|
+
single @code{ffi_cif}. The @dfn{cif} in @code{ffi_cif} stands for
|
124
|
+
Call InterFace. To prepare a call interface object, use the function
|
125
|
+
@code{ffi_prep_cif}.
|
126
|
+
@cindex cif
|
127
|
+
|
128
|
+
@findex ffi_prep_cif
|
129
|
+
@defun ffi_status ffi_prep_cif (ffi_cif *@var{cif}, ffi_abi @var{abi}, unsigned int @var{nargs}, ffi_type *@var{rtype}, ffi_type **@var{argtypes})
|
130
|
+
This initializes @var{cif} according to the given parameters.
|
131
|
+
|
132
|
+
@var{abi} is the ABI to use; normally @code{FFI_DEFAULT_ABI} is what
|
133
|
+
you want. @ref{Multiple ABIs} for more information.
|
134
|
+
|
135
|
+
@var{nargs} is the number of arguments that this function accepts.
|
136
|
+
@samp{libffi} does not yet handle varargs functions; see @ref{Missing
|
137
|
+
Features} for more information.
|
138
|
+
|
139
|
+
@var{rtype} is a pointer to an @code{ffi_type} structure that
|
140
|
+
describes the return type of the function. @xref{Types}.
|
141
|
+
|
142
|
+
@var{argtypes} is a vector of @code{ffi_type} pointers.
|
143
|
+
@var{argtypes} must have @var{nargs} elements. If @var{nargs} is 0,
|
144
|
+
this argument is ignored.
|
145
|
+
|
146
|
+
@code{ffi_prep_cif} returns a @code{libffi} status code, of type
|
147
|
+
@code{ffi_status}. This will be either @code{FFI_OK} if everything
|
148
|
+
worked properly; @code{FFI_BAD_TYPEDEF} if one of the @code{ffi_type}
|
149
|
+
objects is incorrect; or @code{FFI_BAD_ABI} if the @var{abi} parameter
|
150
|
+
is invalid.
|
151
|
+
@end defun
|
152
|
+
|
153
|
+
|
154
|
+
To call a function using an initialized @code{ffi_cif}, use the
|
155
|
+
@code{ffi_call} function:
|
156
|
+
|
157
|
+
@findex ffi_call
|
158
|
+
@defun void ffi_call (ffi_cif *@var{cif}, void *@var{fn}, void *@var{rvalue}, void **@var{avalues})
|
159
|
+
This calls the function @var{fn} according to the description given in
|
160
|
+
@var{cif}. @var{cif} must have already been prepared using
|
161
|
+
@code{ffi_prep_cif}.
|
162
|
+
|
163
|
+
@var{rvalue} is a pointer to a chunk of memory that will hold the
|
164
|
+
result of the function call. This must be large enough to hold the
|
165
|
+
result and must be suitably aligned; it is the caller's responsibility
|
166
|
+
to ensure this. If @var{cif} declares that the function returns
|
167
|
+
@code{void} (using @code{ffi_type_void}), then @var{rvalue} is
|
168
|
+
ignored. If @var{rvalue} is @samp{NULL}, then the return value is
|
169
|
+
discarded.
|
170
|
+
|
171
|
+
@var{avalues} is a vector of @code{void *} pointers that point to the
|
172
|
+
memory locations holding the argument values for a call. If @var{cif}
|
173
|
+
declares that the function has no arguments (i.e., @var{nargs} was 0),
|
174
|
+
then @var{avalues} is ignored. Note that argument values may be
|
175
|
+
modified by the callee (for instance, structs passed by value); the
|
176
|
+
burden of copying pass-by-value arguments is placed on the caller.
|
177
|
+
@end defun
|
178
|
+
|
179
|
+
|
180
|
+
@node Simple Example
|
181
|
+
@section Simple Example
|
182
|
+
|
183
|
+
Here is a trivial example that calls @code{puts} a few times.
|
184
|
+
|
185
|
+
@example
|
186
|
+
#include <stdio.h>
|
187
|
+
#include <ffi.h>
|
188
|
+
|
189
|
+
int main()
|
190
|
+
@{
|
191
|
+
ffi_cif cif;
|
192
|
+
ffi_type *args[1];
|
193
|
+
void *values[1];
|
194
|
+
char *s;
|
195
|
+
int rc;
|
196
|
+
|
197
|
+
/* Initialize the argument info vectors */
|
198
|
+
args[0] = &ffi_type_pointer;
|
199
|
+
values[0] = &s;
|
200
|
+
|
201
|
+
/* Initialize the cif */
|
202
|
+
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
|
203
|
+
&ffi_type_uint, args) == FFI_OK)
|
204
|
+
@{
|
205
|
+
s = "Hello World!";
|
206
|
+
ffi_call(&cif, puts, &rc, values);
|
207
|
+
/* rc now holds the result of the call to puts */
|
208
|
+
|
209
|
+
/* values holds a pointer to the function's arg, so to
|
210
|
+
call puts() again all we need to do is change the
|
211
|
+
value of s */
|
212
|
+
s = "This is cool!";
|
213
|
+
ffi_call(&cif, puts, &rc, values);
|
214
|
+
@}
|
215
|
+
|
216
|
+
return 0;
|
217
|
+
@}
|
218
|
+
@end example
|
219
|
+
|
220
|
+
|
221
|
+
@node Types
|
222
|
+
@section Types
|
223
|
+
|
224
|
+
@menu
|
225
|
+
* Primitive Types:: Built-in types.
|
226
|
+
* Structures:: Structure types.
|
227
|
+
* Type Example:: Structure type example.
|
228
|
+
@end menu
|
229
|
+
|
230
|
+
@node Primitive Types
|
231
|
+
@subsection Primitive Types
|
232
|
+
|
233
|
+
@code{Libffi} provides a number of built-in type descriptors that can
|
234
|
+
be used to describe argument and return types:
|
235
|
+
|
236
|
+
@table @code
|
237
|
+
@item ffi_type_void
|
238
|
+
@tindex ffi_type_void
|
239
|
+
The type @code{void}. This cannot be used for argument types, only
|
240
|
+
for return values.
|
241
|
+
|
242
|
+
@item ffi_type_uint8
|
243
|
+
@tindex ffi_type_uint8
|
244
|
+
An unsigned, 8-bit integer type.
|
245
|
+
|
246
|
+
@item ffi_type_sint8
|
247
|
+
@tindex ffi_type_sint8
|
248
|
+
A signed, 8-bit integer type.
|
249
|
+
|
250
|
+
@item ffi_type_uint16
|
251
|
+
@tindex ffi_type_uint16
|
252
|
+
An unsigned, 16-bit integer type.
|
253
|
+
|
254
|
+
@item ffi_type_sint16
|
255
|
+
@tindex ffi_type_sint16
|
256
|
+
A signed, 16-bit integer type.
|
257
|
+
|
258
|
+
@item ffi_type_uint32
|
259
|
+
@tindex ffi_type_uint32
|
260
|
+
An unsigned, 32-bit integer type.
|
261
|
+
|
262
|
+
@item ffi_type_sint32
|
263
|
+
@tindex ffi_type_sint32
|
264
|
+
A signed, 32-bit integer type.
|
265
|
+
|
266
|
+
@item ffi_type_uint64
|
267
|
+
@tindex ffi_type_uint64
|
268
|
+
An unsigned, 64-bit integer type.
|
269
|
+
|
270
|
+
@item ffi_type_sint64
|
271
|
+
@tindex ffi_type_sint64
|
272
|
+
A signed, 64-bit integer type.
|
273
|
+
|
274
|
+
@item ffi_type_float
|
275
|
+
@tindex ffi_type_float
|
276
|
+
The C @code{float} type.
|
277
|
+
|
278
|
+
@item ffi_type_double
|
279
|
+
@tindex ffi_type_double
|
280
|
+
The C @code{double} type.
|
281
|
+
|
282
|
+
@item ffi_type_uchar
|
283
|
+
@tindex ffi_type_uchar
|
284
|
+
The C @code{unsigned char} type.
|
285
|
+
|
286
|
+
@item ffi_type_schar
|
287
|
+
@tindex ffi_type_schar
|
288
|
+
The C @code{signed char} type. (Note that there is not an exact
|
289
|
+
equivalent to the C @code{char} type in @code{libffi}; ordinarily you
|
290
|
+
should either use @code{ffi_type_schar} or @code{ffi_type_uchar}
|
291
|
+
depending on whether @code{char} is signed.)
|
292
|
+
|
293
|
+
@item ffi_type_ushort
|
294
|
+
@tindex ffi_type_ushort
|
295
|
+
The C @code{unsigned short} type.
|
296
|
+
|
297
|
+
@item ffi_type_sshort
|
298
|
+
@tindex ffi_type_sshort
|
299
|
+
The C @code{short} type.
|
300
|
+
|
301
|
+
@item ffi_type_uint
|
302
|
+
@tindex ffi_type_uint
|
303
|
+
The C @code{unsigned int} type.
|
304
|
+
|
305
|
+
@item ffi_type_sint
|
306
|
+
@tindex ffi_type_sint
|
307
|
+
The C @code{int} type.
|
308
|
+
|
309
|
+
@item ffi_type_ulong
|
310
|
+
@tindex ffi_type_ulong
|
311
|
+
The C @code{unsigned long} type.
|
312
|
+
|
313
|
+
@item ffi_type_slong
|
314
|
+
@tindex ffi_type_slong
|
315
|
+
The C @code{long} type.
|
316
|
+
|
317
|
+
@item ffi_type_longdouble
|
318
|
+
@tindex ffi_type_longdouble
|
319
|
+
On platforms that have a C @code{long double} type, this is defined.
|
320
|
+
On other platforms, it is not.
|
321
|
+
|
322
|
+
@item ffi_type_pointer
|
323
|
+
@tindex ffi_type_pointer
|
324
|
+
A generic @code{void *} pointer. You should use this for all
|
325
|
+
pointers, regardless of their real type.
|
326
|
+
@end table
|
327
|
+
|
328
|
+
Each of these is of type @code{ffi_type}, so you must take the address
|
329
|
+
when passing to @code{ffi_prep_cif}.
|
330
|
+
|
331
|
+
|
332
|
+
@node Structures
|
333
|
+
@subsection Structures
|
334
|
+
|
335
|
+
Although @samp{libffi} has no special support for unions or
|
336
|
+
bit-fields, it is perfectly happy passing structures back and forth.
|
337
|
+
You must first describe the structure to @samp{libffi} by creating a
|
338
|
+
new @code{ffi_type} object for it.
|
339
|
+
|
340
|
+
@tindex ffi_type
|
341
|
+
@deftp ffi_type
|
342
|
+
The @code{ffi_type} has the following members:
|
343
|
+
@table @code
|
344
|
+
@item size_t size
|
345
|
+
This is set by @code{libffi}; you should initialize it to zero.
|
346
|
+
|
347
|
+
@item unsigned short alignment
|
348
|
+
This is set by @code{libffi}; you should initialize it to zero.
|
349
|
+
|
350
|
+
@item unsigned short type
|
351
|
+
For a structure, this should be set to @code{FFI_TYPE_STRUCT}.
|
352
|
+
|
353
|
+
@item ffi_type **elements
|
354
|
+
This is a @samp{NULL}-terminated array of pointers to @code{ffi_type}
|
355
|
+
objects. There is one element per field of the struct.
|
356
|
+
@end table
|
357
|
+
@end deftp
|
358
|
+
|
359
|
+
|
360
|
+
@node Type Example
|
361
|
+
@subsection Type Example
|
362
|
+
|
363
|
+
The following example initializes a @code{ffi_type} object
|
364
|
+
representing the @code{tm} struct from Linux's @file{time.h}.
|
365
|
+
|
366
|
+
Here is how the struct is defined:
|
367
|
+
|
368
|
+
@example
|
369
|
+
struct tm @{
|
370
|
+
int tm_sec;
|
371
|
+
int tm_min;
|
372
|
+
int tm_hour;
|
373
|
+
int tm_mday;
|
374
|
+
int tm_mon;
|
375
|
+
int tm_year;
|
376
|
+
int tm_wday;
|
377
|
+
int tm_yday;
|
378
|
+
int tm_isdst;
|
379
|
+
/* Those are for future use. */
|
380
|
+
long int __tm_gmtoff__;
|
381
|
+
__const char *__tm_zone__;
|
382
|
+
@};
|
383
|
+
@end example
|
384
|
+
|
385
|
+
Here is the corresponding code to describe this struct to
|
386
|
+
@code{libffi}:
|
387
|
+
|
388
|
+
@example
|
389
|
+
@{
|
390
|
+
ffi_type tm_type;
|
391
|
+
ffi_type *tm_type_elements[12];
|
392
|
+
int i;
|
393
|
+
|
394
|
+
tm_type.size = tm_type.alignment = 0;
|
395
|
+
tm_type.elements = &tm_type_elements;
|
396
|
+
|
397
|
+
for (i = 0; i < 9; i++)
|
398
|
+
tm_type_elements[i] = &ffi_type_sint;
|
399
|
+
|
400
|
+
tm_type_elements[9] = &ffi_type_slong;
|
401
|
+
tm_type_elements[10] = &ffi_type_pointer;
|
402
|
+
tm_type_elements[11] = NULL;
|
403
|
+
|
404
|
+
/* tm_type can now be used to represent tm argument types and
|
405
|
+
return types for ffi_prep_cif() */
|
406
|
+
@}
|
407
|
+
@end example
|
408
|
+
|
409
|
+
|
410
|
+
@node Multiple ABIs
|
411
|
+
@section Multiple ABIs
|
412
|
+
|
413
|
+
A given platform may provide multiple different ABIs at once. For
|
414
|
+
instance, the x86 platform has both @samp{stdcall} and @samp{fastcall}
|
415
|
+
functions.
|
416
|
+
|
417
|
+
@code{libffi} provides some support for this. However, this is
|
418
|
+
necessarily platform-specific.
|
419
|
+
|
420
|
+
@c FIXME: document the platforms
|
421
|
+
|
422
|
+
@node The Closure API
|
423
|
+
@section The Closure API
|
424
|
+
|
425
|
+
@code{libffi} also provides a way to write a generic function -- a
|
426
|
+
function that can accept and decode any combination of arguments.
|
427
|
+
This can be useful when writing an interpreter, or to provide wrappers
|
428
|
+
for arbitrary functions.
|
429
|
+
|
430
|
+
This facility is called the @dfn{closure API}. Closures are not
|
431
|
+
supported on all platforms; you can check the @code{FFI_CLOSURES}
|
432
|
+
define to determine whether they are supported on the current
|
433
|
+
platform.
|
434
|
+
@cindex closures
|
435
|
+
@cindex closure API
|
436
|
+
@findex FFI_CLOSURES
|
437
|
+
|
438
|
+
Because closures work by assembling a tiny function at runtime, they
|
439
|
+
require special allocation on platforms that have a non-executable
|
440
|
+
heap. Memory management for closures is handled by a pair of
|
441
|
+
functions:
|
442
|
+
|
443
|
+
@findex ffi_closure_alloc
|
444
|
+
@defun void *ffi_closure_alloc (size_t @var{size}, void **@var{code})
|
445
|
+
Allocate a chunk of memory holding @var{size} bytes. This returns a
|
446
|
+
pointer to the writable address, and sets *@var{code} to the
|
447
|
+
corresponding executable address.
|
448
|
+
|
449
|
+
@var{size} should be sufficient to hold a @code{ffi_closure} object.
|
450
|
+
@end defun
|
451
|
+
|
452
|
+
@findex ffi_closure_free
|
453
|
+
@defun void ffi_closure_free (void *@var{writable})
|
454
|
+
Free memory allocated using @code{ffi_closure_alloc}. The argument is
|
455
|
+
the writable address that was returned.
|
456
|
+
@end defun
|
457
|
+
|
458
|
+
|
459
|
+
Once you have allocated the memory for a closure, you must construct a
|
460
|
+
@code{ffi_cif} describing the function call. Finally you can prepare
|
461
|
+
the closure function:
|
462
|
+
|
463
|
+
@findex ffi_prep_closure_loc
|
464
|
+
@defun ffi_status ffi_prep_closure_loc (ffi_closure *@var{closure}, ffi_cif *@var{cif}, void (*@var{fun}) (ffi_cif *@var{cif}, void *@var{ret}, void **@var{args}, void *@var{user_data}), void *@var{user_data}, void *@var{codeloc})
|
465
|
+
Prepare a closure function.
|
466
|
+
|
467
|
+
@var{closure} is the address of a @code{ffi_closure} object; this is
|
468
|
+
the writable address returned by @code{ffi_closure_alloc}.
|
469
|
+
|
470
|
+
@var{cif} is the @code{ffi_cif} describing the function parameters.
|
471
|
+
|
472
|
+
@var{user_data} is an arbitrary datum that is passed, uninterpreted,
|
473
|
+
to your closure function.
|
474
|
+
|
475
|
+
@var{codeloc} is the executable address returned by
|
476
|
+
@code{ffi_closure_alloc}.
|
477
|
+
|
478
|
+
@var{fun} is the function which will be called when the closure is
|
479
|
+
invoked. It is called with the arguments:
|
480
|
+
@table @var
|
481
|
+
@item cif
|
482
|
+
The @code{ffi_cif} passed to @code{ffi_prep_closure_loc}.
|
483
|
+
|
484
|
+
@item ret
|
485
|
+
A pointer to the memory used for the function's return value.
|
486
|
+
@var{fun} must fill this, unless the function is declared as returning
|
487
|
+
@code{void}.
|
488
|
+
@c FIXME: is this NULL for void-returning functions?
|
489
|
+
|
490
|
+
@item args
|
491
|
+
A vector of pointers to memory holding the arguments to the function.
|
492
|
+
|
493
|
+
@item user_data
|
494
|
+
The same @var{user_data} that was passed to
|
495
|
+
@code{ffi_prep_closure_loc}.
|
496
|
+
@end table
|
497
|
+
|
498
|
+
@code{ffi_prep_closure_loc} will return @code{FFI_OK} if everything
|
499
|
+
went ok, and something else on error.
|
500
|
+
@c FIXME: what?
|
501
|
+
|
502
|
+
After calling @code{ffi_prep_closure_loc}, you can cast @var{codeloc}
|
503
|
+
to the appropriate pointer-to-function type.
|
504
|
+
@end defun
|
505
|
+
|
506
|
+
You may see old code referring to @code{ffi_prep_closure}. This
|
507
|
+
function is deprecated, as it cannot handle the need for separate
|
508
|
+
writable and executable addresses.
|
509
|
+
|
510
|
+
@node Closure Example
|
511
|
+
@section Closure Example
|
512
|
+
|
513
|
+
A trivial example that creates a new @code{puts} by binding
|
514
|
+
@code{fputs} with @code{stdin}.
|
515
|
+
|
516
|
+
@example
|
517
|
+
#include <stdio.h>
|
518
|
+
#include <ffi.h>
|
519
|
+
|
520
|
+
/* Acts like puts with the file given at time of enclosure. */
|
521
|
+
void puts_binding(ffi_cif *cif, unsigned int *ret, void* args[],
|
522
|
+
FILE *stream)
|
523
|
+
@{
|
524
|
+
*ret = fputs(*(char **)args[0], stream);
|
525
|
+
@}
|
526
|
+
|
527
|
+
int main()
|
528
|
+
@{
|
529
|
+
ffi_cif cif;
|
530
|
+
ffi_type *args[1];
|
531
|
+
ffi_closure *closure;
|
532
|
+
|
533
|
+
int (*bound_puts)(char *);
|
534
|
+
int rc;
|
535
|
+
|
536
|
+
/* Allocate closure and bound_puts */
|
537
|
+
closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);
|
538
|
+
|
539
|
+
if (closure)
|
540
|
+
@{
|
541
|
+
/* Initialize the argument info vectors */
|
542
|
+
args[0] = &ffi_type_pointer;
|
543
|
+
|
544
|
+
/* Initialize the cif */
|
545
|
+
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
|
546
|
+
&ffi_type_uint, args) == FFI_OK)
|
547
|
+
@{
|
548
|
+
/* Initialize the closure, setting stream to stdout */
|
549
|
+
if (ffi_prep_closure_loc(closure, &cif, puts_binding,
|
550
|
+
stdout, bound_puts) == FFI_OK)
|
551
|
+
@{
|
552
|
+
rc = bound_puts("Hello World!");
|
553
|
+
/* rc now holds the result of the call to fputs */
|
554
|
+
@}
|
555
|
+
@}
|
556
|
+
@}
|
557
|
+
|
558
|
+
/* Deallocate both closure, and bound_puts */
|
559
|
+
ffi_closure_free(closure);
|
560
|
+
|
561
|
+
return 0;
|
562
|
+
@}
|
563
|
+
|
564
|
+
@end example
|
565
|
+
|
566
|
+
|
567
|
+
@node Missing Features
|
568
|
+
@chapter Missing Features
|
569
|
+
|
570
|
+
@code{libffi} is missing a few features. We welcome patches to add
|
571
|
+
support for these.
|
572
|
+
|
573
|
+
@itemize @bullet
|
574
|
+
@item
|
575
|
+
There is no support for calling varargs functions. This may work on
|
576
|
+
some platforms, depending on how the ABI is defined, but it is not
|
577
|
+
reliable.
|
578
|
+
|
579
|
+
@item
|
580
|
+
There is no support for bit fields in structures.
|
581
|
+
|
582
|
+
@item
|
583
|
+
The closure API is
|
584
|
+
|
585
|
+
@c FIXME: ...
|
586
|
+
|
587
|
+
@item
|
588
|
+
The ``raw'' API is undocumented.
|
589
|
+
@c argument promotion?
|
590
|
+
@c unions?
|
591
|
+
@c anything else?
|
592
|
+
@end itemize
|
593
|
+
|
594
|
+
|
595
|
+
@node Index
|
596
|
+
@unnumbered Index
|
597
|
+
|
598
|
+
@printindex cp
|
599
|
+
|
600
|
+
@bye
|