ffi 1.9.18 → 1.9.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +22 -0
- data/.gitmodules +3 -0
- data/.travis.yml +52 -0
- data/.yardopts +5 -0
- data/Gemfile +15 -0
- data/{spec/ffi/LICENSE.SPECS → LICENSE.SPECS} +1 -1
- data/README.md +3 -4
- data/Rakefile +41 -5
- data/appveyor.yml +22 -0
- data/ext/ffi_c/AbstractMemory.c +6 -1
- data/ext/ffi_c/Call.c +1 -22
- data/ext/ffi_c/Call.h +0 -9
- data/ext/ffi_c/Closure.c +54 -0
- data/ext/ffi_c/{ClosurePool.h → Closure.h} +13 -23
- data/ext/ffi_c/Function.c +16 -25
- data/ext/ffi_c/Function.h +1 -2
- data/ext/ffi_c/FunctionInfo.c +0 -4
- data/ext/ffi_c/MethodHandle.c +33 -268
- data/ext/ffi_c/Platform.c +10 -2
- data/ext/ffi_c/extconf.rb +10 -5
- data/ext/ffi_c/ffi.c +2 -2
- data/ext/ffi_c/libffi/.appveyor.yml +48 -0
- data/ext/ffi_c/libffi/.gitignore +36 -0
- data/ext/ffi_c/libffi/.travis/install.sh +14 -0
- data/ext/ffi_c/libffi/.travis.yml +30 -0
- data/ext/ffi_c/libffi/ChangeLog.libffi +2 -2
- data/ext/ffi_c/libffi/{ChangeLog → ChangeLog.libffi-3.1} +1402 -2
- data/ext/ffi_c/libffi/ChangeLog.v1 +1 -1
- data/ext/ffi_c/libffi/LICENSE +1 -1
- data/ext/ffi_c/libffi/Makefile.am +169 -158
- data/ext/ffi_c/libffi/Makefile.in +927 -938
- data/ext/ffi_c/libffi/README +164 -52
- data/ext/ffi_c/libffi/acinclude.m4 +387 -0
- data/ext/ffi_c/libffi/autogen.sh +2 -0
- data/ext/ffi_c/libffi/config.guess +336 -371
- data/ext/ffi_c/libffi/config.sub +246 -115
- data/ext/ffi_c/libffi/configure +6976 -2189
- data/ext/ffi_c/libffi/configure.ac +148 -256
- data/ext/ffi_c/libffi/configure.host +277 -4
- data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
- data/ext/ffi_c/libffi/doc/Makefile.in +811 -0
- data/ext/ffi_c/libffi/doc/libffi.texi +430 -45
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/fficonfig.h.in +24 -13
- data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +203 -0
- data/ext/ffi_c/libffi/include/Makefile.am +3 -3
- data/ext/ffi_c/libffi/include/Makefile.in +188 -71
- data/ext/ffi_c/libffi/include/ffi.h.in +112 -50
- data/ext/ffi_c/libffi/include/ffi_cfi.h +55 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +32 -11
- data/ext/ffi_c/libffi/install-sh +190 -202
- data/ext/ffi_c/libffi/libffi.map.in +80 -0
- data/ext/ffi_c/libffi/libffi.pc.in +3 -2
- data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +1043 -0
- data/ext/ffi_c/libffi/libtool-ldflags +106 -0
- data/ext/ffi_c/libffi/libtool-version +1 -1
- data/ext/ffi_c/libffi/ltmain.sh +3553 -2033
- data/ext/ffi_c/libffi/m4/asmcfi.m4 +13 -0
- data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +69 -0
- data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +13 -8
- data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +31 -104
- data/ext/ffi_c/libffi/m4/{ax_check_compiler_flags.m4 → ax_check_compile_flag.m4} +30 -34
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +32 -11
- data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +6 -5
- data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +31 -21
- data/ext/ffi_c/libffi/man/Makefile.am +2 -2
- data/ext/ffi_c/libffi/man/Makefile.in +141 -49
- data/ext/ffi_c/libffi/man/ffi.3 +10 -0
- data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +6 -4
- data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +73 -0
- data/ext/ffi_c/libffi/missing +150 -311
- data/ext/ffi_c/libffi/msvcc.sh +72 -9
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +964 -0
- data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +81 -0
- data/ext/ffi_c/libffi/src/aarch64/internal.h +67 -0
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +438 -0
- data/ext/ffi_c/libffi/src/alpha/ffi.c +335 -98
- data/ext/ffi_c/libffi/src/alpha/ffitarget.h +10 -1
- data/ext/ffi_c/libffi/src/alpha/internal.h +23 -0
- data/ext/ffi_c/libffi/src/alpha/osf.S +161 -266
- data/ext/ffi_c/libffi/src/arc/arcompact.S +135 -0
- data/ext/ffi_c/libffi/src/arc/ffi.c +266 -0
- data/ext/ffi_c/libffi/src/arc/ffitarget.h +53 -0
- data/ext/ffi_c/libffi/src/arm/ffi.c +608 -517
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +24 -7
- data/ext/ffi_c/libffi/src/arm/internal.h +7 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +303 -417
- data/ext/ffi_c/libffi/src/avr32/ffitarget.h +6 -1
- data/ext/ffi_c/libffi/src/bfin/ffi.c +196 -0
- data/ext/ffi_c/libffi/src/bfin/ffitarget.h +43 -0
- data/ext/ffi_c/libffi/src/bfin/sysv.S +179 -0
- data/ext/ffi_c/libffi/src/closures.c +366 -45
- data/ext/ffi_c/libffi/src/cris/ffi.c +10 -7
- data/ext/ffi_c/libffi/src/cris/ffitarget.h +6 -1
- data/ext/ffi_c/libffi/src/debug.c +6 -1
- data/ext/ffi_c/libffi/src/dlmalloc.c +16 -11
- data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/frv/ffitarget.h +6 -1
- data/ext/ffi_c/libffi/src/ia64/ffi.c +11 -7
- data/ext/ffi_c/libffi/src/ia64/ffitarget.h +6 -1
- data/ext/ffi_c/libffi/src/ia64/unix.S +2 -0
- data/ext/ffi_c/libffi/src/java_raw_api.c +23 -5
- data/ext/ffi_c/libffi/src/m32r/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/m32r/ffitarget.h +6 -1
- data/ext/ffi_c/libffi/src/m68k/ffi.c +87 -13
- data/ext/ffi_c/libffi/src/m68k/ffitarget.h +6 -1
- data/ext/ffi_c/libffi/src/m68k/sysv.S +119 -32
- data/ext/ffi_c/libffi/src/m88k/ffi.c +400 -0
- data/ext/ffi_c/libffi/src/m88k/ffitarget.h +49 -0
- data/ext/ffi_c/libffi/src/m88k/obsd.S +209 -0
- data/ext/ffi_c/libffi/src/metag/ffi.c +330 -0
- data/ext/ffi_c/libffi/{fficonfig.hw → src/metag/ffitarget.h} +22 -26
- data/ext/ffi_c/libffi/src/metag/sysv.S +311 -0
- data/ext/ffi_c/libffi/src/microblaze/ffi.c +321 -0
- data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +53 -0
- data/ext/ffi_c/libffi/src/microblaze/sysv.S +302 -0
- data/ext/ffi_c/libffi/src/mips/ffi.c +103 -28
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +10 -3
- data/ext/ffi_c/libffi/src/mips/n32.S +128 -56
- data/ext/ffi_c/libffi/src/mips/o32.S +148 -27
- data/ext/ffi_c/libffi/src/moxie/eabi.S +55 -82
- data/ext/ffi_c/libffi/src/moxie/ffi.c +40 -44
- data/ext/ffi_c/libffi/src/moxie/ffitarget.h +52 -0
- data/ext/ffi_c/libffi/src/nios2/ffi.c +304 -0
- data/ext/ffi_c/libffi/src/nios2/ffitarget.h +52 -0
- data/ext/ffi_c/libffi/src/nios2/sysv.S +136 -0
- data/ext/ffi_c/libffi/src/or1k/ffi.c +328 -0
- data/ext/ffi_c/libffi/src/or1k/ffitarget.h +58 -0
- data/ext/ffi_c/libffi/src/or1k/sysv.S +107 -0
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +8 -1
- data/ext/ffi_c/libffi/src/powerpc/aix.S +245 -7
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +253 -4
- data/ext/ffi_c/libffi/src/powerpc/asm.h +2 -2
- data/ext/ffi_c/libffi/src/powerpc/darwin.S +2 -7
- data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +22 -26
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +103 -1378
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +111 -30
- data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +945 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +94 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +923 -0
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +103 -44
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +100 -59
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +360 -108
- data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +138 -68
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +68 -112
- data/ext/ffi_c/libffi/src/prep_cif.c +108 -24
- data/ext/ffi_c/libffi/src/raw_api.c +18 -5
- data/ext/ffi_c/libffi/src/s390/ffi.c +294 -318
- data/ext/ffi_c/libffi/src/s390/ffitarget.h +9 -1
- data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
- data/ext/ffi_c/libffi/src/s390/sysv.S +257 -366
- data/ext/ffi_c/libffi/src/sh/ffi.c +4 -3
- data/ext/ffi_c/libffi/src/sh/ffitarget.h +6 -1
- data/ext/ffi_c/libffi/src/sh64/ffi.c +3 -2
- data/ext/ffi_c/libffi/src/sh64/ffitarget.h +6 -1
- data/ext/ffi_c/libffi/src/sparc/ffi.c +326 -527
- data/ext/ffi_c/libffi/src/sparc/ffi64.c +608 -0
- data/ext/ffi_c/libffi/src/sparc/ffitarget.h +20 -7
- data/ext/ffi_c/libffi/src/sparc/internal.h +26 -0
- data/ext/ffi_c/libffi/src/sparc/v8.S +364 -234
- data/ext/ffi_c/libffi/src/sparc/v9.S +340 -207
- data/ext/ffi_c/libffi/src/tile/ffi.c +355 -0
- data/ext/ffi_c/libffi/src/tile/ffitarget.h +65 -0
- data/ext/ffi_c/libffi/src/tile/tile.S +360 -0
- data/ext/ffi_c/libffi/src/types.c +43 -14
- data/ext/ffi_c/libffi/src/vax/elfbsd.S +195 -0
- data/ext/ffi_c/libffi/src/vax/ffi.c +276 -0
- data/ext/ffi_c/libffi/src/vax/ffitarget.h +49 -0
- data/ext/ffi_c/libffi/src/x86/asmnames.h +30 -0
- data/ext/ffi_c/libffi/src/x86/ffi.c +591 -500
- data/ext/ffi_c/libffi/src/x86/ffi64.c +359 -116
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +55 -35
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +287 -0
- data/ext/ffi_c/libffi/src/x86/internal.h +29 -0
- data/ext/ffi_c/libffi/src/x86/internal64.h +22 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +975 -400
- data/ext/ffi_c/libffi/src/x86/unix64.S +398 -299
- data/ext/ffi_c/libffi/src/x86/win64.S +222 -458
- data/ext/ffi_c/libffi/src/x86/win64_intel.S +237 -0
- data/ext/ffi_c/libffi/src/xtensa/ffi.c +298 -0
- data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +53 -0
- data/ext/ffi_c/libffi/src/xtensa/sysv.S +253 -0
- data/ext/ffi_c/libffi/stamp-h.in +1 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.am +79 -73
- data/ext/ffi_c/libffi/testsuite/Makefile.in +219 -111
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +121 -25
- data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +21 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +46 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +4 -6
- data/ext/ffi_c/libffi/testsuite/libffi.call/{closure_stdcall.c → closure_simple.c} +7 -16
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +5 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3float.c +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +5 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +4 -6
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +4 -6
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +10 -9
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +3 -3
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +10 -9
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_args.c +70 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_float_double.c +55 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +11 -9
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_struct_va1.c +114 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar_va.c +44 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint_va.c +45 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulong_va.c +45 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +5 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort_va.c +44 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +23 -40
- data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +3 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +6 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +4 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +107 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +18 -19
- data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +6 -16
- data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +57 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +70 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +78 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +0 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +6 -6
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +8 -8
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +6 -6
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct11.c +121 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +5 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +5 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +5 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +5 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +6 -6
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +5 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +6 -6
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +6 -6
- data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +46 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +127 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +7 -7
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +7 -7
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +5 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +5 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +49 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +49 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +55 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +9 -7
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +7 -7
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +7 -6
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +9 -8
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +9 -8
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +9 -9
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +9 -9
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +9 -8
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +9 -8
- data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +61 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.call}/unwindtest.cc +3 -10
- data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.call}/unwindtest_ffi_call.cc +2 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +196 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +121 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +123 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +125 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +71 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +80 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +16 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +10 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.special/special.exp → libffi.complex/complex.exp} +9 -8
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +51 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +7 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +7 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +7 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +78 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +37 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +41 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +44 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +34 -0
- data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +28 -0
- data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +36 -0
- data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +19 -0
- data/ext/ffi_c/libffi.bsd.mk +11 -5
- data/ext/ffi_c/libffi.darwin.mk +14 -4
- data/ext/ffi_c/libffi.gnu.mk +3 -2
- data/ext/ffi_c/libffi.mk +10 -5
- data/ext/ffi_c/libffi.vc.mk +1 -1
- data/ext/ffi_c/libffi.vc64.mk +1 -1
- data/ffi.gemspec +16 -3
- data/lib/ffi/enum.rb +124 -0
- data/lib/ffi/library.rb +66 -14
- data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
- data/lib/ffi/platform/x86_64-windows/types.conf +113 -20
- data/lib/ffi/platform.rb +7 -2
- data/lib/ffi/pointer.rb +1 -0
- data/lib/ffi/struct.rb +0 -2
- data/lib/ffi/version.rb +1 -2
- data/samples/getlogin.rb +8 -0
- data/samples/getpid.rb +8 -0
- data/samples/gettimeofday.rb +18 -0
- data/samples/hello.rb +7 -0
- data/samples/inotify.rb +60 -0
- data/samples/pty.rb +76 -0
- data/samples/qsort.rb +21 -0
- data/samples/sample_helper.rb +6 -0
- metadata +164 -115
- data/ext/ffi_c/ClosurePool.c +0 -283
- data/ext/ffi_c/libffi/Makefile.vc +0 -141
- data/ext/ffi_c/libffi/Makefile.vc64 +0 -141
- data/ext/ffi_c/libffi/aclocal.m4 +0 -1873
- data/ext/ffi_c/libffi/build-ios.sh +0 -67
- data/ext/ffi_c/libffi/compile +0 -143
- data/ext/ffi_c/libffi/depcomp +0 -630
- data/ext/ffi_c/libffi/doc/libffi.info +0 -593
- data/ext/ffi_c/libffi/doc/stamp-vti +0 -4
- data/ext/ffi_c/libffi/include/ffi.h.vc +0 -427
- data/ext/ffi_c/libffi/include/ffi.h.vc64 +0 -427
- data/ext/ffi_c/libffi/m4/libtool.m4 +0 -7831
- data/ext/ffi_c/libffi/m4/ltoptions.m4 +0 -369
- data/ext/ffi_c/libffi/m4/ltsugar.m4 +0 -123
- data/ext/ffi_c/libffi/m4/ltversion.m4 +0 -23
- data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +0 -98
- data/ext/ffi_c/libffi/mdate-sh +0 -201
- data/ext/ffi_c/libffi/src/arm/gentramp.sh +0 -118
- data/ext/ffi_c/libffi/src/arm/trampoline.S +0 -4450
- data/ext/ffi_c/libffi/src/x86/darwin.S +0 -444
- data/ext/ffi_c/libffi/src/x86/darwin64.S +0 -416
- data/ext/ffi_c/libffi/src/x86/freebsd.S +0 -458
- data/ext/ffi_c/libffi/src/x86/win32.S +0 -1065
- data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +0 -300
- data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +0 -63
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +0 -44
- data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +0 -96
- data/ext/ffi_c/libffi/texinfo.tex +0 -7210
- data/gen/Rakefile +0 -30
- data/libtest/Benchmark.c +0 -52
- data/libtest/BoolTest.c +0 -34
- data/libtest/BufferTest.c +0 -31
- data/libtest/ClosureTest.c +0 -205
- data/libtest/EnumTest.c +0 -51
- data/libtest/FunctionTest.c +0 -70
- data/libtest/GNUmakefile +0 -149
- data/libtest/GlobalVariable.c +0 -62
- data/libtest/LastErrorTest.c +0 -21
- data/libtest/NumberTest.c +0 -132
- data/libtest/PointerTest.c +0 -63
- data/libtest/ReferenceTest.c +0 -23
- data/libtest/StringTest.c +0 -34
- data/libtest/StructTest.c +0 -243
- data/libtest/UnionTest.c +0 -43
- data/libtest/VariadicTest.c +0 -99
- data/spec/ffi/async_callback_spec.rb +0 -35
- data/spec/ffi/bool_spec.rb +0 -32
- data/spec/ffi/buffer_spec.rb +0 -279
- data/spec/ffi/callback_spec.rb +0 -773
- data/spec/ffi/custom_param_type.rb +0 -37
- data/spec/ffi/custom_type_spec.rb +0 -74
- data/spec/ffi/dup_spec.rb +0 -52
- data/spec/ffi/enum_spec.rb +0 -423
- data/spec/ffi/errno_spec.rb +0 -20
- data/spec/ffi/ffi_spec.rb +0 -28
- data/spec/ffi/fixtures/Benchmark.c +0 -52
- data/spec/ffi/fixtures/BoolTest.c +0 -34
- data/spec/ffi/fixtures/BufferTest.c +0 -31
- data/spec/ffi/fixtures/ClosureTest.c +0 -205
- data/spec/ffi/fixtures/EnumTest.c +0 -51
- data/spec/ffi/fixtures/FunctionTest.c +0 -142
- data/spec/ffi/fixtures/GNUmakefile +0 -149
- data/spec/ffi/fixtures/GlobalVariable.c +0 -62
- data/spec/ffi/fixtures/LastErrorTest.c +0 -21
- data/spec/ffi/fixtures/NumberTest.c +0 -132
- data/spec/ffi/fixtures/PipeHelper.h +0 -21
- data/spec/ffi/fixtures/PipeHelperPosix.c +0 -41
- data/spec/ffi/fixtures/PipeHelperWindows.c +0 -72
- data/spec/ffi/fixtures/PointerTest.c +0 -63
- data/spec/ffi/fixtures/ReferenceTest.c +0 -23
- data/spec/ffi/fixtures/StringTest.c +0 -34
- data/spec/ffi/fixtures/StructTest.c +0 -243
- data/spec/ffi/fixtures/UnionTest.c +0 -43
- data/spec/ffi/fixtures/VariadicTest.c +0 -99
- data/spec/ffi/fixtures/classes.rb +0 -438
- data/spec/ffi/function_spec.rb +0 -97
- data/spec/ffi/io_spec.rb +0 -16
- data/spec/ffi/library_spec.rb +0 -286
- data/spec/ffi/long_double.rb +0 -30
- data/spec/ffi/managed_struct_spec.rb +0 -68
- data/spec/ffi/memorypointer_spec.rb +0 -78
- data/spec/ffi/number_spec.rb +0 -247
- data/spec/ffi/platform_spec.rb +0 -114
- data/spec/ffi/pointer_spec.rb +0 -285
- data/spec/ffi/rbx/attach_function_spec.rb +0 -34
- data/spec/ffi/rbx/memory_pointer_spec.rb +0 -194
- data/spec/ffi/rbx/spec_helper.rb +0 -6
- data/spec/ffi/rbx/struct_spec.rb +0 -18
- data/spec/ffi/spec_helper.rb +0 -93
- data/spec/ffi/string_spec.rb +0 -118
- data/spec/ffi/strptr_spec.rb +0 -50
- data/spec/ffi/struct_by_ref_spec.rb +0 -43
- data/spec/ffi/struct_callback_spec.rb +0 -69
- data/spec/ffi/struct_initialize_spec.rb +0 -35
- data/spec/ffi/struct_packed_spec.rb +0 -50
- data/spec/ffi/struct_spec.rb +0 -886
- data/spec/ffi/typedef_spec.rb +0 -91
- data/spec/ffi/union_spec.rb +0 -67
- data/spec/ffi/variadic_spec.rb +0 -132
- data/spec/spec.opts +0 -4
data/lib/ffi/library.rb
CHANGED
|
@@ -344,7 +344,7 @@ module FFI
|
|
|
344
344
|
raise FFI::NotFoundError.new(cname, ffi_libraries) if address.nil? || address.null?
|
|
345
345
|
if type.is_a?(Class) && type < FFI::Struct
|
|
346
346
|
# If it is a global struct, just attach directly to the pointer
|
|
347
|
-
s = type.new(address)
|
|
347
|
+
s = s = type.new(address) # Assigning twice to suppress unused variable warning
|
|
348
348
|
self.module_eval <<-code, __FILE__, __LINE__
|
|
349
349
|
@@ffi_gvar_#{mname} = s
|
|
350
350
|
def self.#{mname}
|
|
@@ -447,6 +447,28 @@ module FFI
|
|
|
447
447
|
end
|
|
448
448
|
end
|
|
449
449
|
|
|
450
|
+
private
|
|
451
|
+
# Generic enum builder
|
|
452
|
+
# @param [Class] klass can be one of FFI::Enum or FFI::Bitmask
|
|
453
|
+
# @param args (see #enum or #bitmask)
|
|
454
|
+
def generic_enum(klass, *args)
|
|
455
|
+
native_type = args.first.kind_of?(FFI::Type) ? args.shift : nil
|
|
456
|
+
name, values = if args[0].kind_of?(Symbol) && args[1].kind_of?(Array)
|
|
457
|
+
[ args[0], args[1] ]
|
|
458
|
+
elsif args[0].kind_of?(Array)
|
|
459
|
+
[ nil, args[0] ]
|
|
460
|
+
else
|
|
461
|
+
[ nil, args ]
|
|
462
|
+
end
|
|
463
|
+
@ffi_enums = FFI::Enums.new unless defined?(@ffi_enums)
|
|
464
|
+
@ffi_enums << (e = native_type ? klass.new(native_type, values, name) : klass.new(values, name))
|
|
465
|
+
|
|
466
|
+
# If called with a name, add a typedef alias
|
|
467
|
+
typedef(e, name) if name
|
|
468
|
+
e
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
public
|
|
450
472
|
# @overload enum(name, values)
|
|
451
473
|
# Create a named enum.
|
|
452
474
|
# @example
|
|
@@ -485,20 +507,50 @@ module FFI
|
|
|
485
507
|
# @return [FFI::Enum]
|
|
486
508
|
# Create a new {FFI::Enum}.
|
|
487
509
|
def enum(*args)
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
[ args[0], args[1] ]
|
|
491
|
-
elsif args[0].kind_of?(Array)
|
|
492
|
-
[ nil, args[0] ]
|
|
493
|
-
else
|
|
494
|
-
[ nil, args ]
|
|
495
|
-
end
|
|
496
|
-
@ffi_enums = FFI::Enums.new unless defined?(@ffi_enums)
|
|
497
|
-
@ffi_enums << (e = native_type ? FFI::Enum.new(native_type, values, name) : FFI::Enum.new(values, name))
|
|
510
|
+
generic_enum(FFI::Enum, *args)
|
|
511
|
+
end
|
|
498
512
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
513
|
+
# @overload bitmask(name, values)
|
|
514
|
+
# Create a named bitmask
|
|
515
|
+
# @example
|
|
516
|
+
# bitmask :foo, [:red, :green, :blue] # bits 0,1,2 are used
|
|
517
|
+
# bitmask :foo, [:red, :green, 5, :blue] # bits 0,5,6 are used
|
|
518
|
+
# @param [Symbol] name for new bitmask
|
|
519
|
+
# @param [Array<Symbol, Integer>] values for new bitmask
|
|
520
|
+
# @overload bitmask(*args)
|
|
521
|
+
# Create an unamed bitmask
|
|
522
|
+
# @example
|
|
523
|
+
# bm = bitmask :red, :green, :blue # bits 0,1,2 are used
|
|
524
|
+
# bm = bitmask :red, :green, 5, blue # bits 0,5,6 are used
|
|
525
|
+
# @param [Symbol, Integer] args values for new bitmask
|
|
526
|
+
# @overload bitmask(values)
|
|
527
|
+
# Create an unamed bitmask
|
|
528
|
+
# @example
|
|
529
|
+
# bm = bitmask [:red, :green, :blue] # bits 0,1,2 are used
|
|
530
|
+
# bm = bitmask [:red, :green, 5, blue] # bits 0,5,6 are used
|
|
531
|
+
# @param [Array<Symbol, Integer>] values for new bitmask
|
|
532
|
+
# @overload bitmask(native_type, name, values)
|
|
533
|
+
# Create a named enum and specify the native type.
|
|
534
|
+
# @example
|
|
535
|
+
# bitmask FFI::Type::UINT64, :foo, [:red, :green, :blue]
|
|
536
|
+
# @param [FFI::Type] native_type native type for new bitmask
|
|
537
|
+
# @param [Symbol] name for new bitmask
|
|
538
|
+
# @param [Array<Symbol, Integer>] values for new bitmask
|
|
539
|
+
# @overload bitmask(native_type, *args)
|
|
540
|
+
# @example
|
|
541
|
+
# bitmask FFI::Type::UINT64, :red, :green, :blue
|
|
542
|
+
# @param [FFI::Type] native_type native type for new bitmask
|
|
543
|
+
# @param [Symbol, Integer] args values for new bitmask
|
|
544
|
+
# @overload bitmask(native_type, values)
|
|
545
|
+
# Create a named enum and specify the native type.
|
|
546
|
+
# @example
|
|
547
|
+
# bitmask FFI::Type::UINT64, [:red, :green, :blue]
|
|
548
|
+
# @param [FFI::Type] native_type native type for new bitmask
|
|
549
|
+
# @param [Array<Symbol, Integer>] values for new bitmask
|
|
550
|
+
# @return [FFI::Bitmask]
|
|
551
|
+
# Create a new FFI::Bitmask
|
|
552
|
+
def bitmask(*args)
|
|
553
|
+
generic_enum(FFI::Bitmask, *args)
|
|
502
554
|
end
|
|
503
555
|
|
|
504
556
|
# @param name
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
rbx.platform.typedef.__u_char = uchar
|
|
2
|
+
rbx.platform.typedef.__u_short = ushort
|
|
3
|
+
rbx.platform.typedef.__u_int = uint
|
|
4
|
+
rbx.platform.typedef.__u_long = ulong
|
|
5
|
+
rbx.platform.typedef.__int8_t = char
|
|
6
|
+
rbx.platform.typedef.__uint8_t = uchar
|
|
7
|
+
rbx.platform.typedef.__int16_t = short
|
|
8
|
+
rbx.platform.typedef.__uint16_t = ushort
|
|
9
|
+
rbx.platform.typedef.__int32_t = int
|
|
10
|
+
rbx.platform.typedef.__uint32_t = uint
|
|
11
|
+
rbx.platform.typedef.__int64_t = long
|
|
12
|
+
rbx.platform.typedef.__uint64_t = ulong
|
|
13
|
+
rbx.platform.typedef.__quad_t = long
|
|
14
|
+
rbx.platform.typedef.__u_quad_t = ulong
|
|
15
|
+
rbx.platform.typedef.__dev_t = ulong
|
|
16
|
+
rbx.platform.typedef.__uid_t = uint
|
|
17
|
+
rbx.platform.typedef.__gid_t = uint
|
|
18
|
+
rbx.platform.typedef.__ino_t = ulong
|
|
19
|
+
rbx.platform.typedef.__ino64_t = ulong
|
|
20
|
+
rbx.platform.typedef.__mode_t = uint
|
|
21
|
+
rbx.platform.typedef.__nlink_t = uint
|
|
22
|
+
rbx.platform.typedef.__off_t = long
|
|
23
|
+
rbx.platform.typedef.__off64_t = long
|
|
24
|
+
rbx.platform.typedef.__pid_t = int
|
|
25
|
+
rbx.platform.typedef.__clock_t = long
|
|
26
|
+
rbx.platform.typedef.__rlim_t = ulong
|
|
27
|
+
rbx.platform.typedef.__rlim64_t = ulong
|
|
28
|
+
rbx.platform.typedef.__id_t = uint
|
|
29
|
+
rbx.platform.typedef.__time_t = long
|
|
30
|
+
rbx.platform.typedef.__useconds_t = uint
|
|
31
|
+
rbx.platform.typedef.__suseconds_t = int
|
|
32
|
+
rbx.platform.typedef.__daddr_t = int
|
|
33
|
+
rbx.platform.typedef.__swblk_t = long
|
|
34
|
+
rbx.platform.typedef.__key_t = int
|
|
35
|
+
rbx.platform.typedef.__clockid_t = int
|
|
36
|
+
rbx.platform.typedef.__timer_t = pointer
|
|
37
|
+
rbx.platform.typedef.__blksize_t = long
|
|
38
|
+
rbx.platform.typedef.__blkcnt_t = long
|
|
39
|
+
rbx.platform.typedef.__blkcnt64_t = long
|
|
40
|
+
rbx.platform.typedef.__fsblkcnt_t = ulong
|
|
41
|
+
rbx.platform.typedef.__fsblkcnt64_t = ulong
|
|
42
|
+
rbx.platform.typedef.__fsfilcnt_t = ulong
|
|
43
|
+
rbx.platform.typedef.__fsfilcnt64_t = ulong
|
|
44
|
+
rbx.platform.typedef.__ssize_t = long
|
|
45
|
+
rbx.platform.typedef.__loff_t = long
|
|
46
|
+
rbx.platform.typedef.*__qaddr_t = long
|
|
47
|
+
rbx.platform.typedef.*__caddr_t = char
|
|
48
|
+
rbx.platform.typedef.__intptr_t = long
|
|
49
|
+
rbx.platform.typedef.__socklen_t = uint
|
|
50
|
+
rbx.platform.typedef.u_char = uchar
|
|
51
|
+
rbx.platform.typedef.u_short = ushort
|
|
52
|
+
rbx.platform.typedef.u_int = uint
|
|
53
|
+
rbx.platform.typedef.u_long = ulong
|
|
54
|
+
rbx.platform.typedef.quad_t = long
|
|
55
|
+
rbx.platform.typedef.u_quad_t = ulong
|
|
56
|
+
rbx.platform.typedef.loff_t = long
|
|
57
|
+
rbx.platform.typedef.ino_t = ulong
|
|
58
|
+
rbx.platform.typedef.dev_t = ulong
|
|
59
|
+
rbx.platform.typedef.gid_t = uint
|
|
60
|
+
rbx.platform.typedef.mode_t = uint
|
|
61
|
+
rbx.platform.typedef.nlink_t = uint
|
|
62
|
+
rbx.platform.typedef.uid_t = uint
|
|
63
|
+
rbx.platform.typedef.off_t = long
|
|
64
|
+
rbx.platform.typedef.pid_t = int
|
|
65
|
+
rbx.platform.typedef.id_t = uint
|
|
66
|
+
rbx.platform.typedef.ssize_t = long
|
|
67
|
+
rbx.platform.typedef.daddr_t = int
|
|
68
|
+
rbx.platform.typedef.key_t = int
|
|
69
|
+
rbx.platform.typedef.clock_t = long
|
|
70
|
+
rbx.platform.typedef.time_t = long
|
|
71
|
+
rbx.platform.typedef.clockid_t = int
|
|
72
|
+
rbx.platform.typedef.timer_t = pointer
|
|
73
|
+
rbx.platform.typedef.size_t = ulong
|
|
74
|
+
rbx.platform.typedef.ulong = ulong
|
|
75
|
+
rbx.platform.typedef.ushort = ushort
|
|
76
|
+
rbx.platform.typedef.uint = uint
|
|
77
|
+
rbx.platform.typedef.int8_t = char
|
|
78
|
+
rbx.platform.typedef.int16_t = short
|
|
79
|
+
rbx.platform.typedef.int32_t = int
|
|
80
|
+
rbx.platform.typedef.int64_t = long_long
|
|
81
|
+
rbx.platform.typedef.u_int8_t = uchar
|
|
82
|
+
rbx.platform.typedef.u_int16_t = ushort
|
|
83
|
+
rbx.platform.typedef.u_int32_t = uint
|
|
84
|
+
rbx.platform.typedef.u_int64_t = ulong_long
|
|
85
|
+
rbx.platform.typedef.register_t = long
|
|
86
|
+
rbx.platform.typedef.__sig_atomic_t = int
|
|
87
|
+
rbx.platform.typedef.suseconds_t = int
|
|
88
|
+
rbx.platform.typedef.__fd_mask = long
|
|
89
|
+
rbx.platform.typedef.fd_mask = long
|
|
90
|
+
rbx.platform.typedef.blksize_t = long
|
|
91
|
+
rbx.platform.typedef.blkcnt_t = long
|
|
92
|
+
rbx.platform.typedef.fsblkcnt_t = ulong
|
|
93
|
+
rbx.platform.typedef.fsfilcnt_t = ulong
|
|
94
|
+
rbx.platform.typedef.pthread_t = ulong
|
|
95
|
+
rbx.platform.typedef.pthread_key_t = uint
|
|
96
|
+
rbx.platform.typedef.pthread_once_t = int
|
|
97
|
+
rbx.platform.typedef.socklen_t = uint
|
|
98
|
+
rbx.platform.typedef.sa_family_t = ushort
|
|
99
|
+
rbx.platform.typedef.rlim_t = ulong
|
|
100
|
+
rbx.platform.typedef.__rlimit_resource_t = int
|
|
101
|
+
rbx.platform.typedef.__rusage_who_t = int
|
|
102
|
+
rbx.platform.typedef.__priority_which_t = int
|
|
@@ -1,27 +1,120 @@
|
|
|
1
|
-
rbx.platform.typedef.
|
|
2
|
-
rbx.platform.typedef.
|
|
3
|
-
rbx.platform.typedef.
|
|
4
|
-
rbx.platform.typedef.
|
|
5
|
-
rbx.platform.typedef.
|
|
1
|
+
rbx.platform.typedef.__int8_t = char
|
|
2
|
+
rbx.platform.typedef.__uint8_t = uchar
|
|
3
|
+
rbx.platform.typedef.__int16_t = short
|
|
4
|
+
rbx.platform.typedef.__uint16_t = ushort
|
|
5
|
+
rbx.platform.typedef.__int_least16_t = short
|
|
6
|
+
rbx.platform.typedef.__uint_least16_t = ushort
|
|
7
|
+
rbx.platform.typedef.__int32_t = int
|
|
8
|
+
rbx.platform.typedef.__uint32_t = uint
|
|
9
|
+
rbx.platform.typedef.__int_least32_t = int
|
|
10
|
+
rbx.platform.typedef.__uint_least32_t = uint
|
|
11
|
+
rbx.platform.typedef.__int64_t = long_long
|
|
12
|
+
rbx.platform.typedef.__uint64_t = ulong_long
|
|
13
|
+
rbx.platform.typedef._off_t = long
|
|
14
|
+
rbx.platform.typedef.__dev_t = short
|
|
15
|
+
rbx.platform.typedef.__uid_t = ushort
|
|
16
|
+
rbx.platform.typedef.__gid_t = ushort
|
|
17
|
+
rbx.platform.typedef._off64_t = long_long
|
|
18
|
+
rbx.platform.typedef.fpos_t = long_long
|
|
19
|
+
rbx.platform.typedef._fpos_t = long_long
|
|
20
|
+
rbx.platform.typedef._fpos64_t = long_long
|
|
21
|
+
rbx.platform.typedef._ssize_t = long_long
|
|
6
22
|
rbx.platform.typedef.wchar_t = ushort
|
|
7
|
-
rbx.platform.typedef.wint_t =
|
|
23
|
+
rbx.platform.typedef.wint_t = uint
|
|
8
24
|
rbx.platform.typedef.wctype_t = ushort
|
|
9
|
-
rbx.platform.typedef.
|
|
10
|
-
rbx.platform.typedef.
|
|
11
|
-
rbx.platform.typedef.
|
|
25
|
+
rbx.platform.typedef.ptrdiff_t = long_long
|
|
26
|
+
rbx.platform.typedef.size_t = ulong_long
|
|
27
|
+
rbx.platform.typedef.__off_t = long
|
|
28
|
+
rbx.platform.typedef.__pid_t = int
|
|
29
|
+
rbx.platform.typedef.__loff_t = long_long
|
|
30
|
+
rbx.platform.typedef.u_char = uchar
|
|
31
|
+
rbx.platform.typedef.u_short = ushort
|
|
32
|
+
rbx.platform.typedef.u_int = uint
|
|
33
|
+
rbx.platform.typedef.u_long = ulong
|
|
34
|
+
rbx.platform.typedef.ushort = ushort
|
|
35
|
+
rbx.platform.typedef.uint = uint
|
|
36
|
+
rbx.platform.typedef.ulong = ulong
|
|
37
|
+
rbx.platform.typedef.clock_t = ulong
|
|
12
38
|
rbx.platform.typedef.time_t = long_long
|
|
13
|
-
rbx.platform.typedef.
|
|
14
|
-
rbx.platform.typedef.
|
|
39
|
+
rbx.platform.typedef.daddr_t = long
|
|
40
|
+
rbx.platform.typedef.caddr_t = string
|
|
41
|
+
rbx.platform.typedef.pid_t = int
|
|
42
|
+
rbx.platform.typedef.ssize_t = int
|
|
43
|
+
rbx.platform.typedef.nlink_t = ushort
|
|
44
|
+
rbx.platform.typedef.fd_mask = long
|
|
45
|
+
rbx.platform.typedef.clockid_t = ulong
|
|
46
|
+
rbx.platform.typedef.timer_t = ulong
|
|
47
|
+
rbx.platform.typedef.useconds_t = ulong
|
|
48
|
+
rbx.platform.typedef.suseconds_t = long
|
|
49
|
+
rbx.platform.typedef.int8_t = char
|
|
50
|
+
rbx.platform.typedef.int16_t = short
|
|
51
|
+
rbx.platform.typedef.int32_t = int
|
|
52
|
+
rbx.platform.typedef.int64_t = long_long
|
|
53
|
+
rbx.platform.typedef.uint8_t = uchar
|
|
54
|
+
rbx.platform.typedef.uint16_t = ushort
|
|
55
|
+
rbx.platform.typedef.uint32_t = uint
|
|
56
|
+
rbx.platform.typedef.uint64_t = ulong_long
|
|
57
|
+
rbx.platform.typedef.int_least8_t = char
|
|
58
|
+
rbx.platform.typedef.int_least16_t = short
|
|
59
|
+
rbx.platform.typedef.int_least32_t = int
|
|
60
|
+
rbx.platform.typedef.int_least64_t = long_long
|
|
61
|
+
rbx.platform.typedef.uint_least8_t = uchar
|
|
62
|
+
rbx.platform.typedef.uint_least16_t = ushort
|
|
63
|
+
rbx.platform.typedef.uint_least32_t = uint
|
|
64
|
+
rbx.platform.typedef.uint_least64_t = ulong_long
|
|
65
|
+
rbx.platform.typedef.int_fast8_t = char
|
|
66
|
+
rbx.platform.typedef.int_fast16_t = int
|
|
67
|
+
rbx.platform.typedef.int_fast32_t = int
|
|
68
|
+
rbx.platform.typedef.int_fast64_t = long_long
|
|
69
|
+
rbx.platform.typedef.uint_fast8_t = uchar
|
|
70
|
+
rbx.platform.typedef.uint_fast16_t = uint
|
|
71
|
+
rbx.platform.typedef.uint_fast32_t = uint
|
|
72
|
+
rbx.platform.typedef.uint_fast64_t = ulong_long
|
|
73
|
+
rbx.platform.typedef.intptr_t = long_long
|
|
74
|
+
rbx.platform.typedef.uintptr_t = ulong_long
|
|
75
|
+
rbx.platform.typedef.intmax_t = long_long
|
|
76
|
+
rbx.platform.typedef.uintmax_t = ulong_long
|
|
77
|
+
rbx.platform.typedef.off_t = long_long
|
|
78
|
+
rbx.platform.typedef.loff_t = long_long
|
|
79
|
+
rbx.platform.typedef.__dev16_t = short
|
|
80
|
+
rbx.platform.typedef.__dev32_t = ulong
|
|
15
81
|
rbx.platform.typedef._dev_t = uint
|
|
16
82
|
rbx.platform.typedef.dev_t = uint
|
|
17
|
-
rbx.platform.typedef.
|
|
18
|
-
rbx.platform.typedef.
|
|
83
|
+
rbx.platform.typedef.blksize_t = long
|
|
84
|
+
rbx.platform.typedef.__blkcnt32_t = long
|
|
85
|
+
rbx.platform.typedef.__blkcnt64_t = long_long
|
|
86
|
+
rbx.platform.typedef.blkcnt_t = long_long
|
|
87
|
+
rbx.platform.typedef.fsblkcnt_t = ulong
|
|
88
|
+
rbx.platform.typedef.fsfilcnt_t = ulong
|
|
89
|
+
rbx.platform.typedef.__uid16_t = ushort
|
|
90
|
+
rbx.platform.typedef.__uid32_t = ulong
|
|
91
|
+
rbx.platform.typedef.uid_t = ulong
|
|
92
|
+
rbx.platform.typedef.__gid16_t = ushort
|
|
93
|
+
rbx.platform.typedef.__gid32_t = ulong
|
|
94
|
+
rbx.platform.typedef.gid_t = ulong
|
|
95
|
+
rbx.platform.typedef.__ino32_t = ulong
|
|
96
|
+
rbx.platform.typedef.__ino64_t = ulong_long
|
|
97
|
+
rbx.platform.typedef.ino_t = ushort
|
|
98
|
+
rbx.platform.typedef._ino_t = ushort
|
|
99
|
+
rbx.platform.typedef.id_t = ulong
|
|
100
|
+
rbx.platform.typedef.key_t = long_long
|
|
101
|
+
rbx.platform.typedef.vm_offset_t = ulong
|
|
102
|
+
rbx.platform.typedef.vm_size_t = ulong
|
|
103
|
+
rbx.platform.typedef.u_int8_t = uchar
|
|
104
|
+
rbx.platform.typedef.u_int16_t = ushort
|
|
105
|
+
rbx.platform.typedef.u_int32_t = uint
|
|
106
|
+
rbx.platform.typedef.u_int64_t = ulong_long
|
|
107
|
+
rbx.platform.typedef.register_t = int
|
|
108
|
+
rbx.platform.typedef.*addr_t = char
|
|
109
|
+
rbx.platform.typedef.socklen_t = int
|
|
110
|
+
rbx.platform.typedef.sa_family_t = ushort
|
|
111
|
+
rbx.platform.typedef.__ULong = ulong
|
|
112
|
+
rbx.platform.typedef.sigset_t = ulong
|
|
113
|
+
rbx.platform.typedef.sig_atomic_t = int
|
|
114
|
+
rbx.platform.typedef.rlim_t = ulong
|
|
115
|
+
rbx.platform.typedef._sigset_t = ulong_long
|
|
116
|
+
rbx.platform.typedef.__time32_t = long
|
|
117
|
+
rbx.platform.typedef.__time64_t = long_long
|
|
118
|
+
rbx.platform.typedef.errno_t = int
|
|
19
119
|
rbx.platform.typedef._mode_t = ushort
|
|
20
120
|
rbx.platform.typedef.mode_t = ushort
|
|
21
|
-
rbx.platform.typedef._off_t = long
|
|
22
|
-
rbx.platform.typedef.off32_t = long
|
|
23
|
-
rbx.platform.typedef._off64_t = long_long
|
|
24
|
-
rbx.platform.typedef.off64_t = long_long
|
|
25
|
-
rbx.platform.typedef.off_t = long_long
|
|
26
|
-
rbx.platform.typedef.useconds_t = uint
|
|
27
|
-
rbx.platform.typedef._sigset_t = ulong_long
|
data/lib/ffi/platform.rb
CHANGED
|
@@ -63,6 +63,8 @@ module FFI
|
|
|
63
63
|
"powerpc64"
|
|
64
64
|
when /ppc|powerpc/
|
|
65
65
|
"powerpc"
|
|
66
|
+
when /sparcv9|sparc64/
|
|
67
|
+
"sparcv9"
|
|
66
68
|
else
|
|
67
69
|
case RbConfig::CONFIG['host_cpu']
|
|
68
70
|
when /^arm/
|
|
@@ -95,7 +97,7 @@ module FFI
|
|
|
95
97
|
public
|
|
96
98
|
|
|
97
99
|
LIBPREFIX = case OS
|
|
98
|
-
when /windows/
|
|
100
|
+
when /windows|msys/
|
|
99
101
|
''
|
|
100
102
|
when /cygwin/
|
|
101
103
|
'cyg'
|
|
@@ -108,7 +110,7 @@ module FFI
|
|
|
108
110
|
'dylib'
|
|
109
111
|
when /linux|bsd|solaris/
|
|
110
112
|
'so'
|
|
111
|
-
when /windows|cygwin/
|
|
113
|
+
when /windows|cygwin|msys/
|
|
112
114
|
'dll'
|
|
113
115
|
else
|
|
114
116
|
# Punt and just assume a sane unix (i.e. anything but AIX)
|
|
@@ -121,6 +123,9 @@ module FFI
|
|
|
121
123
|
GNU_LIBC
|
|
122
124
|
elsif OS == 'cygwin'
|
|
123
125
|
"cygwin1.dll"
|
|
126
|
+
elsif OS == 'msys'
|
|
127
|
+
# Not sure how msys 1.0 behaves, tested on MSYS2.
|
|
128
|
+
"msys-2.0.dll"
|
|
124
129
|
else
|
|
125
130
|
"#{LIBPREFIX}c.#{LIBSUFFIX}"
|
|
126
131
|
end
|
data/lib/ffi/pointer.rb
CHANGED
data/lib/ffi/struct.rb
CHANGED
|
@@ -338,10 +338,8 @@ module FFI
|
|
|
338
338
|
# @param [StructLayoutBuilder] builder
|
|
339
339
|
# @param [Hash] spec
|
|
340
340
|
# @return [builder]
|
|
341
|
-
# @raise if Ruby 1.8
|
|
342
341
|
# Add hash +spec+ to +builder+.
|
|
343
342
|
def hash_layout(builder, spec)
|
|
344
|
-
raise "Ruby version not supported" if RUBY_VERSION =~ /^1\.8\..*/
|
|
345
343
|
spec[0].each do |name, type|
|
|
346
344
|
builder.add name, find_field_type(type), nil
|
|
347
345
|
end
|
data/lib/ffi/version.rb
CHANGED
data/samples/getlogin.rb
ADDED
data/samples/getpid.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'ffi'
|
|
3
|
+
class Timeval < FFI::Struct
|
|
4
|
+
rb_maj, rb_min, rb_micro = RUBY_VERSION.split('.')
|
|
5
|
+
if rb_maj.to_i >= 1 && rb_min.to_i >= 9 || RUBY_PLATFORM =~ /java/
|
|
6
|
+
layout :tv_sec => :ulong, :tv_usec => :ulong
|
|
7
|
+
else
|
|
8
|
+
layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
module LibC
|
|
12
|
+
extend FFI::Library
|
|
13
|
+
ffi_lib FFI::Library::LIBC
|
|
14
|
+
attach_function :gettimeofday, [ :pointer, :pointer ], :int
|
|
15
|
+
end
|
|
16
|
+
t = Timeval.new
|
|
17
|
+
LibC.gettimeofday(t.pointer, nil)
|
|
18
|
+
puts "t.tv_sec=#{t[:tv_sec]} t.tv_usec=#{t[:tv_usec]}"
|
data/samples/hello.rb
ADDED
data/samples/inotify.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'ffi'
|
|
3
|
+
module Inotify
|
|
4
|
+
extend FFI::Library
|
|
5
|
+
ffi_lib FFI::Library::LIBC
|
|
6
|
+
class Event < FFI::Struct
|
|
7
|
+
layout \
|
|
8
|
+
:wd, :int,
|
|
9
|
+
:mask, :uint,
|
|
10
|
+
:cookie, :uint,
|
|
11
|
+
:len, :uint
|
|
12
|
+
end
|
|
13
|
+
attach_function :init, :inotify_init, [ ], :int
|
|
14
|
+
attach_function :add_watch, :inotify_add_watch, [ :int, :string, :uint ], :int
|
|
15
|
+
attach_function :rm_watch, :inotify_rm_watch, [ :int, :uint ], :int
|
|
16
|
+
attach_function :read, [ :int, :buffer_out, :uint ], :int
|
|
17
|
+
IN_ACCESS=0x00000001
|
|
18
|
+
IN_MODIFY=0x00000002
|
|
19
|
+
IN_ATTRIB=0x00000004
|
|
20
|
+
IN_CLOSE_WRITE=0x00000008
|
|
21
|
+
IN_CLOSE_NOWRITE=0x00000010
|
|
22
|
+
IN_CLOSE=(IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)
|
|
23
|
+
IN_OPEN=0x00000020
|
|
24
|
+
IN_MOVED_FROM=0x00000040
|
|
25
|
+
IN_MOVED_TO=0x00000080
|
|
26
|
+
IN_MOVE= (IN_MOVED_FROM | IN_MOVED_TO)
|
|
27
|
+
IN_CREATE=0x00000100
|
|
28
|
+
IN_DELETE=0x00000200
|
|
29
|
+
IN_DELETE_SELF=0x00000400
|
|
30
|
+
IN_MOVE_SELF=0x00000800
|
|
31
|
+
# Events sent by the kernel.
|
|
32
|
+
IN_UNMOUNT=0x00002000
|
|
33
|
+
IN_Q_OVERFLOW=0x00004000
|
|
34
|
+
IN_IGNORED=0x00008000
|
|
35
|
+
IN_ONLYDIR=0x01000000
|
|
36
|
+
IN_DONT_FOLLOW=0x02000000
|
|
37
|
+
IN_MASK_ADD=0x20000000
|
|
38
|
+
IN_ISDIR=0x40000000
|
|
39
|
+
IN_ONESHOT=0x80000000
|
|
40
|
+
IN_ALL_EVENTS=(IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE \
|
|
41
|
+
| IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM \
|
|
42
|
+
| IN_MOVED_TO | IN_CREATE | IN_DELETE \
|
|
43
|
+
| IN_DELETE_SELF | IN_MOVE_SELF)
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
if $0 == __FILE__
|
|
47
|
+
fd = Inotify.init
|
|
48
|
+
puts "fd=#{fd}"
|
|
49
|
+
wd = Inotify.add_watch(fd, "/tmp/", Inotify::IN_ALL_EVENTS)
|
|
50
|
+
fp = FFI::IO.for_fd(fd)
|
|
51
|
+
puts "wfp=#{fp}"
|
|
52
|
+
while true
|
|
53
|
+
buf = FFI::Buffer.alloc_out(Inotify::Event.size + 4096, 1, false)
|
|
54
|
+
ev = Inotify::Event.new buf
|
|
55
|
+
ready = IO.select([ fp ], nil, nil, nil)
|
|
56
|
+
n = Inotify.read(fd, buf, buf.total)
|
|
57
|
+
puts "Read #{n} bytes from inotify fd"
|
|
58
|
+
puts "event.wd=#{ev[:wd]} mask=#{ev[:mask]} len=#{ev[:len]} name=#{ev[:len] > 0 ? buf.get_string(16) : 'unknown'}"
|
|
59
|
+
end
|
|
60
|
+
end
|
data/samples/pty.rb
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'ffi'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module PTY
|
|
5
|
+
private
|
|
6
|
+
module LibC
|
|
7
|
+
extend FFI::Library
|
|
8
|
+
ffi_lib FFI::Library::LIBC
|
|
9
|
+
attach_function :forkpty, [ :buffer_out, :buffer_out, :buffer_in, :buffer_in ], :int
|
|
10
|
+
attach_function :openpty, [ :buffer_out, :buffer_out, :buffer_out, :buffer_in, :buffer_in ], :int
|
|
11
|
+
attach_function :login_tty, [ :int ], :int
|
|
12
|
+
attach_function :close, [ :int ], :int
|
|
13
|
+
attach_function :strerror, [ :int ], :string
|
|
14
|
+
attach_function :fork, [], :int
|
|
15
|
+
attach_function :execv, [ :string, :buffer_in ], :int
|
|
16
|
+
attach_function :execvp, [ :string, :buffer_in ], :int
|
|
17
|
+
attach_function :dup2, [ :int, :int ], :int
|
|
18
|
+
attach_function :dup, [ :int ], :int
|
|
19
|
+
end
|
|
20
|
+
Buffer = FFI::Buffer
|
|
21
|
+
def self.build_args(args)
|
|
22
|
+
cmd = args.shift
|
|
23
|
+
cmd_args = args.map do |arg|
|
|
24
|
+
MemoryPointer.from_string(arg)
|
|
25
|
+
end
|
|
26
|
+
exec_args = MemoryPointer.new(:pointer, 1 + cmd_args.length + 1)
|
|
27
|
+
exec_cmd = MemoryPointer.from_string(cmd)
|
|
28
|
+
exec_args[0].put_pointer(0, exec_cmd)
|
|
29
|
+
cmd_args.each_with_index do |arg, i|
|
|
30
|
+
exec_args[i + 1].put_pointer(0, arg)
|
|
31
|
+
end
|
|
32
|
+
[ cmd, exec_args ]
|
|
33
|
+
end
|
|
34
|
+
public
|
|
35
|
+
def self.getpty(*args)
|
|
36
|
+
mfdp = Buffer.new :int
|
|
37
|
+
name = Buffer.new 1024
|
|
38
|
+
#
|
|
39
|
+
# All the execv setup is done in the parent, since doing anything other than
|
|
40
|
+
# execv in the child after fork is really flakey
|
|
41
|
+
#
|
|
42
|
+
exec_cmd, exec_args = build_args(args)
|
|
43
|
+
pid = LibC.forkpty(mfdp, name, nil, nil)
|
|
44
|
+
raise "forkpty failed: #{LibC.strerror(FFI.errno)}" if pid < 0
|
|
45
|
+
if pid == 0
|
|
46
|
+
LibC.execvp(exec_cmd, exec_args)
|
|
47
|
+
exit 1
|
|
48
|
+
end
|
|
49
|
+
masterfd = mfdp.get_int(0)
|
|
50
|
+
rfp = FFI::IO.for_fd(masterfd, "r")
|
|
51
|
+
wfp = FFI::IO.for_fd(LibC.dup(masterfd), "w")
|
|
52
|
+
if block_given?
|
|
53
|
+
yield rfp, wfp, pid
|
|
54
|
+
rfp.close unless rfp.closed?
|
|
55
|
+
wfp.close unless wfp.closed?
|
|
56
|
+
else
|
|
57
|
+
[ rfp, wfp, pid ]
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
def self.spawn(*args, &block)
|
|
61
|
+
self.getpty("/bin/sh", "-c", args[0], &block)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
module LibC
|
|
65
|
+
extend FFI::Library
|
|
66
|
+
attach_function :close, [ :int ], :int
|
|
67
|
+
attach_function :write, [ :int, :buffer_in, :ulong ], :long
|
|
68
|
+
attach_function :read, [ :int, :buffer_out, :ulong ], :long
|
|
69
|
+
end
|
|
70
|
+
PTY.getpty("/bin/ls", "-alR", "/") { |rfd, wfd, pid|
|
|
71
|
+
#PTY.spawn("ls -laR /") { |rfd, wfd, pid|
|
|
72
|
+
puts "child pid=#{pid}"
|
|
73
|
+
while !rfd.eof? && (buf = rfd.gets)
|
|
74
|
+
puts "child: '#{buf.strip}'"
|
|
75
|
+
end
|
|
76
|
+
}
|
data/samples/qsort.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'ffi'
|
|
3
|
+
|
|
4
|
+
module LibC
|
|
5
|
+
extend FFI::Library
|
|
6
|
+
ffi_lib FFI::Library::LIBC
|
|
7
|
+
callback :qsort_cmp, [ :pointer, :pointer ], :int
|
|
8
|
+
attach_function :qsort, [ :pointer, :ulong, :ulong, :qsort_cmp ], :int
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
p = FFI::MemoryPointer.new(:int, 2)
|
|
12
|
+
p.put_array_of_int32(0, [ 2, 1 ])
|
|
13
|
+
puts "ptr=#{p.inspect}"
|
|
14
|
+
puts "Before qsort #{p.get_array_of_int32(0, 2).join(', ')}"
|
|
15
|
+
LibC.qsort(p, 2, 4) do |p1, p2|
|
|
16
|
+
i1 = p1.get_int32(0)
|
|
17
|
+
i2 = p2.get_int32(0)
|
|
18
|
+
puts "In block: comparing #{i1} and #{i2}"
|
|
19
|
+
i1 < i2 ? -1 : i1 > i2 ? 1 : 0
|
|
20
|
+
end
|
|
21
|
+
puts "After qsort #{p.get_array_of_int32(0, 2).join(', ')}"
|