ffi 1.9.25 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +212 -0
- data/Gemfile +3 -4
- data/README.md +38 -18
- data/Rakefile +55 -146
- data/ext/ffi_c/AbstractMemory.c +29 -34
- data/ext/ffi_c/Buffer.c +4 -9
- data/ext/ffi_c/Call.c +16 -49
- data/ext/ffi_c/Call.h +4 -7
- data/ext/ffi_c/ClosurePool.c +75 -25
- data/ext/ffi_c/ClosurePool.h +3 -1
- data/ext/ffi_c/DynamicLibrary.c +2 -7
- data/ext/ffi_c/Function.c +47 -131
- data/ext/ffi_c/Function.h +0 -4
- data/ext/ffi_c/FunctionInfo.c +3 -8
- data/ext/ffi_c/LastError.c +49 -8
- data/ext/ffi_c/LongDouble.c +12 -10
- data/ext/ffi_c/LongDouble.h +0 -4
- data/ext/ffi_c/MemoryPointer.c +3 -8
- data/ext/ffi_c/MemoryPointer.h +0 -4
- data/ext/ffi_c/MethodHandle.c +21 -31
- data/ext/ffi_c/MethodHandle.h +3 -2
- data/ext/ffi_c/Platform.c +3 -54
- data/ext/ffi_c/Pointer.c +25 -26
- data/ext/ffi_c/Pointer.h +0 -4
- data/ext/ffi_c/Struct.c +49 -56
- data/ext/ffi_c/Struct.h +12 -6
- data/ext/ffi_c/StructByValue.c +2 -7
- data/ext/ffi_c/StructLayout.c +22 -20
- data/ext/ffi_c/Thread.c +4 -228
- data/ext/ffi_c/Thread.h +1 -20
- data/ext/ffi_c/Type.c +1 -19
- data/ext/ffi_c/Type.h +0 -1
- data/ext/ffi_c/Types.c +7 -8
- data/ext/ffi_c/Types.h +3 -4
- data/ext/ffi_c/Variadic.c +23 -24
- data/ext/ffi_c/compat.h +4 -0
- data/ext/ffi_c/extconf.rb +53 -30
- data/ext/ffi_c/ffi.c +3 -8
- data/ext/ffi_c/libffi.darwin.mk +1 -1
- data/ext/ffi_c/libffi/.appveyor.yml +29 -13
- data/ext/ffi_c/libffi/.gitattributes +4 -0
- data/ext/ffi_c/libffi/.travis.yml +51 -2
- data/ext/ffi_c/libffi/.travis/bfin-sim.exp +58 -0
- data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +14 -0
- data/ext/ffi_c/libffi/.travis/build-in-container.sh +12 -0
- data/ext/ffi_c/libffi/.travis/build.sh +116 -8
- data/ext/ffi_c/libffi/.travis/install.sh +65 -16
- data/ext/ffi_c/libffi/.travis/m32r-sim.exp +58 -0
- data/ext/ffi_c/libffi/.travis/moxie-sim.exp +1 -1
- data/ext/ffi_c/libffi/.travis/or1k-sim.exp +58 -0
- data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +58 -0
- data/ext/ffi_c/libffi/.travis/site.exp +10 -1
- data/ext/ffi_c/libffi/.travis/wine-sim.exp +55 -0
- data/ext/ffi_c/libffi/{ChangeLog.libffi-3.1 → ChangeLog.old} +1407 -0
- data/ext/ffi_c/libffi/LICENSE +1 -1
- data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +5 -4
- data/ext/ffi_c/libffi/Makefile.am +56 -72
- data/ext/ffi_c/libffi/README.md +33 -8
- data/ext/ffi_c/libffi/config.guess +552 -331
- data/ext/ffi_c/libffi/config.sub +1321 -1306
- data/ext/ffi_c/libffi/configure.ac +37 -12
- data/ext/ffi_c/libffi/configure.host +56 -27
- data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
- data/ext/ffi_c/libffi/doc/libffi.texi +997 -0
- data/ext/ffi_c/libffi/doc/version.texi +4 -0
- data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +2 -4
- data/ext/ffi_c/libffi/include/ffi.h.in +19 -7
- data/ext/ffi_c/libffi/include/ffi_common.h +5 -1
- data/ext/ffi_c/libffi/libffi.map.in +8 -12
- data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +2 -48
- data/ext/ffi_c/libffi/libtool-version +1 -1
- data/ext/ffi_c/libffi/m4/asmcfi.m4 +1 -1
- data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +5 -26
- data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +5 -26
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +2 -1
- data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +5 -26
- data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +7 -3
- data/ext/ffi_c/libffi/make_sunver.pl +333 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.sln +33 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj +130 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.filters +57 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user +4 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +511 -0
- data/ext/ffi_c/libffi/msvcc.sh +38 -13
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +153 -69
- data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +19 -3
- data/ext/ffi_c/libffi/src/aarch64/internal.h +1 -0
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +22 -9
- data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
- data/ext/ffi_c/libffi/src/arm/ffi.c +62 -5
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +8 -1
- data/ext/ffi_c/libffi/src/arm/sysv.S +6 -4
- data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
- data/ext/ffi_c/libffi/src/closures.c +69 -14
- data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
- data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
- data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
- data/ext/ffi_c/libffi/src/dlmalloc.c +1 -1
- data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
- data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
- data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
- data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
- data/ext/ffi_c/libffi/src/metag/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/mips/ffi.c +5 -1
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
- data/ext/ffi_c/libffi/src/mips/o32.S +2 -0
- data/ext/ffi_c/libffi/src/moxie/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +1 -6
- data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
- data/ext/ffi_c/libffi/src/pa/linux.S +27 -4
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +6 -4
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +13 -1
- data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +211 -32
- data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +18 -7
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +10 -4
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +91 -28
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +81 -5
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
- data/ext/ffi_c/libffi/src/prep_cif.c +4 -2
- data/ext/ffi_c/libffi/src/riscv/ffi.c +42 -6
- data/ext/ffi_c/libffi/src/riscv/ffitarget.h +1 -0
- data/ext/ffi_c/libffi/src/riscv/sysv.S +86 -7
- data/ext/ffi_c/libffi/src/x86/ffi.c +29 -12
- data/ext/ffi_c/libffi/src/x86/ffi64.c +22 -11
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +20 -10
- data/ext/ffi_c/libffi/src/x86/sysv.S +105 -10
- data/ext/ffi_c/libffi/src/x86/sysv_intel.S +995 -0
- data/ext/ffi_c/libffi/src/x86/unix64.S +100 -4
- data/ext/ffi_c/libffi/src/x86/win64.S +12 -3
- data/ext/ffi_c/libffi/src/x86/win64_intel.S +3 -2
- data/ext/ffi_c/libffi/testsuite/Makefile.am +114 -109
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +32 -8
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +7 -2
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +12 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +9 -8
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure.exp +67 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn0.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn1.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn2.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn3.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn4.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn5.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn6.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_loc_fn0.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_simple.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_12byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_16byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_18byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_19byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_1_1byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte1.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_24byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_2byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3_1byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte1.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte2.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3float.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4_1byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5_1_byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_64byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6_1_byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7_1_byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_8byte.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte1.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte2.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_double.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_float.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split2.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_pointer.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint16.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint32.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint64.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint16.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint32.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint64.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_dbls_struct.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double_va.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_float.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble_va.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_args.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_float_double.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_schar.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshort.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshortchar.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_uchar.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushort.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushortchar.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer_stack.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_schar.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sint.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sshort.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_struct_va1.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar_va.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint_va.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulong_va.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulonglong.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort_va.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/err_bad_abi.c +0 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +138 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/huge_struct.c +3 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct1.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct10.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct11.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct2.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct3.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct4.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct5.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct6.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct7.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct8.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct9.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/problem1.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large2.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium2.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/testclosure.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest.cc +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest_ffi_call.cc +0 -0
- data/ext/ffi_c/rbffi.h +0 -2
- data/ffi.gemspec +13 -6
- data/lib/ffi.rb +10 -2
- data/lib/ffi/abstract_memory.rb +44 -0
- data/lib/ffi/autopointer.rb +1 -1
- data/lib/ffi/data_converter.rb +67 -0
- data/lib/ffi/ffi.rb +3 -0
- data/lib/ffi/io.rb +3 -3
- data/lib/ffi/library.rb +12 -8
- data/lib/ffi/managedstruct.rb +2 -2
- data/lib/ffi/platform.rb +34 -10
- data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
- data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
- data/lib/ffi/platform/aarch64-freebsd12/types.conf +128 -0
- data/lib/ffi/platform/aarch64-linux/types.conf +81 -81
- data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
- data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
- data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
- data/lib/ffi/platform/arm-linux/types.conf +110 -82
- data/lib/ffi/platform/i386-cygwin/types.conf +1 -1
- data/lib/ffi/platform/i386-darwin/types.conf +63 -63
- data/lib/ffi/platform/i386-freebsd/types.conf +89 -89
- data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
- data/lib/ffi/platform/i386-gnu/types.conf +84 -84
- data/lib/ffi/platform/i386-linux/types.conf +77 -77
- data/lib/ffi/platform/i386-netbsd/types.conf +87 -87
- data/lib/ffi/platform/i386-openbsd/types.conf +89 -89
- data/lib/ffi/platform/i386-solaris/types.conf +96 -96
- data/lib/ffi/platform/i386-windows/types.conf +43 -96
- data/lib/ffi/platform/ia64-linux/types.conf +79 -79
- data/lib/ffi/platform/mips-linux/types.conf +79 -79
- data/lib/ffi/platform/mips64-linux/types.conf +81 -81
- data/lib/ffi/platform/mips64el-linux/types.conf +81 -81
- data/lib/ffi/platform/mipsel-linux/types.conf +79 -79
- data/lib/ffi/platform/mipsisa32r6-linux/types.conf +79 -79
- data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +79 -79
- data/lib/ffi/platform/mipsisa64r6-linux/types.conf +81 -81
- data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +81 -81
- data/lib/ffi/platform/powerpc-aix/types.conf +155 -155
- data/lib/ffi/platform/powerpc-darwin/types.conf +63 -63
- data/lib/ffi/platform/powerpc-linux/types.conf +108 -78
- data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
- data/lib/ffi/platform/powerpc64-linux/types.conf +81 -81
- data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
- data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
- data/lib/ffi/platform/s390-linux/types.conf +79 -79
- data/lib/ffi/platform/s390x-linux/types.conf +79 -79
- data/lib/ffi/platform/sparc-linux/types.conf +79 -79
- data/lib/ffi/platform/sparc-solaris/types.conf +103 -103
- data/lib/ffi/platform/sparc64-linux/types.conf +79 -79
- data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
- data/lib/ffi/platform/sparcv9-solaris/types.conf +103 -103
- data/lib/ffi/platform/x86_64-cygwin/types.conf +1 -1
- data/lib/ffi/platform/x86_64-darwin/types.conf +88 -84
- data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
- data/lib/ffi/platform/x86_64-freebsd/types.conf +90 -90
- data/lib/ffi/platform/x86_64-freebsd12/types.conf +158 -0
- data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
- data/lib/ffi/platform/x86_64-linux/types.conf +107 -77
- data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
- data/lib/ffi/platform/x86_64-netbsd/types.conf +89 -89
- data/lib/ffi/platform/x86_64-openbsd/types.conf +86 -86
- data/lib/ffi/platform/x86_64-solaris/types.conf +96 -96
- data/lib/ffi/platform/x86_64-windows/types.conf +42 -110
- data/lib/ffi/pointer.rb +26 -20
- data/lib/ffi/struct.rb +13 -68
- data/lib/ffi/struct_by_reference.rb +72 -0
- data/lib/ffi/struct_layout.rb +96 -0
- data/lib/ffi/tools/const_generator.rb +5 -4
- data/lib/ffi/tools/generator.rb +47 -2
- data/lib/ffi/tools/generator_task.rb +13 -17
- data/lib/ffi/tools/struct_generator.rb +4 -4
- data/lib/ffi/tools/types_generator.rb +7 -4
- data/lib/ffi/types.rb +1 -1
- data/lib/ffi/variadic.rb +1 -10
- data/lib/ffi/version.rb +1 -1
- data/rakelib/ffi_gem_helper.rb +65 -0
- data/samples/getlogin.rb +1 -1
- data/samples/getpid.rb +1 -1
- data/samples/gettimeofday.rb +8 -8
- data/samples/hello.rb +2 -1
- data/samples/inotify.rb +1 -1
- data/samples/pty.rb +1 -2
- data/samples/qsort.rb +0 -1
- metadata +160 -122
- data/.gitignore +0 -22
- data/.gitmodules +0 -3
- data/.travis.yml +0 -52
- data/.yardopts +0 -5
- data/appveyor.yml +0 -22
- data/ext/ffi_c/DataConverter.c +0 -91
- data/ext/ffi_c/StructByReference.c +0 -190
- data/ext/ffi_c/StructByReference.h +0 -50
- data/ext/ffi_c/libffi/ChangeLog.libffi +0 -584
- data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
- data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
- data/ext/ffi_c/win32/stdbool.h +0 -8
- data/ext/ffi_c/win32/stdint.h +0 -201
- data/samples/sample_helper.rb +0 -6
data/ext/ffi_c/AbstractMemory.c
CHANGED
@@ -32,12 +32,9 @@
|
|
32
32
|
#include <sys/types.h>
|
33
33
|
#ifndef _MSC_VER
|
34
34
|
# include <sys/param.h>
|
35
|
-
# include <stdint.h>
|
36
|
-
# include <stdbool.h>
|
37
|
-
#else
|
38
|
-
# include "win32/stdbool.h"
|
39
|
-
# include "win32/stdint.h"
|
40
35
|
#endif
|
36
|
+
#include <stdint.h>
|
37
|
+
#include <stdbool.h>
|
41
38
|
|
42
39
|
#include <limits.h>
|
43
40
|
#include <ruby.h>
|
@@ -135,11 +132,13 @@ static VALUE memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary); \
|
|
135
132
|
static VALUE \
|
136
133
|
memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \
|
137
134
|
{ \
|
138
|
-
long count
|
135
|
+
long count; \
|
139
136
|
long off = NUM2LONG(offset); \
|
140
137
|
AbstractMemory* memory = MEMORY(self); \
|
141
138
|
long i; \
|
142
|
-
|
139
|
+
Check_Type(ary, T_ARRAY); \
|
140
|
+
count = RARRAY_LEN(ary); \
|
141
|
+
if (likely(count > 0)) checkWrite(memory); \
|
143
142
|
checkBounds(memory, off, count * sizeof(type)); \
|
144
143
|
for (i = 0; i < count; i++) { \
|
145
144
|
type tmp = (type) VAL(toNative(RARRAY_PTR(ary)[i]), swap); \
|
@@ -162,7 +161,7 @@ memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length) \
|
|
162
161
|
AbstractMemory* memory = MEMORY(self); \
|
163
162
|
VALUE retVal = rb_ary_new2(count); \
|
164
163
|
long i; \
|
165
|
-
checkRead(memory); \
|
164
|
+
if (likely(count > 0)) checkRead(memory); \
|
166
165
|
checkBounds(memory, off, count * sizeof(type)); \
|
167
166
|
for (i = 0; i < count; ++i) { \
|
168
167
|
type tmp; \
|
@@ -209,13 +208,13 @@ SWAPU16(uint16_t x)
|
|
209
208
|
((x >> 40) & 0x000000000000ff00ULL) | \
|
210
209
|
((x >> 56) & 0x00000000000000ffULL))
|
211
210
|
|
212
|
-
static inline int32_t
|
211
|
+
static inline int32_t
|
213
212
|
SWAPS32(int32_t x)
|
214
213
|
{
|
215
214
|
return bswap32(x);
|
216
215
|
}
|
217
216
|
|
218
|
-
static inline uint32_t
|
217
|
+
static inline uint32_t
|
219
218
|
SWAPU32(uint32_t x)
|
220
219
|
{
|
221
220
|
return bswap32(x);
|
@@ -417,7 +416,7 @@ memory_get_string(int argc, VALUE* argv, VALUE self)
|
|
417
416
|
checkBounds(ptr, off, len);
|
418
417
|
|
419
418
|
end = memchr(ptr->address + off, 0, len);
|
420
|
-
return
|
419
|
+
return rb_str_new((char *) ptr->address + off,
|
421
420
|
(end != NULL ? end - ptr->address - off : len));
|
422
421
|
}
|
423
422
|
|
@@ -450,10 +449,10 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
450
449
|
int i;
|
451
450
|
|
452
451
|
checkBounds(ptr, off, count * sizeof (char*));
|
453
|
-
|
452
|
+
|
454
453
|
for (i = 0; i < count; ++i) {
|
455
454
|
const char* strptr = *((const char**) (ptr->address + off) + i);
|
456
|
-
rb_ary_push(retVal, (strptr == NULL ? Qnil :
|
455
|
+
rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_str_new2(strptr)));
|
457
456
|
}
|
458
457
|
|
459
458
|
} else {
|
@@ -463,7 +462,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
463
462
|
if (strptr == NULL) {
|
464
463
|
break;
|
465
464
|
}
|
466
|
-
rb_ary_push(retVal,
|
465
|
+
rb_ary_push(retVal, rb_str_new2(strptr));
|
467
466
|
}
|
468
467
|
}
|
469
468
|
|
@@ -477,7 +476,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
477
476
|
* @param [Numeric] count number of strings to get. If nil, return all strings
|
478
477
|
* @return [Array<String>]
|
479
478
|
*/
|
480
|
-
static VALUE
|
479
|
+
static VALUE
|
481
480
|
memory_read_array_of_string(int argc, VALUE* argv, VALUE self)
|
482
481
|
{
|
483
482
|
VALUE* rargv = ALLOCA_N(VALUE, argc + 1);
|
@@ -535,14 +534,14 @@ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
|
|
535
534
|
{
|
536
535
|
AbstractMemory* ptr = MEMORY(self);
|
537
536
|
long off, len;
|
538
|
-
|
537
|
+
|
539
538
|
off = NUM2LONG(offset);
|
540
539
|
len = NUM2LONG(length);
|
541
540
|
|
542
541
|
checkRead(ptr);
|
543
542
|
checkBounds(ptr, off, len);
|
544
|
-
|
545
|
-
return
|
543
|
+
|
544
|
+
return rb_str_new((char *) ptr->address + off, len);
|
546
545
|
}
|
547
546
|
|
548
547
|
/*
|
@@ -583,10 +582,6 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
|
|
583
582
|
checkWrite(ptr);
|
584
583
|
checkBounds(ptr, off, len);
|
585
584
|
|
586
|
-
if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
|
587
|
-
rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
|
588
|
-
return Qnil;
|
589
|
-
}
|
590
585
|
memcpy(ptr->address + off, RSTRING_PTR(str) + idx, len);
|
591
586
|
|
592
587
|
return self;
|
@@ -599,7 +594,7 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
|
|
599
594
|
* equivalent to :
|
600
595
|
* memory.get_bytes(0, length)
|
601
596
|
*/
|
602
|
-
static VALUE
|
597
|
+
static VALUE
|
603
598
|
memory_read_bytes(VALUE self, VALUE length)
|
604
599
|
{
|
605
600
|
return memory_get_bytes(self, INT2FIX(0), length);
|
@@ -614,7 +609,7 @@ memory_read_bytes(VALUE self, VALUE length)
|
|
614
609
|
* equivalent to :
|
615
610
|
* memory.put_bytes(0, str, index, length)
|
616
611
|
*/
|
617
|
-
static VALUE
|
612
|
+
static VALUE
|
618
613
|
memory_write_bytes(int argc, VALUE* argv, VALUE self)
|
619
614
|
{
|
620
615
|
VALUE* wargv = ALLOCA_N(VALUE, argc + 1);
|
@@ -647,7 +642,7 @@ memory_type_size(VALUE self)
|
|
647
642
|
* Document-method: []
|
648
643
|
* call-seq: memory[idx]
|
649
644
|
* @param [Numeric] idx index to access in memory
|
650
|
-
* @return
|
645
|
+
* @return
|
651
646
|
* Memory read accessor.
|
652
647
|
*/
|
653
648
|
static VALUE
|
@@ -718,7 +713,7 @@ memory_op_get_strptr(AbstractMemory* ptr, long offset)
|
|
718
713
|
memcpy(&tmp, ptr->address + offset, sizeof(tmp));
|
719
714
|
}
|
720
715
|
|
721
|
-
return tmp != NULL ?
|
716
|
+
return tmp != NULL ? rb_str_new2(tmp) : Qnil;
|
722
717
|
}
|
723
718
|
|
724
719
|
static void
|
@@ -752,9 +747,9 @@ MemoryOps rbffi_AbstractMemoryOps = {
|
|
752
747
|
void
|
753
748
|
rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
754
749
|
{
|
755
|
-
/*
|
750
|
+
/*
|
756
751
|
* Document-class: FFI::AbstractMemory
|
757
|
-
*
|
752
|
+
*
|
758
753
|
* {AbstractMemory} is the base class for many memory management classes such as {Buffer}.
|
759
754
|
*
|
760
755
|
* This class has a lot of methods to work with integers :
|
@@ -782,8 +777,8 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
782
777
|
*/
|
783
778
|
VALUE classMemory = rb_define_class_under(moduleFFI, "AbstractMemory", rb_cObject);
|
784
779
|
rbffi_AbstractMemoryClass = classMemory;
|
785
|
-
/*
|
786
|
-
* Document-variable: FFI::AbstractMemory
|
780
|
+
/*
|
781
|
+
* Document-variable: FFI::AbstractMemory
|
787
782
|
*/
|
788
783
|
rb_global_variable(&rbffi_AbstractMemoryClass);
|
789
784
|
rb_define_alloc_func(classMemory, memory_allocate);
|
@@ -811,13 +806,13 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
811
806
|
rb_define_method(classMemory, "read_array_of_" #type, memory_read_array_of_##type, 1); \
|
812
807
|
rb_define_method(classMemory, "write_array_of_u" #type, memory_write_array_of_u##type, 1); \
|
813
808
|
rb_define_method(classMemory, "read_array_of_u" #type, memory_read_array_of_u##type, 1);
|
814
|
-
|
809
|
+
|
815
810
|
INT(int8);
|
816
811
|
INT(int16);
|
817
812
|
INT(int32);
|
818
813
|
INT(int64);
|
819
814
|
INT(long);
|
820
|
-
|
815
|
+
|
821
816
|
#define ALIAS(name, old) \
|
822
817
|
rb_define_alias(classMemory, "put_" #name, "put_" #old); \
|
823
818
|
rb_define_alias(classMemory, "get_" #name, "get_" #old); \
|
@@ -835,12 +830,12 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
835
830
|
rb_define_alias(classMemory, "read_array_of_" #name, "read_array_of_" #old); \
|
836
831
|
rb_define_alias(classMemory, "write_array_of_u" #name, "write_array_of_u" #old); \
|
837
832
|
rb_define_alias(classMemory, "read_array_of_u" #name, "read_array_of_u" #old);
|
838
|
-
|
833
|
+
|
839
834
|
ALIAS(char, int8);
|
840
835
|
ALIAS(short, int16);
|
841
836
|
ALIAS(int, int32);
|
842
837
|
ALIAS(long_long, int64);
|
843
|
-
|
838
|
+
|
844
839
|
/*
|
845
840
|
* Document-method: put_float32
|
846
841
|
* call-seq: memory.put_float32offset, value)
|
data/ext/ffi_c/Buffer.c
CHANGED
@@ -28,13 +28,8 @@
|
|
28
28
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
29
|
*/
|
30
30
|
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# include <stdbool.h>
|
34
|
-
#else
|
35
|
-
# include "win32/stdbool.h"
|
36
|
-
# include "win32/stdint.h"
|
37
|
-
#endif
|
31
|
+
#include <stdint.h>
|
32
|
+
#include <stdbool.h>
|
38
33
|
#include <limits.h>
|
39
34
|
#include <ruby.h>
|
40
35
|
#include "rbffi.h"
|
@@ -114,7 +109,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
114
109
|
}
|
115
110
|
|
116
111
|
/* ensure the memory is aligned on at least a 8 byte boundary */
|
117
|
-
p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~
|
112
|
+
p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7ULL);
|
118
113
|
|
119
114
|
if (p->memory.size > 0 && (nargs < 3 || RTEST(rbClear))) {
|
120
115
|
memset(p->memory.address, 0, p->memory.size);
|
@@ -154,7 +149,7 @@ buffer_initialize_copy(VALUE self, VALUE other)
|
|
154
149
|
return Qnil;
|
155
150
|
}
|
156
151
|
|
157
|
-
dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~
|
152
|
+
dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7ULL);
|
158
153
|
dst->memory.size = src->size;
|
159
154
|
dst->memory.typeSize = src->typeSize;
|
160
155
|
|
data/ext/ffi_c/Call.c
CHANGED
@@ -34,19 +34,12 @@
|
|
34
34
|
#endif
|
35
35
|
#include <sys/types.h>
|
36
36
|
#include <stdio.h>
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# include <stdbool.h>
|
40
|
-
#else
|
41
|
-
# include "win32/stdbool.h"
|
42
|
-
# include "win32/stdint.h"
|
43
|
-
#endif
|
37
|
+
#include <stdint.h>
|
38
|
+
#include <stdbool.h>
|
44
39
|
#include <errno.h>
|
45
40
|
#include <ruby.h>
|
46
|
-
#if defined(HAVE_RUBY_THREAD_H)
|
47
41
|
#include <ruby/thread.h>
|
48
|
-
#
|
49
|
-
#if defined(HAVE_NATIVETHREAD) && (defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) && !defined(_WIN32)
|
42
|
+
#if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
|
50
43
|
# include <signal.h>
|
51
44
|
# include <pthread.h>
|
52
45
|
#endif
|
@@ -116,7 +109,7 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
116
109
|
Type* paramType = paramTypes[i];
|
117
110
|
int type;
|
118
111
|
|
119
|
-
|
112
|
+
|
120
113
|
if (unlikely(paramType->nativeType == NATIVE_MAPPED)) {
|
121
114
|
VALUE values[] = { argv[argidx], Qnil };
|
122
115
|
argv[argidx] = rb_funcall2(((MappedType *) paramType)->rbConverter, id_to_native, 2, values);
|
@@ -297,13 +290,9 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
297
290
|
|
298
291
|
case NATIVE_STRING:
|
299
292
|
if (type == T_NIL) {
|
300
|
-
param->ptr = NULL;
|
301
|
-
|
302
|
-
} else {
|
303
|
-
if (rb_safe_level() >= 1 && OBJ_TAINTED(argv[argidx])) {
|
304
|
-
rb_raise(rb_eSecurityError, "Unsafe string parameter");
|
305
|
-
}
|
293
|
+
param->ptr = NULL;
|
306
294
|
|
295
|
+
} else {
|
307
296
|
param->ptr = StringValueCStr(argv[argidx]);
|
308
297
|
}
|
309
298
|
|
@@ -321,7 +310,6 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
321
310
|
|
322
311
|
|
323
312
|
case NATIVE_FUNCTION:
|
324
|
-
case NATIVE_CALLBACK:
|
325
313
|
if (callbackProc != Qnil) {
|
326
314
|
param->ptr = callback_param(callbackProc, callbackParameters[cbidx++]);
|
327
315
|
} else {
|
@@ -345,23 +333,21 @@ static void *
|
|
345
333
|
call_blocking_function(void* data)
|
346
334
|
{
|
347
335
|
rbffi_blocking_call_t* b = (rbffi_blocking_call_t *) data;
|
348
|
-
b->frame->has_gvl = false;
|
349
336
|
ffi_call(&b->cif, FFI_FN(b->function), b->retval, b->ffiValues);
|
350
|
-
b->frame->has_gvl = true;
|
351
337
|
|
352
338
|
return NULL;
|
353
339
|
}
|
354
340
|
|
355
341
|
VALUE
|
356
|
-
rbffi_do_blocking_call(
|
342
|
+
rbffi_do_blocking_call(VALUE data)
|
357
343
|
{
|
358
|
-
|
344
|
+
rb_thread_call_without_gvl(call_blocking_function, (void*)data, (rb_unblock_function_t *) -1, NULL);
|
359
345
|
|
360
346
|
return Qnil;
|
361
347
|
}
|
362
348
|
|
363
349
|
VALUE
|
364
|
-
rbffi_save_frame_exception(
|
350
|
+
rbffi_save_frame_exception(VALUE data, VALUE exc)
|
365
351
|
{
|
366
352
|
rbffi_frame_t* frame = (rbffi_frame_t *) data;
|
367
353
|
frame->exc = exc;
|
@@ -376,28 +362,17 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
376
362
|
FFIStorage* params;
|
377
363
|
VALUE rbReturnValue;
|
378
364
|
rbffi_frame_t frame = { 0 };
|
379
|
-
|
365
|
+
|
380
366
|
retval = alloca(MAX(fnInfo->ffi_cif.rtype->size, FFI_SIZEOF_ARG));
|
381
|
-
|
367
|
+
|
382
368
|
if (unlikely(fnInfo->blocking)) {
|
383
369
|
rbffi_blocking_call_t* bc;
|
384
370
|
|
385
|
-
/*
|
386
|
-
* due to the way thread switching works on older ruby variants, we
|
387
|
-
* cannot allocate anything passed to the blocking function on the stack
|
388
|
-
*/
|
389
|
-
#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
|
371
|
+
/* allocate information passed to the blocking function on the stack */
|
390
372
|
ffiValues = ALLOCA_N(void *, fnInfo->parameterCount);
|
391
373
|
params = ALLOCA_N(FFIStorage, fnInfo->parameterCount);
|
392
374
|
bc = ALLOCA_N(rbffi_blocking_call_t, 1);
|
393
375
|
bc->retval = retval;
|
394
|
-
#else
|
395
|
-
ffiValues = ALLOC_N(void *, fnInfo->parameterCount);
|
396
|
-
params = ALLOC_N(FFIStorage, fnInfo->parameterCount);
|
397
|
-
bc = ALLOC_N(rbffi_blocking_call_t, 1);
|
398
|
-
bc->retval = xmalloc(MAX(fnInfo->ffi_cif.rtype->size, FFI_SIZEOF_ARG));
|
399
|
-
bc->stkretval = retval;
|
400
|
-
#endif
|
401
376
|
bc->cif = fnInfo->ffi_cif;
|
402
377
|
bc->function = function;
|
403
378
|
bc->ffiValues = ffiValues;
|
@@ -408,18 +383,10 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
408
383
|
fnInfo->parameterCount, fnInfo->parameterTypes, params, ffiValues,
|
409
384
|
fnInfo->callbackParameters, fnInfo->callbackCount, fnInfo->rbEnums);
|
410
385
|
|
411
|
-
rbffi_frame_push(&frame);
|
386
|
+
rbffi_frame_push(&frame);
|
412
387
|
rb_rescue2(rbffi_do_blocking_call, (VALUE) bc, rbffi_save_frame_exception, (VALUE) &frame, rb_eException, (VALUE) 0);
|
413
388
|
rbffi_frame_pop(&frame);
|
414
389
|
|
415
|
-
#if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
|
416
|
-
memcpy(bc->stkretval, bc->retval, MAX(bc->cif.rtype->size, FFI_SIZEOF_ARG));
|
417
|
-
xfree(bc->params);
|
418
|
-
xfree(bc->ffiValues);
|
419
|
-
xfree(bc->retval);
|
420
|
-
xfree(bc);
|
421
|
-
#endif
|
422
|
-
|
423
390
|
} else {
|
424
391
|
|
425
392
|
ffiValues = ALLOCA_N(void *, fnInfo->parameterCount);
|
@@ -436,7 +403,7 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
436
403
|
|
437
404
|
if (unlikely(!fnInfo->ignoreErrno)) {
|
438
405
|
rbffi_save_errno();
|
439
|
-
}
|
406
|
+
}
|
440
407
|
|
441
408
|
if (RTEST(frame.exc) && frame.exc != Qnil) {
|
442
409
|
rb_exc_raise(frame.exc);
|
@@ -444,7 +411,7 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
444
411
|
|
445
412
|
RB_GC_GUARD(rbReturnValue) = rbffi_NativeValue_ToRuby(fnInfo->returnType, fnInfo->rbReturnType, retval);
|
446
413
|
RB_GC_GUARD(fnInfo->rbReturnType);
|
447
|
-
|
414
|
+
|
448
415
|
return rbReturnValue;
|
449
416
|
}
|
450
417
|
|
@@ -461,7 +428,7 @@ getPointer(VALUE value, int type)
|
|
461
428
|
return memory != NULL ? memory->address : NULL;
|
462
429
|
|
463
430
|
} else if (type == T_STRING) {
|
464
|
-
|
431
|
+
|
465
432
|
return StringValuePtr(value);
|
466
433
|
|
467
434
|
} else if (type == T_NIL) {
|
data/ext/ffi_c/Call.h
CHANGED
@@ -48,7 +48,7 @@ extern "C" {
|
|
48
48
|
#if (defined(__i386__) || defined(__x86_64__)) && !(defined(_WIN32) || defined(__WIN32__))
|
49
49
|
# define BYPASS_FFI 1
|
50
50
|
#endif
|
51
|
-
|
51
|
+
|
52
52
|
typedef union {
|
53
53
|
#ifdef USE_RAW
|
54
54
|
signed int s8, s16, s32;
|
@@ -70,7 +70,7 @@ typedef union {
|
|
70
70
|
double f64;
|
71
71
|
long double ld;
|
72
72
|
} FFIStorage;
|
73
|
-
|
73
|
+
|
74
74
|
extern void rbffi_Call_Init(VALUE moduleFFI);
|
75
75
|
|
76
76
|
extern void rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
@@ -94,13 +94,10 @@ typedef struct rbffi_blocking_call {
|
|
94
94
|
void **ffiValues;
|
95
95
|
void* retval;
|
96
96
|
void* params;
|
97
|
-
#if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
|
98
|
-
void* stkretval;
|
99
|
-
#endif
|
100
97
|
} rbffi_blocking_call_t;
|
101
98
|
|
102
|
-
VALUE rbffi_do_blocking_call(
|
103
|
-
VALUE rbffi_save_frame_exception(
|
99
|
+
VALUE rbffi_do_blocking_call(VALUE data);
|
100
|
+
VALUE rbffi_save_frame_exception(VALUE data, VALUE exc);
|
104
101
|
|
105
102
|
#ifdef __cplusplus
|
106
103
|
}
|
data/ext/ffi_c/ClosurePool.c
CHANGED
@@ -34,13 +34,8 @@
|
|
34
34
|
# include <sys/mman.h>
|
35
35
|
#endif
|
36
36
|
#include <stdio.h>
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# include <stdbool.h>
|
40
|
-
#else
|
41
|
-
# include "win32/stdbool.h"
|
42
|
-
# include "win32/stdint.h"
|
43
|
-
#endif
|
37
|
+
#include <stdint.h>
|
38
|
+
#include <stdbool.h>
|
44
39
|
#if defined(__CYGWIN__) || !defined(_WIN32)
|
45
40
|
# include <unistd.h>
|
46
41
|
#else
|
@@ -51,9 +46,6 @@
|
|
51
46
|
#include <errno.h>
|
52
47
|
#include <ruby.h>
|
53
48
|
|
54
|
-
#if defined(_MSC_VER) && !defined(INT8_MIN)
|
55
|
-
# include "win32/stdint.h"
|
56
|
-
#endif
|
57
49
|
#include <ffi.h>
|
58
50
|
#include "rbffi.h"
|
59
51
|
#include "compat.h"
|
@@ -66,13 +58,9 @@
|
|
66
58
|
|
67
59
|
#include "ClosurePool.h"
|
68
60
|
|
69
|
-
|
70
61
|
#ifndef roundup
|
71
62
|
# define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
|
72
63
|
#endif
|
73
|
-
#ifdef _WIN32
|
74
|
-
typedef char* caddr_t;
|
75
|
-
#endif
|
76
64
|
|
77
65
|
typedef struct Memory {
|
78
66
|
void* code;
|
@@ -96,7 +84,7 @@ static bool freePage(void *);
|
|
96
84
|
static bool protectPage(void *);
|
97
85
|
|
98
86
|
ClosurePool*
|
99
|
-
rbffi_ClosurePool_New(int closureSize,
|
87
|
+
rbffi_ClosurePool_New(int closureSize,
|
100
88
|
bool (*prep)(void* ctx, void *code, Closure* closure, char* errbuf, size_t errbufsize),
|
101
89
|
void* ctx)
|
102
90
|
{
|
@@ -107,7 +95,7 @@ rbffi_ClosurePool_New(int closureSize,
|
|
107
95
|
pool->ctx = ctx;
|
108
96
|
pool->prep = prep;
|
109
97
|
pool->refcnt = 1;
|
110
|
-
|
98
|
+
|
111
99
|
return pool;
|
112
100
|
}
|
113
101
|
|
@@ -115,10 +103,14 @@ void
|
|
115
103
|
cleanup_closure_pool(ClosurePool* pool)
|
116
104
|
{
|
117
105
|
Memory* memory;
|
118
|
-
|
106
|
+
|
119
107
|
for (memory = pool->blocks; memory != NULL; ) {
|
120
108
|
Memory* next = memory->next;
|
109
|
+
#if !USE_FFI_ALLOC
|
121
110
|
freePage(memory->code);
|
111
|
+
#else
|
112
|
+
ffi_closure_free(memory->code);
|
113
|
+
#endif
|
122
114
|
free(memory->data);
|
123
115
|
free(memory);
|
124
116
|
memory = next;
|
@@ -137,12 +129,14 @@ rbffi_ClosurePool_Free(ClosurePool* pool)
|
|
137
129
|
}
|
138
130
|
}
|
139
131
|
|
132
|
+
#if !USE_FFI_ALLOC
|
133
|
+
|
140
134
|
Closure*
|
141
135
|
rbffi_Closure_Alloc(ClosurePool* pool)
|
142
136
|
{
|
143
137
|
Closure *list = NULL;
|
144
138
|
Memory* block = NULL;
|
145
|
-
|
139
|
+
void *code = NULL;
|
146
140
|
char errmsg[256];
|
147
141
|
int nclosures;
|
148
142
|
long trampolineSize;
|
@@ -152,7 +146,7 @@ rbffi_Closure_Alloc(ClosurePool* pool)
|
|
152
146
|
Closure* closure = pool->list;
|
153
147
|
pool->list = pool->list->next;
|
154
148
|
pool->refcnt++;
|
155
|
-
|
149
|
+
|
156
150
|
return closure;
|
157
151
|
}
|
158
152
|
|
@@ -161,17 +155,18 @@ rbffi_Closure_Alloc(ClosurePool* pool)
|
|
161
155
|
block = calloc(1, sizeof(*block));
|
162
156
|
list = calloc(nclosures, sizeof(*list));
|
163
157
|
code = allocatePage();
|
164
|
-
|
158
|
+
|
165
159
|
if (block == NULL || list == NULL || code == NULL) {
|
166
160
|
snprintf(errmsg, sizeof(errmsg), "failed to allocate a page. errno=%d (%s)", errno, strerror(errno));
|
167
161
|
goto error;
|
168
162
|
}
|
169
|
-
|
163
|
+
|
170
164
|
for (i = 0; i < nclosures; ++i) {
|
171
165
|
Closure* closure = &list[i];
|
172
166
|
closure->next = &list[i + 1];
|
173
167
|
closure->pool = pool;
|
174
|
-
closure->code = (code + (i * trampolineSize));
|
168
|
+
closure->code = ((char *)code + (i * trampolineSize));
|
169
|
+
closure->pcl = closure->code;
|
175
170
|
|
176
171
|
if (!(*pool->prep)(pool->ctx, closure->code, closure, errmsg, sizeof(errmsg))) {
|
177
172
|
goto error;
|
@@ -202,12 +197,63 @@ error:
|
|
202
197
|
if (code != NULL) {
|
203
198
|
freePage(code);
|
204
199
|
}
|
205
|
-
|
200
|
+
|
206
201
|
|
207
202
|
rb_raise(rb_eRuntimeError, "%s", errmsg);
|
208
203
|
return NULL;
|
209
204
|
}
|
210
205
|
|
206
|
+
#else
|
207
|
+
|
208
|
+
Closure*
|
209
|
+
rbffi_Closure_Alloc(ClosurePool* pool)
|
210
|
+
{
|
211
|
+
Closure *closure = NULL;
|
212
|
+
Memory* block = NULL;
|
213
|
+
void *code = NULL;
|
214
|
+
void *pcl = NULL;
|
215
|
+
char errmsg[256];
|
216
|
+
|
217
|
+
block = calloc(1, sizeof(*block));
|
218
|
+
closure = calloc(1, sizeof(*closure));
|
219
|
+
pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
220
|
+
|
221
|
+
if (block == NULL || closure == NULL || pcl == NULL) {
|
222
|
+
snprintf(errmsg, sizeof(errmsg), "failed to allocate a page. errno=%d (%s)", errno, strerror(errno));
|
223
|
+
goto error;
|
224
|
+
}
|
225
|
+
|
226
|
+
closure->pool = pool;
|
227
|
+
closure->code = code;
|
228
|
+
closure->pcl = pcl;
|
229
|
+
|
230
|
+
if (!(*pool->prep)(pool->ctx, closure->code, closure, errmsg, sizeof(errmsg))) {
|
231
|
+
goto error;
|
232
|
+
}
|
233
|
+
|
234
|
+
/* Track the allocated page + Closure memory area */
|
235
|
+
block->data = closure;
|
236
|
+
block->code = pcl;
|
237
|
+
pool->blocks = block;
|
238
|
+
|
239
|
+
/* Thread the new block onto the free list, apart from the first one. */
|
240
|
+
pool->refcnt++;
|
241
|
+
|
242
|
+
return closure;
|
243
|
+
|
244
|
+
error:
|
245
|
+
free(block);
|
246
|
+
free(closure);
|
247
|
+
if (pcl != NULL) {
|
248
|
+
ffi_closure_free(pcl);
|
249
|
+
}
|
250
|
+
|
251
|
+
rb_raise(rb_eRuntimeError, "%s", errmsg);
|
252
|
+
return NULL;
|
253
|
+
}
|
254
|
+
|
255
|
+
#endif /* !USE_FFI_ALLOC */
|
256
|
+
|
211
257
|
void
|
212
258
|
rbffi_Closure_Free(Closure* closure)
|
213
259
|
{
|
@@ -243,14 +289,16 @@ getPageSize()
|
|
243
289
|
#endif
|
244
290
|
}
|
245
291
|
|
292
|
+
#if !USE_FFI_ALLOC
|
293
|
+
|
246
294
|
static void*
|
247
295
|
allocatePage(void)
|
248
296
|
{
|
249
297
|
#if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__))
|
250
298
|
return VirtualAlloc(NULL, pageSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
251
299
|
#else
|
252
|
-
|
253
|
-
return (page != (
|
300
|
+
void *page = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
301
|
+
return (page != (void *) -1) ? page : NULL;
|
254
302
|
#endif
|
255
303
|
}
|
256
304
|
|
@@ -275,6 +323,8 @@ protectPage(void* page)
|
|
275
323
|
#endif
|
276
324
|
}
|
277
325
|
|
326
|
+
#endif /* !USE_FFI_ALLOC */
|
327
|
+
|
278
328
|
void
|
279
329
|
rbffi_ClosurePool_Init(VALUE module)
|
280
330
|
{
|