ffi 1.10.0 → 1.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{appveyor.yml → .appveyor.yml} +9 -1
- data/.github/workflows/ci.yml +64 -0
- data/.gitignore +3 -0
- data/.gitmodules +1 -0
- data/.travis.yml +35 -20
- data/CHANGELOG.md +124 -0
- data/Gemfile +6 -4
- data/README.md +29 -17
- data/Rakefile +29 -120
- data/ext/ffi_c/AbstractMemory.c +5 -9
- data/ext/ffi_c/Buffer.c +2 -2
- data/ext/ffi_c/Call.c +14 -41
- data/ext/ffi_c/Call.h +4 -7
- data/ext/ffi_c/ClosurePool.c +11 -14
- data/ext/ffi_c/DynamicLibrary.c +1 -1
- data/ext/ffi_c/Function.c +18 -117
- data/ext/ffi_c/FunctionInfo.c +1 -2
- data/ext/ffi_c/LongDouble.c +12 -10
- data/ext/ffi_c/LongDouble.h +0 -4
- data/ext/ffi_c/MemoryPointer.c +1 -1
- data/ext/ffi_c/MethodHandle.c +18 -24
- data/ext/ffi_c/MethodHandle.h +3 -2
- data/ext/ffi_c/Platform.c +1 -47
- data/ext/ffi_c/Pointer.c +1 -1
- data/ext/ffi_c/Struct.c +47 -51
- data/ext/ffi_c/Struct.h +12 -6
- data/ext/ffi_c/StructLayout.c +20 -14
- data/ext/ffi_c/Thread.c +4 -223
- data/ext/ffi_c/Thread.h +0 -14
- data/ext/ffi_c/Type.c +0 -18
- data/ext/ffi_c/Type.h +0 -1
- data/ext/ffi_c/Types.c +1 -1
- data/ext/ffi_c/Variadic.c +9 -15
- data/ext/ffi_c/compat.h +4 -0
- data/ext/ffi_c/extconf.rb +36 -26
- 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/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 +35 -41
- data/ext/ffi_c/libffi/README.md +29 -8
- data/ext/ffi_c/libffi/configure.ac +31 -11
- data/ext/ffi_c/libffi/configure.host +26 -9
- data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +1 -3
- 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 +27 -2
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +132 -58
- data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +13 -2
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +21 -8
- data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
- data/ext/ffi_c/libffi/src/arm/ffi.c +40 -5
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +8 -1
- data/ext/ffi_c/libffi/src/arm/sysv.S +2 -0
- data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
- data/ext/ffi_c/libffi/src/closures.c +51 -13
- data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/metag/ffi.c +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_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 +83 -28
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +68 -4
- 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 +21 -10
- data/ext/ffi_c/libffi/src/x86/ffi64.c +15 -11
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +15 -10
- data/ext/ffi_c/libffi/src/x86/sysv.S +103 -8
- data/ext/ffi_c/libffi/src/x86/sysv_intel.S +995 -0
- data/ext/ffi_c/libffi/src/x86/unix64.S +99 -2
- data/ext/ffi_c/libffi/src/x86/win64.S +9 -1
- data/ext/ffi_c/libffi/testsuite/Makefile.am +114 -109
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +26 -22
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +7 -2
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +1 -1
- 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 +1 -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 +12 -5
- data/lib/ffi.rb +10 -2
- data/lib/ffi/data_converter.rb +67 -0
- data/lib/ffi/ffi.rb +2 -0
- data/lib/ffi/library.rb +10 -6
- data/lib/ffi/platform.rb +12 -3
- data/lib/ffi/platform/aarch64-freebsd/types.conf +89 -89
- data/lib/ffi/platform/aarch64-freebsd12/types.conf +89 -89
- data/lib/ffi/platform/aarch64-linux/types.conf +81 -81
- data/lib/ffi/platform/arm-freebsd/types.conf +87 -87
- data/lib/ffi/platform/arm-freebsd12/types.conf +87 -87
- 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 +87 -87
- data/lib/ffi/platform/i386-freebsd12/types.conf +87 -87
- 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/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 +89 -89
- data/lib/ffi/platform/x86_64-freebsd12/types.conf +139 -109
- data/lib/ffi/platform/x86_64-linux/types.conf +107 -77
- 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 +20 -13
- 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/version.rb +1 -1
- 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 +141 -116
- 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/samples/sample_helper.rb +0 -6
data/ext/ffi_c/AbstractMemory.c
CHANGED
@@ -417,7 +417,7 @@ memory_get_string(int argc, VALUE* argv, VALUE self)
|
|
417
417
|
checkBounds(ptr, off, len);
|
418
418
|
|
419
419
|
end = memchr(ptr->address + off, 0, len);
|
420
|
-
return
|
420
|
+
return rb_str_new((char *) ptr->address + off,
|
421
421
|
(end != NULL ? end - ptr->address - off : len));
|
422
422
|
}
|
423
423
|
|
@@ -453,7 +453,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
453
453
|
|
454
454
|
for (i = 0; i < count; ++i) {
|
455
455
|
const char* strptr = *((const char**) (ptr->address + off) + i);
|
456
|
-
rb_ary_push(retVal, (strptr == NULL ? Qnil :
|
456
|
+
rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_str_new2(strptr)));
|
457
457
|
}
|
458
458
|
|
459
459
|
} else {
|
@@ -463,7 +463,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
463
463
|
if (strptr == NULL) {
|
464
464
|
break;
|
465
465
|
}
|
466
|
-
rb_ary_push(retVal,
|
466
|
+
rb_ary_push(retVal, rb_str_new2(strptr));
|
467
467
|
}
|
468
468
|
}
|
469
469
|
|
@@ -542,7 +542,7 @@ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
|
|
542
542
|
checkRead(ptr);
|
543
543
|
checkBounds(ptr, off, len);
|
544
544
|
|
545
|
-
return
|
545
|
+
return rb_str_new((char *) ptr->address + off, len);
|
546
546
|
}
|
547
547
|
|
548
548
|
/*
|
@@ -583,10 +583,6 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
|
|
583
583
|
checkWrite(ptr);
|
584
584
|
checkBounds(ptr, off, len);
|
585
585
|
|
586
|
-
if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
|
587
|
-
rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
|
588
|
-
return Qnil;
|
589
|
-
}
|
590
586
|
memcpy(ptr->address + off, RSTRING_PTR(str) + idx, len);
|
591
587
|
|
592
588
|
return self;
|
@@ -718,7 +714,7 @@ memory_op_get_strptr(AbstractMemory* ptr, long offset)
|
|
718
714
|
memcpy(&tmp, ptr->address + offset, sizeof(tmp));
|
719
715
|
}
|
720
716
|
|
721
|
-
return tmp != NULL ?
|
717
|
+
return tmp != NULL ? rb_str_new2(tmp) : Qnil;
|
722
718
|
}
|
723
719
|
|
724
720
|
static void
|
data/ext/ffi_c/Buffer.c
CHANGED
@@ -114,7 +114,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
114
114
|
}
|
115
115
|
|
116
116
|
/* 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) ~
|
117
|
+
p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7ULL);
|
118
118
|
|
119
119
|
if (p->memory.size > 0 && (nargs < 3 || RTEST(rbClear))) {
|
120
120
|
memset(p->memory.address, 0, p->memory.size);
|
@@ -154,7 +154,7 @@ buffer_initialize_copy(VALUE self, VALUE other)
|
|
154
154
|
return Qnil;
|
155
155
|
}
|
156
156
|
|
157
|
-
dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~
|
157
|
+
dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7ULL);
|
158
158
|
dst->memory.size = src->size;
|
159
159
|
dst->memory.typeSize = src->typeSize;
|
160
160
|
|
data/ext/ffi_c/Call.c
CHANGED
@@ -43,10 +43,8 @@
|
|
43
43
|
#endif
|
44
44
|
#include <errno.h>
|
45
45
|
#include <ruby.h>
|
46
|
-
#if defined(HAVE_RUBY_THREAD_H)
|
47
46
|
#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)
|
47
|
+
#if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
|
50
48
|
# include <signal.h>
|
51
49
|
# include <pthread.h>
|
52
50
|
#endif
|
@@ -116,7 +114,7 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
116
114
|
Type* paramType = paramTypes[i];
|
117
115
|
int type;
|
118
116
|
|
119
|
-
|
117
|
+
|
120
118
|
if (unlikely(paramType->nativeType == NATIVE_MAPPED)) {
|
121
119
|
VALUE values[] = { argv[argidx], Qnil };
|
122
120
|
argv[argidx] = rb_funcall2(((MappedType *) paramType)->rbConverter, id_to_native, 2, values);
|
@@ -297,13 +295,9 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
297
295
|
|
298
296
|
case NATIVE_STRING:
|
299
297
|
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
|
-
}
|
298
|
+
param->ptr = NULL;
|
306
299
|
|
300
|
+
} else {
|
307
301
|
param->ptr = StringValueCStr(argv[argidx]);
|
308
302
|
}
|
309
303
|
|
@@ -345,23 +339,21 @@ static void *
|
|
345
339
|
call_blocking_function(void* data)
|
346
340
|
{
|
347
341
|
rbffi_blocking_call_t* b = (rbffi_blocking_call_t *) data;
|
348
|
-
b->frame->has_gvl = false;
|
349
342
|
ffi_call(&b->cif, FFI_FN(b->function), b->retval, b->ffiValues);
|
350
|
-
b->frame->has_gvl = true;
|
351
343
|
|
352
344
|
return NULL;
|
353
345
|
}
|
354
346
|
|
355
347
|
VALUE
|
356
|
-
rbffi_do_blocking_call(
|
348
|
+
rbffi_do_blocking_call(VALUE data)
|
357
349
|
{
|
358
|
-
|
350
|
+
rb_thread_call_without_gvl(call_blocking_function, (void*)data, (rb_unblock_function_t *) -1, NULL);
|
359
351
|
|
360
352
|
return Qnil;
|
361
353
|
}
|
362
354
|
|
363
355
|
VALUE
|
364
|
-
rbffi_save_frame_exception(
|
356
|
+
rbffi_save_frame_exception(VALUE data, VALUE exc)
|
365
357
|
{
|
366
358
|
rbffi_frame_t* frame = (rbffi_frame_t *) data;
|
367
359
|
frame->exc = exc;
|
@@ -376,28 +368,17 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
376
368
|
FFIStorage* params;
|
377
369
|
VALUE rbReturnValue;
|
378
370
|
rbffi_frame_t frame = { 0 };
|
379
|
-
|
371
|
+
|
380
372
|
retval = alloca(MAX(fnInfo->ffi_cif.rtype->size, FFI_SIZEOF_ARG));
|
381
|
-
|
373
|
+
|
382
374
|
if (unlikely(fnInfo->blocking)) {
|
383
375
|
rbffi_blocking_call_t* bc;
|
384
376
|
|
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)
|
377
|
+
/* allocate information passed to the blocking function on the stack */
|
390
378
|
ffiValues = ALLOCA_N(void *, fnInfo->parameterCount);
|
391
379
|
params = ALLOCA_N(FFIStorage, fnInfo->parameterCount);
|
392
380
|
bc = ALLOCA_N(rbffi_blocking_call_t, 1);
|
393
381
|
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
382
|
bc->cif = fnInfo->ffi_cif;
|
402
383
|
bc->function = function;
|
403
384
|
bc->ffiValues = ffiValues;
|
@@ -408,18 +389,10 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
408
389
|
fnInfo->parameterCount, fnInfo->parameterTypes, params, ffiValues,
|
409
390
|
fnInfo->callbackParameters, fnInfo->callbackCount, fnInfo->rbEnums);
|
410
391
|
|
411
|
-
rbffi_frame_push(&frame);
|
392
|
+
rbffi_frame_push(&frame);
|
412
393
|
rb_rescue2(rbffi_do_blocking_call, (VALUE) bc, rbffi_save_frame_exception, (VALUE) &frame, rb_eException, (VALUE) 0);
|
413
394
|
rbffi_frame_pop(&frame);
|
414
395
|
|
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
396
|
} else {
|
424
397
|
|
425
398
|
ffiValues = ALLOCA_N(void *, fnInfo->parameterCount);
|
@@ -436,7 +409,7 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
436
409
|
|
437
410
|
if (unlikely(!fnInfo->ignoreErrno)) {
|
438
411
|
rbffi_save_errno();
|
439
|
-
}
|
412
|
+
}
|
440
413
|
|
441
414
|
if (RTEST(frame.exc) && frame.exc != Qnil) {
|
442
415
|
rb_exc_raise(frame.exc);
|
@@ -444,7 +417,7 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
444
417
|
|
445
418
|
RB_GC_GUARD(rbReturnValue) = rbffi_NativeValue_ToRuby(fnInfo->returnType, fnInfo->rbReturnType, retval);
|
446
419
|
RB_GC_GUARD(fnInfo->rbReturnType);
|
447
|
-
|
420
|
+
|
448
421
|
return rbReturnValue;
|
449
422
|
}
|
450
423
|
|
@@ -461,7 +434,7 @@ getPointer(VALUE value, int type)
|
|
461
434
|
return memory != NULL ? memory->address : NULL;
|
462
435
|
|
463
436
|
} else if (type == T_STRING) {
|
464
|
-
|
437
|
+
|
465
438
|
return StringValuePtr(value);
|
466
439
|
|
467
440
|
} 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
@@ -70,9 +70,6 @@
|
|
70
70
|
#ifndef roundup
|
71
71
|
# define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
|
72
72
|
#endif
|
73
|
-
#ifdef _WIN32
|
74
|
-
typedef char* caddr_t;
|
75
|
-
#endif
|
76
73
|
|
77
74
|
typedef struct Memory {
|
78
75
|
void* code;
|
@@ -96,7 +93,7 @@ static bool freePage(void *);
|
|
96
93
|
static bool protectPage(void *);
|
97
94
|
|
98
95
|
ClosurePool*
|
99
|
-
rbffi_ClosurePool_New(int closureSize,
|
96
|
+
rbffi_ClosurePool_New(int closureSize,
|
100
97
|
bool (*prep)(void* ctx, void *code, Closure* closure, char* errbuf, size_t errbufsize),
|
101
98
|
void* ctx)
|
102
99
|
{
|
@@ -107,7 +104,7 @@ rbffi_ClosurePool_New(int closureSize,
|
|
107
104
|
pool->ctx = ctx;
|
108
105
|
pool->prep = prep;
|
109
106
|
pool->refcnt = 1;
|
110
|
-
|
107
|
+
|
111
108
|
return pool;
|
112
109
|
}
|
113
110
|
|
@@ -115,7 +112,7 @@ void
|
|
115
112
|
cleanup_closure_pool(ClosurePool* pool)
|
116
113
|
{
|
117
114
|
Memory* memory;
|
118
|
-
|
115
|
+
|
119
116
|
for (memory = pool->blocks; memory != NULL; ) {
|
120
117
|
Memory* next = memory->next;
|
121
118
|
freePage(memory->code);
|
@@ -142,7 +139,7 @@ rbffi_Closure_Alloc(ClosurePool* pool)
|
|
142
139
|
{
|
143
140
|
Closure *list = NULL;
|
144
141
|
Memory* block = NULL;
|
145
|
-
|
142
|
+
void *code = NULL;
|
146
143
|
char errmsg[256];
|
147
144
|
int nclosures;
|
148
145
|
long trampolineSize;
|
@@ -152,7 +149,7 @@ rbffi_Closure_Alloc(ClosurePool* pool)
|
|
152
149
|
Closure* closure = pool->list;
|
153
150
|
pool->list = pool->list->next;
|
154
151
|
pool->refcnt++;
|
155
|
-
|
152
|
+
|
156
153
|
return closure;
|
157
154
|
}
|
158
155
|
|
@@ -161,17 +158,17 @@ rbffi_Closure_Alloc(ClosurePool* pool)
|
|
161
158
|
block = calloc(1, sizeof(*block));
|
162
159
|
list = calloc(nclosures, sizeof(*list));
|
163
160
|
code = allocatePage();
|
164
|
-
|
161
|
+
|
165
162
|
if (block == NULL || list == NULL || code == NULL) {
|
166
163
|
snprintf(errmsg, sizeof(errmsg), "failed to allocate a page. errno=%d (%s)", errno, strerror(errno));
|
167
164
|
goto error;
|
168
165
|
}
|
169
|
-
|
166
|
+
|
170
167
|
for (i = 0; i < nclosures; ++i) {
|
171
168
|
Closure* closure = &list[i];
|
172
169
|
closure->next = &list[i + 1];
|
173
170
|
closure->pool = pool;
|
174
|
-
closure->code = (code + (i * trampolineSize));
|
171
|
+
closure->code = ((char *)code + (i * trampolineSize));
|
175
172
|
|
176
173
|
if (!(*pool->prep)(pool->ctx, closure->code, closure, errmsg, sizeof(errmsg))) {
|
177
174
|
goto error;
|
@@ -202,7 +199,7 @@ error:
|
|
202
199
|
if (code != NULL) {
|
203
200
|
freePage(code);
|
204
201
|
}
|
205
|
-
|
202
|
+
|
206
203
|
|
207
204
|
rb_raise(rb_eRuntimeError, "%s", errmsg);
|
208
205
|
return NULL;
|
@@ -249,8 +246,8 @@ allocatePage(void)
|
|
249
246
|
#if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__))
|
250
247
|
return VirtualAlloc(NULL, pageSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
251
248
|
#else
|
252
|
-
|
253
|
-
return (page != (
|
249
|
+
void *page = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
250
|
+
return (page != (void *) -1) ? page : NULL;
|
254
251
|
#endif
|
255
252
|
}
|
256
253
|
|
data/ext/ffi_c/DynamicLibrary.c
CHANGED
data/ext/ffi_c/Function.c
CHANGED
@@ -47,9 +47,7 @@
|
|
47
47
|
# endif
|
48
48
|
#endif
|
49
49
|
#include <ruby.h>
|
50
|
-
#if defined(HAVE_RUBY_THREAD_H)
|
51
50
|
#include <ruby/thread.h>
|
52
|
-
#endif
|
53
51
|
|
54
52
|
#include <ffi.h>
|
55
53
|
#if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
|
@@ -90,8 +88,8 @@ static VALUE function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc);
|
|
90
88
|
static void callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data);
|
91
89
|
static bool callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize);
|
92
90
|
static void* callback_with_gvl(void* data);
|
93
|
-
static VALUE invoke_callback(
|
94
|
-
static VALUE save_callback_exception(
|
91
|
+
static VALUE invoke_callback(VALUE data);
|
92
|
+
static VALUE save_callback_exception(VALUE data, VALUE exc);
|
95
93
|
|
96
94
|
#define DEFER_ASYNC_CALLBACK 1
|
97
95
|
|
@@ -101,9 +99,8 @@ static VALUE async_cb_event(void *);
|
|
101
99
|
static VALUE async_cb_call(void *);
|
102
100
|
#endif
|
103
101
|
|
104
|
-
|
105
|
-
extern
|
106
|
-
#endif
|
102
|
+
extern int ruby_thread_has_gvl_p(void);
|
103
|
+
extern int ruby_native_thread_p(void);
|
107
104
|
|
108
105
|
VALUE rbffi_FunctionClass = Qnil;
|
109
106
|
|
@@ -136,15 +133,9 @@ static struct gvl_callback* async_cb_list = NULL;
|
|
136
133
|
# ifndef _WIN32
|
137
134
|
static pthread_mutex_t async_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
|
138
135
|
static pthread_cond_t async_cb_cond = PTHREAD_COND_INITIALIZER;
|
139
|
-
# if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
|
140
|
-
static int async_cb_pipe[2];
|
141
|
-
# endif
|
142
136
|
# else
|
143
137
|
static HANDLE async_cb_cond;
|
144
138
|
static CRITICAL_SECTION async_cb_lock;
|
145
|
-
# if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
|
146
|
-
static int async_cb_pipe[2];
|
147
|
-
# endif
|
148
139
|
# endif
|
149
140
|
#endif
|
150
141
|
|
@@ -323,16 +314,8 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
323
314
|
|
324
315
|
#if defined(DEFER_ASYNC_CALLBACK)
|
325
316
|
if (async_cb_thread == Qnil) {
|
326
|
-
#if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) && defined(_WIN32)
|
327
|
-
_pipe(async_cb_pipe, 1024, O_BINARY);
|
328
|
-
#elif !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
|
329
|
-
pipe(async_cb_pipe);
|
330
|
-
fcntl(async_cb_pipe[0], F_SETFL, fcntl(async_cb_pipe[0], F_GETFL) | O_NONBLOCK);
|
331
|
-
fcntl(async_cb_pipe[1], F_SETFL, fcntl(async_cb_pipe[1], F_GETFL) | O_NONBLOCK);
|
332
|
-
#endif
|
333
317
|
async_cb_thread = rb_thread_create(async_cb_event, NULL);
|
334
318
|
}
|
335
|
-
|
336
319
|
#endif
|
337
320
|
|
338
321
|
fn->closure = rbffi_Closure_Alloc(fn->info->closurePool);
|
@@ -474,13 +457,13 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
474
457
|
cb.frame = rbffi_frame_current();
|
475
458
|
|
476
459
|
if (cb.frame != NULL) cb.frame->exc = Qnil;
|
477
|
-
if (cb.frame != NULL && cb.frame->has_gvl) {
|
478
|
-
callback_with_gvl(&cb);
|
479
460
|
|
480
|
-
|
481
|
-
|
461
|
+
if (ruby_native_thread_p()) {
|
462
|
+
if(ruby_thread_has_gvl_p()) {
|
463
|
+
callback_with_gvl(&cb);
|
464
|
+
} else {
|
482
465
|
rb_thread_call_with_gvl(callback_with_gvl, &cb);
|
483
|
-
|
466
|
+
}
|
484
467
|
#if defined(DEFER_ASYNC_CALLBACK) && !defined(_WIN32)
|
485
468
|
} else {
|
486
469
|
bool empty = false;
|
@@ -494,17 +477,8 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
494
477
|
cb.next = async_cb_list;
|
495
478
|
async_cb_list = &cb;
|
496
479
|
|
497
|
-
#if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
|
498
|
-
pthread_mutex_unlock(&async_cb_mutex);
|
499
|
-
/* Only signal if the list was empty */
|
500
|
-
if (empty) {
|
501
|
-
char c;
|
502
|
-
write(async_cb_pipe[1], &c, 1);
|
503
|
-
}
|
504
|
-
#else
|
505
480
|
pthread_cond_signal(&async_cb_cond);
|
506
481
|
pthread_mutex_unlock(&async_cb_mutex);
|
507
|
-
#endif
|
508
482
|
|
509
483
|
/* Wait for the thread executing the ruby callback to signal it is done */
|
510
484
|
pthread_mutex_lock(&cb.async_mutex);
|
@@ -528,15 +502,7 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
528
502
|
async_cb_list = &cb;
|
529
503
|
LeaveCriticalSection(&async_cb_lock);
|
530
504
|
|
531
|
-
#if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL))
|
532
|
-
/* Only signal if the list was empty */
|
533
|
-
if (empty) {
|
534
|
-
char c;
|
535
|
-
write(async_cb_pipe[1], &c, 1);
|
536
|
-
}
|
537
|
-
#else
|
538
505
|
SetEvent(async_cb_cond);
|
539
|
-
#endif
|
540
506
|
|
541
507
|
/* Wait for the thread executing the ruby callback to signal it is done */
|
542
508
|
WaitForSingleObject(cb.async_event, INFINITE);
|
@@ -554,7 +520,6 @@ struct async_wait {
|
|
554
520
|
static void * async_cb_wait(void *);
|
555
521
|
static void async_cb_stop(void *);
|
556
522
|
|
557
|
-
#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
|
558
523
|
static VALUE
|
559
524
|
async_cb_event(void* unused)
|
560
525
|
{
|
@@ -562,11 +527,7 @@ async_cb_event(void* unused)
|
|
562
527
|
|
563
528
|
w.stop = false;
|
564
529
|
while (!w.stop) {
|
565
|
-
#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
|
566
530
|
rb_thread_call_without_gvl(async_cb_wait, &w, async_cb_stop, &w);
|
567
|
-
#else
|
568
|
-
rb_thread_blocking_region(async_cb_wait, &w, async_cb_stop, &w);
|
569
|
-
#endif
|
570
531
|
if (w.cb != NULL) {
|
571
532
|
/* Start up a new ruby thread to run the ruby callback */
|
572
533
|
rb_thread_create(async_cb_call, w.cb);
|
@@ -576,69 +537,6 @@ async_cb_event(void* unused)
|
|
576
537
|
return Qnil;
|
577
538
|
}
|
578
539
|
|
579
|
-
#elif defined(_WIN32)
|
580
|
-
static VALUE
|
581
|
-
async_cb_event(void* unused)
|
582
|
-
{
|
583
|
-
while (true) {
|
584
|
-
struct gvl_callback* cb;
|
585
|
-
char buf[64];
|
586
|
-
fd_set rfds;
|
587
|
-
|
588
|
-
FD_ZERO(&rfds);
|
589
|
-
FD_SET(async_cb_pipe[0], &rfds);
|
590
|
-
rb_thread_select(async_cb_pipe[0] + 1, &rfds, NULL, NULL, NULL);
|
591
|
-
read(async_cb_pipe[0], buf, sizeof(buf));
|
592
|
-
|
593
|
-
EnterCriticalSection(&async_cb_lock);
|
594
|
-
cb = async_cb_list;
|
595
|
-
async_cb_list = NULL;
|
596
|
-
LeaveCriticalSection(&async_cb_lock);
|
597
|
-
|
598
|
-
while (cb != NULL) {
|
599
|
-
struct gvl_callback* next = cb->next;
|
600
|
-
/* Start up a new ruby thread to run the ruby callback */
|
601
|
-
rb_thread_create(async_cb_call, cb);
|
602
|
-
cb = next;
|
603
|
-
}
|
604
|
-
}
|
605
|
-
|
606
|
-
return Qnil;
|
607
|
-
}
|
608
|
-
#else
|
609
|
-
static VALUE
|
610
|
-
async_cb_event(void* unused)
|
611
|
-
{
|
612
|
-
while (true) {
|
613
|
-
struct gvl_callback* cb;
|
614
|
-
char buf[64];
|
615
|
-
|
616
|
-
if (read(async_cb_pipe[0], buf, sizeof(buf)) < 0) {
|
617
|
-
rb_thread_wait_fd(async_cb_pipe[0]);
|
618
|
-
while (read(async_cb_pipe[0], buf, sizeof (buf)) < 0) {
|
619
|
-
if (rb_io_wait_readable(async_cb_pipe[0]) != Qtrue) {
|
620
|
-
return Qfalse;
|
621
|
-
}
|
622
|
-
}
|
623
|
-
}
|
624
|
-
|
625
|
-
pthread_mutex_lock(&async_cb_mutex);
|
626
|
-
cb = async_cb_list;
|
627
|
-
async_cb_list = NULL;
|
628
|
-
pthread_mutex_unlock(&async_cb_mutex);
|
629
|
-
|
630
|
-
while (cb != NULL) {
|
631
|
-
struct gvl_callback* next = cb->next;
|
632
|
-
/* Start up a new ruby thread to run the ruby callback */
|
633
|
-
rb_thread_create(async_cb_call, cb);
|
634
|
-
cb = next;
|
635
|
-
}
|
636
|
-
}
|
637
|
-
|
638
|
-
return Qnil;
|
639
|
-
}
|
640
|
-
#endif
|
641
|
-
|
642
540
|
#ifdef _WIN32
|
643
541
|
static void *
|
644
542
|
async_cb_wait(void *data)
|
@@ -742,7 +640,7 @@ callback_with_gvl(void* data)
|
|
742
640
|
}
|
743
641
|
|
744
642
|
static VALUE
|
745
|
-
invoke_callback(
|
643
|
+
invoke_callback(VALUE data)
|
746
644
|
{
|
747
645
|
struct gvl_callback* cb = (struct gvl_callback *) data;
|
748
646
|
|
@@ -805,10 +703,10 @@ invoke_callback(void* data)
|
|
805
703
|
param = rb_float_new(*(double *) parameters[i]);
|
806
704
|
break;
|
807
705
|
case NATIVE_LONGDOUBLE:
|
808
|
-
|
706
|
+
param = rbffi_longdouble_new(*(long double *) parameters[i]);
|
809
707
|
break;
|
810
708
|
case NATIVE_STRING:
|
811
|
-
param = (*(void **) parameters[i] != NULL) ?
|
709
|
+
param = (*(void **) parameters[i] != NULL) ? rb_str_new2(*(char **) parameters[i]) : Qnil;
|
812
710
|
break;
|
813
711
|
case NATIVE_POINTER:
|
814
712
|
param = rbffi_Pointer_NewInstance(*(void **) parameters[i]);
|
@@ -877,6 +775,9 @@ invoke_callback(void* data)
|
|
877
775
|
case NATIVE_FLOAT64:
|
878
776
|
*((double *) retval) = NUM2DBL(rbReturnValue);
|
879
777
|
break;
|
778
|
+
case NATIVE_LONGDOUBLE:
|
779
|
+
*((long double *) retval) = rbffi_num2longdouble(rbReturnValue);
|
780
|
+
break;
|
880
781
|
case NATIVE_POINTER:
|
881
782
|
if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_PointerClass)) {
|
882
783
|
*((void **) retval) = ((AbstractMemory *) DATA_PTR(rbReturnValue))->address;
|
@@ -932,7 +833,7 @@ invoke_callback(void* data)
|
|
932
833
|
}
|
933
834
|
|
934
835
|
static VALUE
|
935
|
-
save_callback_exception(
|
836
|
+
save_callback_exception(VALUE data, VALUE exc)
|
936
837
|
{
|
937
838
|
struct gvl_callback* cb = (struct gvl_callback *) data;
|
938
839
|
|
@@ -948,9 +849,9 @@ callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errm
|
|
948
849
|
FunctionType* fnInfo = (FunctionType *) ctx;
|
949
850
|
ffi_status ffiStatus;
|
950
851
|
|
951
|
-
ffiStatus =
|
852
|
+
ffiStatus = ffi_prep_closure_loc(code, &fnInfo->ffi_cif, callback_invoke, closure, code);
|
952
853
|
if (ffiStatus != FFI_OK) {
|
953
|
-
snprintf(errmsg, errmsgsize, "
|
854
|
+
snprintf(errmsg, errmsgsize, "ffi_prep_closure_loc failed. status=%#x", ffiStatus);
|
954
855
|
return false;
|
955
856
|
}
|
956
857
|
|