ffi 1.15.5 → 1.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +54 -0
- data/Gemfile +1 -1
- data/README.md +3 -2
- data/Rakefile +10 -7
- data/ext/ffi_c/AbstractMemory.c +56 -34
- data/ext/ffi_c/AbstractMemory.h +3 -2
- data/ext/ffi_c/ArrayType.c +49 -13
- data/ext/ffi_c/ArrayType.h +1 -0
- data/ext/ffi_c/Buffer.c +86 -29
- data/ext/ffi_c/Call.c +13 -5
- data/ext/ffi_c/DynamicLibrary.c +89 -26
- data/ext/ffi_c/Function.c +238 -98
- data/ext/ffi_c/Function.h +1 -0
- data/ext/ffi_c/FunctionInfo.c +78 -24
- data/ext/ffi_c/LastError.c +25 -7
- data/ext/ffi_c/MappedType.c +66 -23
- data/ext/ffi_c/MappedType.h +0 -2
- data/ext/ffi_c/MemoryPointer.c +34 -7
- data/ext/ffi_c/MethodHandle.c +3 -1
- data/ext/ffi_c/Pointer.c +68 -29
- data/ext/ffi_c/Pointer.h +1 -0
- data/ext/ffi_c/Struct.c +151 -80
- data/ext/ffi_c/Struct.h +7 -4
- data/ext/ffi_c/StructByValue.c +48 -16
- data/ext/ffi_c/StructLayout.c +117 -48
- data/ext/ffi_c/Type.c +104 -36
- data/ext/ffi_c/Type.h +3 -1
- data/ext/ffi_c/Types.c +1 -1
- data/ext/ffi_c/Variadic.c +65 -23
- data/ext/ffi_c/compat.h +22 -22
- data/ext/ffi_c/extconf.rb +19 -2
- data/ext/ffi_c/ffi.c +4 -0
- data/ext/ffi_c/libffi/.appveyor/site.exp +16 -0
- data/ext/ffi_c/libffi/.appveyor/unix-noexec.exp +7 -0
- data/ext/ffi_c/libffi/.appveyor.yml +27 -9
- data/ext/ffi_c/libffi/.ci/build-cross-in-container.sh +18 -0
- data/ext/ffi_c/libffi/{.travis → .ci}/build-in-container.sh +4 -6
- data/ext/ffi_c/libffi/.ci/build.sh +124 -0
- data/ext/ffi_c/libffi/{.travis → .ci}/install.sh +14 -7
- data/ext/ffi_c/libffi/.ci/msvs-detect +1103 -0
- data/ext/ffi_c/libffi/{.travis → .ci}/site.exp +5 -3
- data/ext/ffi_c/libffi/.circleci/config.yml +156 -0
- data/ext/ffi_c/libffi/.github/workflows/build.yml +460 -0
- data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +171 -0
- data/ext/ffi_c/libffi/.gitignore +10 -2
- data/ext/ffi_c/libffi/LICENSE +1 -1
- data/ext/ffi_c/libffi/Makefile.am +12 -5
- data/ext/ffi_c/libffi/Makefile.in +118 -51
- data/ext/ffi_c/libffi/README.md +144 -104
- data/ext/ffi_c/libffi/acinclude.m4 +10 -112
- data/ext/ffi_c/libffi/config.guess +623 -556
- data/ext/ffi_c/libffi/config.sub +75 -34
- data/ext/ffi_c/libffi/configure +4571 -3830
- data/ext/ffi_c/libffi/configure.ac +64 -28
- data/ext/ffi_c/libffi/configure.host +25 -6
- data/ext/ffi_c/libffi/doc/Makefile.in +9 -6
- data/ext/ffi_c/libffi/doc/libffi.texi +82 -33
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/fficonfig.h.in +12 -47
- data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +163 -52
- data/ext/ffi_c/libffi/include/Makefile.am +1 -1
- data/ext/ffi_c/libffi/include/Makefile.in +10 -9
- data/ext/ffi_c/libffi/include/ffi.h.in +54 -50
- data/ext/ffi_c/libffi/include/ffi_cfi.h +21 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +29 -0
- data/ext/ffi_c/libffi/include/tramp.h +45 -0
- data/ext/ffi_c/libffi/install-sh +92 -69
- data/ext/ffi_c/libffi/libtool-version +2 -2
- data/ext/ffi_c/libffi/ltmain.sh +512 -315
- data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +18 -14
- data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +108 -72
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +76 -45
- data/ext/ffi_c/libffi/m4/ax_prepend_flag.m4 +51 -0
- data/ext/ffi_c/libffi/man/Makefile.in +9 -6
- data/ext/ffi_c/libffi/missing +1 -1
- data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +1 -1
- data/ext/ffi_c/libffi/msvcc.sh +1 -1
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +146 -42
- data/ext/ffi_c/libffi/src/aarch64/internal.h +32 -0
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +134 -42
- data/ext/ffi_c/libffi/src/arc/arcompact.S +169 -94
- data/ext/ffi_c/libffi/src/arc/ffi.c +325 -148
- data/ext/ffi_c/libffi/src/arc/ffitarget.h +14 -0
- data/ext/ffi_c/libffi/src/arm/ffi.c +62 -17
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +3 -3
- data/ext/ffi_c/libffi/src/arm/internal.h +10 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +113 -42
- data/ext/ffi_c/libffi/src/closures.c +133 -47
- data/ext/ffi_c/libffi/src/dlmalloc.c +5 -0
- data/ext/ffi_c/libffi/src/ia64/ffi.c +12 -0
- data/ext/ffi_c/libffi/src/ia64/unix.S +20 -2
- data/ext/ffi_c/libffi/src/loongarch64/ffi.c +621 -0
- data/ext/ffi_c/libffi/src/loongarch64/ffitarget.h +82 -0
- data/ext/ffi_c/libffi/src/loongarch64/sysv.S +327 -0
- data/ext/ffi_c/libffi/src/m32r/ffi.c +31 -14
- data/ext/ffi_c/libffi/src/mips/ffi.c +240 -65
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +7 -0
- data/ext/ffi_c/libffi/src/mips/n32.S +137 -28
- data/ext/ffi_c/libffi/src/mips/o32.S +61 -4
- data/ext/ffi_c/libffi/src/moxie/ffi.c +47 -22
- data/ext/ffi_c/libffi/src/or1k/ffi.c +25 -12
- data/ext/ffi_c/libffi/src/pa/ffi.c +32 -33
- data/ext/ffi_c/libffi/src/pa/ffi64.c +614 -0
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +22 -8
- data/ext/ffi_c/libffi/src/pa/hpux32.S +83 -36
- data/ext/ffi_c/libffi/src/pa/hpux64.S +681 -0
- data/ext/ffi_c/libffi/src/pa/linux.S +82 -35
- data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1 -1
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +2 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +2 -0
- data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
- data/ext/ffi_c/libffi/src/prep_cif.c +22 -2
- data/ext/ffi_c/libffi/src/riscv/ffi.c +37 -4
- data/ext/ffi_c/libffi/src/sparc/ffi64.c +16 -0
- data/ext/ffi_c/libffi/src/tramp.c +716 -0
- data/ext/ffi_c/libffi/src/wasm32/ffi.c +934 -0
- data/ext/ffi_c/libffi/src/wasm32/ffitarget.h +62 -0
- data/ext/ffi_c/libffi/src/x86/ffi.c +99 -37
- data/ext/ffi_c/libffi/src/x86/ffi64.c +67 -12
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +9 -5
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +43 -0
- data/ext/ffi_c/libffi/src/x86/internal.h +14 -0
- data/ext/ffi_c/libffi/src/x86/internal64.h +14 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +172 -38
- data/ext/ffi_c/libffi/src/x86/sysv_intel.S +91 -88
- data/ext/ffi_c/libffi/src/x86/unix64.S +96 -6
- data/ext/ffi_c/libffi/src/x86/win64.S +20 -7
- data/ext/ffi_c/libffi/src/xtensa/ffi.c +16 -8
- data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +4 -0
- data/ext/ffi_c/libffi/src/xtensa/sysv.S +26 -16
- data/ext/ffi_c/libffi/testsuite/Makefile.am +127 -114
- data/ext/ffi_c/libffi/testsuite/Makefile.in +137 -121
- data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +54 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +63 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +80 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +48 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/test.html +7 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/test_libffi.py +51 -0
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +43 -21
- data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +5 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/bpo_38748.c +41 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +28 -3
- data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +5 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/s55.c +60 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +8 -9
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_2.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3f.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4f.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_big.c +93 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_small.c +61 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_2H.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_8H.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -119
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_2.c +220 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_3.c +154 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +15 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn0.c +3 -2
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn1.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn2.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn3.c +21 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn4.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn5.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn6.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_loc_fn0.c +7 -6
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_simple.c +6 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_12byte.c +18 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_16byte.c +22 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_18byte.c +24 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_19byte.c +29 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_1_1byte.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte1.c +21 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_24byte.c +35 -3
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_2byte.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3_1byte.c +19 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte1.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte2.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +18 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4_1byte.c +22 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4byte.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5_1_byte.c +29 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5byte.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_64byte.c +24 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6_1_byte.c +28 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6byte.c +24 -2
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7_1_byte.c +39 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7byte.c +25 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_8byte.c +14 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte1.c +14 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte2.c +14 -2
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_double.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_float.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble.c +20 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split.c +40 -25
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split2.c +40 -3
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_pointer.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint16.c +18 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint32.c +18 -3
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint64.c +18 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint16.c +18 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint32.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint64.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_dbls_struct.c +3 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_double_va.c +9 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_float.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble.c +11 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble_va.c +22 -3
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_schar.c +5 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshort.c +6 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshortchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_uchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushort.c +6 -2
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushortchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer.c +5 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer_stack.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_schar.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sint.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sshort.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulonglong.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +1 -138
- data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +21 -21
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct.c +32 -9
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct1.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct10.c +12 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +21 -5
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct12.c +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct13.c +115 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct2.c +10 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct3.c +10 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct4.c +9 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct5.c +9 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct6.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct7.c +9 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct8.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct9.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs1.c +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs2.c +102 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs3.c +101 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium2.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/testclosure.c +6 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest.cc +2 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest_ffi_call.cc +1 -0
- data/ext/ffi_c/libffi.bsd.mk +2 -2
- data/ext/ffi_c/libffi.gnu.mk +2 -2
- data/ext/ffi_c/rbffi.h +1 -1
- data/ffi.gemspec +2 -2
- data/lib/ffi/autopointer.rb +7 -22
- data/lib/ffi/compat.rb +43 -0
- data/lib/ffi/data_converter.rb +2 -2
- data/lib/ffi/dynamic_library.rb +89 -0
- data/lib/ffi/enum.rb +18 -11
- data/lib/ffi/ffi.rb +3 -0
- data/lib/ffi/function.rb +71 -0
- data/lib/ffi/library.rb +55 -71
- data/lib/ffi/library_path.rb +109 -0
- data/lib/ffi/managedstruct.rb +1 -1
- data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
- data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
- data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
- data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
- data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
- data/lib/ffi/platform.rb +15 -13
- data/lib/ffi/struct.rb +2 -1
- data/lib/ffi/struct_layout.rb +1 -1
- data/lib/ffi/struct_layout_builder.rb +1 -1
- data/lib/ffi/types.rb +30 -5
- data/lib/ffi/variadic.rb +19 -8
- data/lib/ffi/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +97 -25
- metadata.gz.sig +1 -0
- data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +0 -14
- data/ext/ffi_c/libffi/.travis/build.sh +0 -142
- data/ext/ffi_c/libffi/.travis.yml +0 -83
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +0 -44
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +0 -44
- /data/ext/ffi_c/libffi/{.travis → .ci}/ar-lib +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/bfin-sim.exp +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/compile +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/m32r-sim.exp +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/moxie-sim.exp +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/or1k-sim.exp +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/powerpc-eabisim.exp +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/wine-sim.exp +0 -0
- /data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
- /data/lib/ffi/platform/{sparc64-linux → sparcv9-linux}/types.conf +0 -0
data/ext/ffi_c/Function.c
CHANGED
@@ -42,6 +42,10 @@
|
|
42
42
|
#include <ruby.h>
|
43
43
|
#include <ruby/thread.h>
|
44
44
|
|
45
|
+
#if HAVE_RB_EXT_RACTOR_SAFE
|
46
|
+
#include <ruby/ractor.h>
|
47
|
+
#endif
|
48
|
+
|
45
49
|
#include <ffi.h>
|
46
50
|
#if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
|
47
51
|
#include <pthread.h>
|
@@ -65,6 +69,9 @@
|
|
65
69
|
#include "MethodHandle.h"
|
66
70
|
#include "Function.h"
|
67
71
|
|
72
|
+
#define DEFER_ASYNC_CALLBACK 1
|
73
|
+
|
74
|
+
struct async_cb_dispatcher;
|
68
75
|
typedef struct Function_ {
|
69
76
|
Pointer base;
|
70
77
|
FunctionType* info;
|
@@ -73,10 +80,15 @@ typedef struct Function_ {
|
|
73
80
|
Closure* closure;
|
74
81
|
VALUE rbProc;
|
75
82
|
VALUE rbFunctionInfo;
|
83
|
+
#if defined(DEFER_ASYNC_CALLBACK)
|
84
|
+
struct async_cb_dispatcher *dispatcher;
|
85
|
+
#endif
|
76
86
|
} Function;
|
77
87
|
|
78
|
-
static void function_mark(
|
79
|
-
static void
|
88
|
+
static void function_mark(void *data);
|
89
|
+
static void function_compact(void *data);
|
90
|
+
static void function_free(void *data);
|
91
|
+
static size_t function_memsize(const void *data);
|
80
92
|
static VALUE function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc);
|
81
93
|
static void callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data);
|
82
94
|
static bool callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize);
|
@@ -84,9 +96,6 @@ static void* callback_with_gvl(void* data);
|
|
84
96
|
static VALUE invoke_callback(VALUE data);
|
85
97
|
static VALUE save_callback_exception(VALUE data, VALUE exc);
|
86
98
|
|
87
|
-
#define DEFER_ASYNC_CALLBACK 1
|
88
|
-
|
89
|
-
|
90
99
|
#if defined(DEFER_ASYNC_CALLBACK)
|
91
100
|
static VALUE async_cb_event(void *);
|
92
101
|
static VALUE async_cb_call(void *);
|
@@ -95,11 +104,21 @@ static VALUE async_cb_call(void *);
|
|
95
104
|
extern int ruby_thread_has_gvl_p(void);
|
96
105
|
extern int ruby_native_thread_p(void);
|
97
106
|
|
98
|
-
|
107
|
+
static const rb_data_type_t function_data_type = {
|
108
|
+
.wrap_struct_name = "FFI::Function",
|
109
|
+
.function = {
|
110
|
+
.dmark = function_mark,
|
111
|
+
.dfree = function_free,
|
112
|
+
.dsize = function_memsize,
|
113
|
+
ffi_compact_callback( function_compact )
|
114
|
+
},
|
115
|
+
.parent = &rbffi_pointer_data_type,
|
116
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
117
|
+
// macro to update VALUE references, as to trigger write barriers.
|
118
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
119
|
+
};
|
99
120
|
|
100
|
-
|
101
|
-
static VALUE async_cb_thread = Qnil;
|
102
|
-
#endif
|
121
|
+
VALUE rbffi_FunctionClass = Qnil;
|
103
122
|
|
104
123
|
static ID id_call = 0, id_to_native = 0, id_from_native = 0, id_cbtable = 0, id_cb_ref = 0;
|
105
124
|
|
@@ -110,7 +129,10 @@ struct gvl_callback {
|
|
110
129
|
bool done;
|
111
130
|
rbffi_frame_t *frame;
|
112
131
|
#if defined(DEFER_ASYNC_CALLBACK)
|
132
|
+
struct async_cb_dispatcher *dispatcher;
|
113
133
|
struct gvl_callback* next;
|
134
|
+
|
135
|
+
/* Signal when the callback has finished and retval is set */
|
114
136
|
# ifndef _WIN32
|
115
137
|
pthread_cond_t async_cond;
|
116
138
|
pthread_mutex_t async_mutex;
|
@@ -122,16 +144,74 @@ struct gvl_callback {
|
|
122
144
|
|
123
145
|
|
124
146
|
#if defined(DEFER_ASYNC_CALLBACK)
|
125
|
-
|
147
|
+
struct async_cb_dispatcher {
|
148
|
+
/* the Ractor-local dispatcher thread */
|
149
|
+
VALUE thread;
|
150
|
+
|
151
|
+
/* single linked list of pending callbacks */
|
152
|
+
struct gvl_callback* async_cb_list;
|
153
|
+
|
154
|
+
/* Signal new entries in async_cb_list */
|
126
155
|
# ifndef _WIN32
|
127
|
-
|
128
|
-
|
156
|
+
pthread_mutex_t async_cb_mutex;
|
157
|
+
pthread_cond_t async_cb_cond;
|
129
158
|
# else
|
130
|
-
|
131
|
-
|
159
|
+
HANDLE async_cb_cond;
|
160
|
+
CRITICAL_SECTION async_cb_lock;
|
132
161
|
# endif
|
133
|
-
|
162
|
+
};
|
163
|
+
|
164
|
+
#if HAVE_RB_EXT_RACTOR_SAFE
|
165
|
+
static void
|
166
|
+
async_cb_dispatcher_mark(void *ptr)
|
167
|
+
{
|
168
|
+
struct async_cb_dispatcher *ctx = (struct async_cb_dispatcher *)ptr;
|
169
|
+
rb_gc_mark(ctx->thread);
|
170
|
+
}
|
171
|
+
|
172
|
+
static void
|
173
|
+
async_cb_dispatcher_free(void *ptr)
|
174
|
+
{
|
175
|
+
struct async_cb_dispatcher *ctx = (struct async_cb_dispatcher *)ptr;
|
176
|
+
xfree(ctx);
|
177
|
+
}
|
178
|
+
|
179
|
+
struct rb_ractor_local_storage_type async_cb_dispatcher_key_type = {
|
180
|
+
async_cb_dispatcher_mark,
|
181
|
+
async_cb_dispatcher_free,
|
182
|
+
};
|
183
|
+
|
184
|
+
static rb_ractor_local_key_t async_cb_dispatcher_key;
|
185
|
+
|
186
|
+
static struct async_cb_dispatcher *
|
187
|
+
async_cb_dispatcher_get(void)
|
188
|
+
{
|
189
|
+
struct async_cb_dispatcher *ctx = (struct async_cb_dispatcher *)rb_ractor_local_storage_ptr(async_cb_dispatcher_key);
|
190
|
+
return ctx;
|
191
|
+
}
|
192
|
+
|
193
|
+
static void
|
194
|
+
async_cb_dispatcher_set(struct async_cb_dispatcher *ctx)
|
195
|
+
{
|
196
|
+
rb_ractor_local_storage_ptr_set(async_cb_dispatcher_key, ctx);
|
197
|
+
}
|
198
|
+
#else
|
199
|
+
// for ruby 2.x
|
200
|
+
static struct async_cb_dispatcher *async_cb_dispatcher = NULL;
|
134
201
|
|
202
|
+
static struct async_cb_dispatcher *
|
203
|
+
async_cb_dispatcher_get(void)
|
204
|
+
{
|
205
|
+
return async_cb_dispatcher;
|
206
|
+
}
|
207
|
+
|
208
|
+
static void
|
209
|
+
async_cb_dispatcher_set(struct async_cb_dispatcher *ctx)
|
210
|
+
{
|
211
|
+
async_cb_dispatcher = ctx;
|
212
|
+
}
|
213
|
+
#endif
|
214
|
+
#endif
|
135
215
|
|
136
216
|
static VALUE
|
137
217
|
function_allocate(VALUE klass)
|
@@ -139,28 +219,39 @@ function_allocate(VALUE klass)
|
|
139
219
|
Function *fn;
|
140
220
|
VALUE obj;
|
141
221
|
|
142
|
-
obj =
|
222
|
+
obj = TypedData_Make_Struct(klass, Function, &function_data_type, fn);
|
143
223
|
|
144
224
|
fn->base.memory.flags = MEM_RD;
|
145
|
-
fn->base.rbParent
|
146
|
-
fn->rbProc
|
147
|
-
fn->rbFunctionInfo
|
225
|
+
RB_OBJ_WRITE(obj, &fn->base.rbParent, Qnil);
|
226
|
+
RB_OBJ_WRITE(obj, &fn->rbProc, Qnil);
|
227
|
+
RB_OBJ_WRITE(obj, &fn->rbFunctionInfo, Qnil);
|
148
228
|
fn->autorelease = true;
|
149
229
|
|
150
230
|
return obj;
|
151
231
|
}
|
152
232
|
|
153
233
|
static void
|
154
|
-
function_mark(
|
234
|
+
function_mark(void *data)
|
155
235
|
{
|
156
|
-
|
157
|
-
|
158
|
-
|
236
|
+
Function *fn = (Function *)data;
|
237
|
+
rb_gc_mark_movable(fn->base.rbParent);
|
238
|
+
rb_gc_mark_movable(fn->rbProc);
|
239
|
+
rb_gc_mark_movable(fn->rbFunctionInfo);
|
159
240
|
}
|
160
241
|
|
161
242
|
static void
|
162
|
-
|
243
|
+
function_compact(void *data)
|
163
244
|
{
|
245
|
+
Function *fn = (Function *)data;
|
246
|
+
ffi_gc_location(fn->base.rbParent);
|
247
|
+
ffi_gc_location(fn->rbProc);
|
248
|
+
ffi_gc_location(fn->rbFunctionInfo);
|
249
|
+
}
|
250
|
+
|
251
|
+
static void
|
252
|
+
function_free(void *data)
|
253
|
+
{
|
254
|
+
Function *fn = (Function *)data;
|
164
255
|
if (fn->methodHandle != NULL) {
|
165
256
|
rbffi_MethodHandle_Free(fn->methodHandle);
|
166
257
|
}
|
@@ -172,6 +263,20 @@ function_free(Function *fn)
|
|
172
263
|
xfree(fn);
|
173
264
|
}
|
174
265
|
|
266
|
+
static size_t
|
267
|
+
function_memsize(const void *data)
|
268
|
+
{
|
269
|
+
const Function *fn = (const Function *)data;
|
270
|
+
size_t memsize = sizeof(Function);
|
271
|
+
|
272
|
+
// Would be nice to better account for MethodHandle and Closure too.
|
273
|
+
if (fn->closure) {
|
274
|
+
memsize += sizeof(Closure);
|
275
|
+
}
|
276
|
+
|
277
|
+
return memsize;
|
278
|
+
}
|
279
|
+
|
175
280
|
/*
|
176
281
|
* @param [Type, Symbol] return_type return type for the function
|
177
282
|
* @param [Array<Type, Symbol>] param_types array of parameters types
|
@@ -254,7 +359,7 @@ rbffi_Function_ForProc(VALUE rbFunctionInfo, VALUE proc)
|
|
254
359
|
/* If the first callback reference has the same function function signature, use it */
|
255
360
|
if (cbref != Qnil && CLASS_OF(cbref) == rbffi_FunctionClass) {
|
256
361
|
Function* fp;
|
257
|
-
|
362
|
+
TypedData_Get_Struct(cbref, Function, &function_data_type, fp);
|
258
363
|
if (fp->rbFunctionInfo == rbFunctionInfo) {
|
259
364
|
return cbref;
|
260
365
|
}
|
@@ -287,9 +392,7 @@ static void
|
|
287
392
|
after_fork_callback(void)
|
288
393
|
{
|
289
394
|
/* Ensure that a new dispatcher thread is started in a forked process */
|
290
|
-
|
291
|
-
pthread_mutex_init(&async_cb_mutex, NULL);
|
292
|
-
pthread_cond_init(&async_cb_cond, NULL);
|
395
|
+
async_cb_dispatcher_set(NULL);
|
293
396
|
}
|
294
397
|
#endif
|
295
398
|
|
@@ -298,17 +401,17 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
298
401
|
{
|
299
402
|
Function* fn = NULL;
|
300
403
|
|
301
|
-
|
404
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
302
405
|
|
303
|
-
fn->rbFunctionInfo
|
406
|
+
RB_OBJ_WRITE(self, &fn->rbFunctionInfo, rbFunctionInfo);
|
304
407
|
|
305
|
-
|
408
|
+
TypedData_Get_Struct(fn->rbFunctionInfo, FunctionType, &rbffi_fntype_data_type, fn->info);
|
306
409
|
|
307
410
|
if (rb_obj_is_kind_of(rbProc, rbffi_PointerClass)) {
|
308
411
|
Pointer* orig;
|
309
|
-
|
412
|
+
TypedData_Get_Struct(rbProc, Pointer, &rbffi_pointer_data_type, orig);
|
310
413
|
fn->base.memory = orig->memory;
|
311
|
-
fn->base.rbParent
|
414
|
+
RB_OBJ_WRITE(self, &fn->base.rbParent, rbProc);
|
312
415
|
|
313
416
|
} else if (rb_obj_is_kind_of(rbProc, rb_cProc) || rb_respond_to(rbProc, id_call)) {
|
314
417
|
if (fn->info->closurePool == NULL) {
|
@@ -319,17 +422,30 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
319
422
|
}
|
320
423
|
|
321
424
|
#if defined(DEFER_ASYNC_CALLBACK)
|
322
|
-
|
425
|
+
{
|
426
|
+
struct async_cb_dispatcher *ctx = async_cb_dispatcher_get();
|
427
|
+
if (ctx == NULL) {
|
428
|
+
ctx = (struct async_cb_dispatcher*)ALLOC(struct async_cb_dispatcher);
|
429
|
+
ctx->async_cb_list = NULL;
|
323
430
|
|
324
431
|
#if !defined(_WIN32)
|
325
|
-
|
326
|
-
|
327
|
-
|
432
|
+
pthread_mutex_init(&ctx->async_cb_mutex, NULL);
|
433
|
+
pthread_cond_init(&ctx->async_cb_cond, NULL);
|
434
|
+
if( pthread_atfork(NULL, NULL, after_fork_callback) ){
|
435
|
+
rb_warn("FFI: unable to register fork callback");
|
436
|
+
}
|
437
|
+
#else
|
438
|
+
InitializeCriticalSection(&ctx->async_cb_lock);
|
439
|
+
ctx->async_cb_cond = CreateEvent(NULL, FALSE, FALSE, NULL);
|
328
440
|
#endif
|
441
|
+
ctx->thread = rb_thread_create(async_cb_event, ctx);
|
329
442
|
|
330
|
-
|
331
|
-
|
332
|
-
|
443
|
+
/* Name thread, for better debugging */
|
444
|
+
rb_funcall(ctx->thread, rb_intern("name="), 1, rb_str_new2("FFI Callback Dispatcher"));
|
445
|
+
|
446
|
+
async_cb_dispatcher_set(ctx);
|
447
|
+
}
|
448
|
+
fn->dispatcher = ctx;
|
333
449
|
}
|
334
450
|
#endif
|
335
451
|
|
@@ -344,7 +460,7 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
344
460
|
rb_obj_classname(rbProc));
|
345
461
|
}
|
346
462
|
|
347
|
-
fn->rbProc
|
463
|
+
RB_OBJ_WRITE(self, &fn->rbProc, rbProc);
|
348
464
|
|
349
465
|
return self;
|
350
466
|
}
|
@@ -360,7 +476,7 @@ function_call(int argc, VALUE* argv, VALUE self)
|
|
360
476
|
{
|
361
477
|
Function* fn;
|
362
478
|
|
363
|
-
|
479
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
364
480
|
|
365
481
|
return (*fn->info->invoke)(argc, argv, fn->base.memory.address, fn->info);
|
366
482
|
}
|
@@ -376,9 +492,9 @@ static VALUE
|
|
376
492
|
function_attach(VALUE self, VALUE module, VALUE name)
|
377
493
|
{
|
378
494
|
Function* fn;
|
379
|
-
char var[1024];
|
380
495
|
|
381
|
-
|
496
|
+
StringValue(name);
|
497
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
382
498
|
|
383
499
|
if (fn->info->parameterCount == -1) {
|
384
500
|
rb_raise(rb_eRuntimeError, "cannot attach variadic functions");
|
@@ -394,12 +510,6 @@ function_attach(VALUE self, VALUE module, VALUE name)
|
|
394
510
|
fn->methodHandle = rbffi_MethodHandle_Alloc(fn->info, fn->base.memory.address);
|
395
511
|
}
|
396
512
|
|
397
|
-
/*
|
398
|
-
* Stash the Function in a module variable so it does not get garbage collected
|
399
|
-
*/
|
400
|
-
snprintf(var, sizeof(var), "@@%s", StringValueCStr(name));
|
401
|
-
rb_cv_set(module, var, self);
|
402
|
-
|
403
513
|
rb_define_singleton_method(module, StringValueCStr(name),
|
404
514
|
rbffi_MethodHandle_CodeAddress(fn->methodHandle), -1);
|
405
515
|
|
@@ -421,7 +531,8 @@ function_set_autorelease(VALUE self, VALUE autorelease)
|
|
421
531
|
{
|
422
532
|
Function* fn;
|
423
533
|
|
424
|
-
|
534
|
+
rb_check_frozen(self);
|
535
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
425
536
|
|
426
537
|
fn->autorelease = RTEST(autorelease);
|
427
538
|
|
@@ -433,11 +544,21 @@ function_autorelease_p(VALUE self)
|
|
433
544
|
{
|
434
545
|
Function* fn;
|
435
546
|
|
436
|
-
|
547
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
437
548
|
|
438
549
|
return fn->autorelease ? Qtrue : Qfalse;
|
439
550
|
}
|
440
551
|
|
552
|
+
static VALUE
|
553
|
+
function_type(VALUE self)
|
554
|
+
{
|
555
|
+
Function* fn;
|
556
|
+
|
557
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
558
|
+
|
559
|
+
return fn->rbFunctionInfo;
|
560
|
+
}
|
561
|
+
|
441
562
|
/*
|
442
563
|
* call-seq: free
|
443
564
|
* @return [self]
|
@@ -448,7 +569,7 @@ function_release(VALUE self)
|
|
448
569
|
{
|
449
570
|
Function* fn;
|
450
571
|
|
451
|
-
|
572
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
452
573
|
|
453
574
|
if (fn->closure == NULL) {
|
454
575
|
rb_raise(rb_eRuntimeError, "cannot free function which was not allocated");
|
@@ -463,6 +584,7 @@ function_release(VALUE self)
|
|
463
584
|
static void
|
464
585
|
callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
465
586
|
{
|
587
|
+
Function* fn;
|
466
588
|
struct gvl_callback cb = { 0 };
|
467
589
|
|
468
590
|
cb.closure = (Closure *) user_data;
|
@@ -470,6 +592,7 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
470
592
|
cb.parameters = parameters;
|
471
593
|
cb.done = false;
|
472
594
|
cb.frame = rbffi_frame_current();
|
595
|
+
fn = (Function *) cb.closure->info;
|
473
596
|
|
474
597
|
if (cb.frame != NULL) cb.frame->exc = Qnil;
|
475
598
|
|
@@ -482,18 +605,19 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
482
605
|
#if defined(DEFER_ASYNC_CALLBACK) && !defined(_WIN32)
|
483
606
|
} else {
|
484
607
|
bool empty = false;
|
608
|
+
struct async_cb_dispatcher *ctx = fn->dispatcher;
|
485
609
|
|
486
610
|
pthread_mutex_init(&cb.async_mutex, NULL);
|
487
611
|
pthread_cond_init(&cb.async_cond, NULL);
|
488
612
|
|
489
|
-
/* Now signal the async callback thread */
|
490
|
-
pthread_mutex_lock(&async_cb_mutex);
|
491
|
-
empty = async_cb_list == NULL;
|
492
|
-
cb.next = async_cb_list;
|
493
|
-
async_cb_list = &cb;
|
613
|
+
/* Now signal the async callback dispatcher thread */
|
614
|
+
pthread_mutex_lock(&ctx->async_cb_mutex);
|
615
|
+
empty = ctx->async_cb_list == NULL;
|
616
|
+
cb.next = ctx->async_cb_list;
|
617
|
+
ctx->async_cb_list = &cb;
|
494
618
|
|
495
|
-
pthread_cond_signal(&async_cb_cond);
|
496
|
-
pthread_mutex_unlock(&async_cb_mutex);
|
619
|
+
pthread_cond_signal(&ctx->async_cb_cond);
|
620
|
+
pthread_mutex_unlock(&ctx->async_cb_mutex);
|
497
621
|
|
498
622
|
/* Wait for the thread executing the ruby callback to signal it is done */
|
499
623
|
pthread_mutex_lock(&cb.async_mutex);
|
@@ -507,17 +631,18 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
507
631
|
#elif defined(DEFER_ASYNC_CALLBACK) && defined(_WIN32)
|
508
632
|
} else {
|
509
633
|
bool empty = false;
|
634
|
+
struct async_cb_dispatcher *ctx = fn->dispatcher;
|
510
635
|
|
511
636
|
cb.async_event = CreateEvent(NULL, FALSE, FALSE, NULL);
|
512
637
|
|
513
|
-
/* Now signal the async callback thread */
|
514
|
-
EnterCriticalSection(&async_cb_lock);
|
515
|
-
empty = async_cb_list == NULL;
|
516
|
-
cb.next = async_cb_list;
|
517
|
-
async_cb_list = &cb;
|
518
|
-
LeaveCriticalSection(&async_cb_lock);
|
638
|
+
/* Now signal the async callback dispatcher thread */
|
639
|
+
EnterCriticalSection(&ctx->async_cb_lock);
|
640
|
+
empty = ctx->async_cb_list == NULL;
|
641
|
+
cb.next = ctx->async_cb_list;
|
642
|
+
ctx->async_cb_list = &cb;
|
643
|
+
LeaveCriticalSection(&ctx->async_cb_lock);
|
519
644
|
|
520
|
-
SetEvent(async_cb_cond);
|
645
|
+
SetEvent(ctx->async_cb_cond);
|
521
646
|
|
522
647
|
/* Wait for the thread executing the ruby callback to signal it is done */
|
523
648
|
WaitForSingleObject(cb.async_event, INFINITE);
|
@@ -528,6 +653,7 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
528
653
|
|
529
654
|
#if defined(DEFER_ASYNC_CALLBACK)
|
530
655
|
struct async_wait {
|
656
|
+
struct async_cb_dispatcher *dispatcher;
|
531
657
|
void* cb;
|
532
658
|
bool stop;
|
533
659
|
};
|
@@ -536,9 +662,10 @@ static void * async_cb_wait(void *);
|
|
536
662
|
static void async_cb_stop(void *);
|
537
663
|
|
538
664
|
static VALUE
|
539
|
-
async_cb_event(void*
|
665
|
+
async_cb_event(void* ptr)
|
540
666
|
{
|
541
|
-
struct
|
667
|
+
struct async_cb_dispatcher *ctx = (struct async_cb_dispatcher *)ptr;
|
668
|
+
struct async_wait w = { ctx };
|
542
669
|
|
543
670
|
w.stop = false;
|
544
671
|
while (!w.stop) {
|
@@ -559,23 +686,24 @@ static void *
|
|
559
686
|
async_cb_wait(void *data)
|
560
687
|
{
|
561
688
|
struct async_wait* w = (struct async_wait *) data;
|
689
|
+
struct async_cb_dispatcher *ctx = w->dispatcher;
|
562
690
|
|
563
691
|
w->cb = NULL;
|
564
692
|
|
565
|
-
EnterCriticalSection(&async_cb_lock);
|
693
|
+
EnterCriticalSection(&ctx->async_cb_lock);
|
566
694
|
|
567
|
-
while (!w->stop && async_cb_list == NULL) {
|
568
|
-
LeaveCriticalSection(&async_cb_lock);
|
569
|
-
WaitForSingleObject(async_cb_cond, INFINITE);
|
570
|
-
EnterCriticalSection(&async_cb_lock);
|
695
|
+
while (!w->stop && ctx->async_cb_list == NULL) {
|
696
|
+
LeaveCriticalSection(&ctx->async_cb_lock);
|
697
|
+
WaitForSingleObject(ctx->async_cb_cond, INFINITE);
|
698
|
+
EnterCriticalSection(&ctx->async_cb_lock);
|
571
699
|
}
|
572
700
|
|
573
|
-
if (async_cb_list != NULL) {
|
574
|
-
w->cb = async_cb_list;
|
575
|
-
async_cb_list = async_cb_list->next;
|
701
|
+
if (ctx->async_cb_list != NULL) {
|
702
|
+
w->cb = ctx->async_cb_list;
|
703
|
+
ctx->async_cb_list = ctx->async_cb_list->next;
|
576
704
|
}
|
577
705
|
|
578
|
-
LeaveCriticalSection(&async_cb_lock);
|
706
|
+
LeaveCriticalSection(&ctx->async_cb_lock);
|
579
707
|
|
580
708
|
return NULL;
|
581
709
|
}
|
@@ -584,11 +712,12 @@ static void
|
|
584
712
|
async_cb_stop(void *data)
|
585
713
|
{
|
586
714
|
struct async_wait* w = (struct async_wait *) data;
|
715
|
+
struct async_cb_dispatcher *ctx = w->dispatcher;
|
587
716
|
|
588
|
-
EnterCriticalSection(&async_cb_lock);
|
717
|
+
EnterCriticalSection(&ctx->async_cb_lock);
|
589
718
|
w->stop = true;
|
590
|
-
LeaveCriticalSection(&async_cb_lock);
|
591
|
-
SetEvent(async_cb_cond);
|
719
|
+
LeaveCriticalSection(&ctx->async_cb_lock);
|
720
|
+
SetEvent(ctx->async_cb_cond);
|
592
721
|
}
|
593
722
|
|
594
723
|
#else
|
@@ -596,21 +725,22 @@ static void *
|
|
596
725
|
async_cb_wait(void *data)
|
597
726
|
{
|
598
727
|
struct async_wait* w = (struct async_wait *) data;
|
728
|
+
struct async_cb_dispatcher *ctx = w->dispatcher;
|
599
729
|
|
600
730
|
w->cb = NULL;
|
601
731
|
|
602
|
-
pthread_mutex_lock(&async_cb_mutex);
|
732
|
+
pthread_mutex_lock(&ctx->async_cb_mutex);
|
603
733
|
|
604
|
-
while (!w->stop && async_cb_list == NULL) {
|
605
|
-
pthread_cond_wait(&async_cb_cond, &async_cb_mutex);
|
734
|
+
while (!w->stop && ctx->async_cb_list == NULL) {
|
735
|
+
pthread_cond_wait(&ctx->async_cb_cond, &ctx->async_cb_mutex);
|
606
736
|
}
|
607
737
|
|
608
|
-
if (async_cb_list != NULL) {
|
609
|
-
w->cb = async_cb_list;
|
610
|
-
async_cb_list = async_cb_list->next;
|
738
|
+
if (ctx->async_cb_list != NULL) {
|
739
|
+
w->cb = ctx->async_cb_list;
|
740
|
+
ctx->async_cb_list = ctx->async_cb_list->next;
|
611
741
|
}
|
612
742
|
|
613
|
-
pthread_mutex_unlock(&async_cb_mutex);
|
743
|
+
pthread_mutex_unlock(&ctx->async_cb_mutex);
|
614
744
|
|
615
745
|
return NULL;
|
616
746
|
}
|
@@ -619,11 +749,12 @@ static void
|
|
619
749
|
async_cb_stop(void *data)
|
620
750
|
{
|
621
751
|
struct async_wait* w = (struct async_wait *) data;
|
752
|
+
struct async_cb_dispatcher *ctx = w->dispatcher;
|
622
753
|
|
623
|
-
pthread_mutex_lock(&async_cb_mutex);
|
754
|
+
pthread_mutex_lock(&ctx->async_cb_mutex);
|
624
755
|
w->stop = true;
|
625
|
-
pthread_cond_signal(&async_cb_cond);
|
626
|
-
pthread_mutex_unlock(&async_cb_mutex);
|
756
|
+
pthread_cond_signal(&ctx->async_cb_cond);
|
757
|
+
pthread_mutex_unlock(&ctx->async_cb_mutex);
|
627
758
|
}
|
628
759
|
#endif
|
629
760
|
|
@@ -796,7 +927,9 @@ invoke_callback(VALUE data)
|
|
796
927
|
break;
|
797
928
|
case NATIVE_POINTER:
|
798
929
|
if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_PointerClass)) {
|
799
|
-
|
930
|
+
AbstractMemory* memory;
|
931
|
+
TypedData_Get_Struct(rbReturnValue, AbstractMemory, &rbffi_abstract_memory_data_type, memory);
|
932
|
+
*((void **) retval) = memory->address;
|
800
933
|
} else {
|
801
934
|
/* Default to returning NULL if not a value pointer object. handles nil case as well */
|
802
935
|
*((void **) retval) = NULL;
|
@@ -809,15 +942,20 @@ invoke_callback(VALUE data)
|
|
809
942
|
|
810
943
|
case NATIVE_FUNCTION:
|
811
944
|
if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_PointerClass)) {
|
945
|
+
AbstractMemory* memory;
|
946
|
+
TypedData_Get_Struct(rbReturnValue, AbstractMemory, &rbffi_abstract_memory_data_type, memory);
|
812
947
|
|
813
|
-
*((void **) retval) =
|
948
|
+
*((void **) retval) = memory->address;
|
814
949
|
|
815
950
|
} else if (rb_obj_is_kind_of(rbReturnValue, rb_cProc) || rb_respond_to(rbReturnValue, id_call)) {
|
816
951
|
VALUE function;
|
817
952
|
|
818
953
|
function = rbffi_Function_ForProc(rbReturnType, rbReturnValue);
|
819
954
|
|
820
|
-
|
955
|
+
AbstractMemory* memory;
|
956
|
+
TypedData_Get_Struct(function, AbstractMemory, &rbffi_abstract_memory_data_type, memory);
|
957
|
+
|
958
|
+
*((void **) retval) = memory->address;
|
821
959
|
} else {
|
822
960
|
*((void **) retval) = NULL;
|
823
961
|
}
|
@@ -825,7 +963,9 @@ invoke_callback(VALUE data)
|
|
825
963
|
|
826
964
|
case NATIVE_STRUCT:
|
827
965
|
if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_StructClass)) {
|
828
|
-
|
966
|
+
Struct* s;
|
967
|
+
TypedData_Get_Struct(rbReturnValue, Struct, &rbffi_struct_data_type, s);
|
968
|
+
AbstractMemory* memory = s->pointer;
|
829
969
|
|
830
970
|
if (memory->address != NULL) {
|
831
971
|
memcpy(retval, memory->address, returnType->ffiType->size);
|
@@ -891,6 +1031,7 @@ rbffi_Function_Init(VALUE moduleFFI)
|
|
891
1031
|
rb_define_method(rbffi_FunctionClass, "attach", function_attach, 2);
|
892
1032
|
rb_define_method(rbffi_FunctionClass, "free", function_release, 0);
|
893
1033
|
rb_define_method(rbffi_FunctionClass, "autorelease=", function_set_autorelease, 1);
|
1034
|
+
rb_define_private_method(rbffi_FunctionClass, "type", function_type, 0);
|
894
1035
|
/*
|
895
1036
|
* call-seq: autorelease
|
896
1037
|
* @return [Boolean]
|
@@ -910,8 +1051,7 @@ rbffi_Function_Init(VALUE moduleFFI)
|
|
910
1051
|
id_cb_ref = rb_intern("@__ffi_callback__");
|
911
1052
|
id_to_native = rb_intern("to_native");
|
912
1053
|
id_from_native = rb_intern("from_native");
|
913
|
-
#if defined(
|
914
|
-
|
915
|
-
async_cb_cond = CreateEvent(NULL, FALSE, FALSE, NULL);
|
1054
|
+
#if defined(DEFER_ASYNC_CALLBACK) && defined(HAVE_RB_EXT_RACTOR_SAFE)
|
1055
|
+
async_cb_dispatcher_key = rb_ractor_local_storage_ptr_newkey(&async_cb_dispatcher_key_type);
|
916
1056
|
#endif
|
917
1057
|
}
|