ffi 1.15.5 → 1.17.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +169 -0
- data/Gemfile +15 -3
- data/README.md +5 -3
- data/Rakefile +30 -12
- data/Steepfile +8 -0
- data/ext/ffi_c/AbstractMemory.c +99 -74
- data/ext/ffi_c/AbstractMemory.h +3 -2
- data/ext/ffi_c/ArrayType.c +51 -15
- data/ext/ffi_c/ArrayType.h +1 -0
- data/ext/ffi_c/Buffer.c +90 -33
- data/ext/ffi_c/Call.c +29 -12
- data/ext/ffi_c/Call.h +3 -2
- data/ext/ffi_c/DynamicLibrary.c +90 -27
- data/ext/ffi_c/Function.c +276 -110
- data/ext/ffi_c/Function.h +1 -0
- data/ext/ffi_c/FunctionInfo.c +81 -25
- data/ext/ffi_c/LastError.c +29 -11
- data/ext/ffi_c/MappedType.c +66 -23
- data/ext/ffi_c/MappedType.h +0 -2
- data/ext/ffi_c/MemoryPointer.c +36 -9
- data/ext/ffi_c/MethodHandle.c +7 -3
- data/ext/ffi_c/Pointer.c +82 -40
- data/ext/ffi_c/Pointer.h +1 -0
- data/ext/ffi_c/Struct.c +166 -84
- data/ext/ffi_c/Struct.h +7 -4
- data/ext/ffi_c/StructByValue.c +48 -16
- data/ext/ffi_c/StructLayout.c +259 -73
- data/ext/ffi_c/Type.c +120 -51
- data/ext/ffi_c/Type.h +3 -1
- data/ext/ffi_c/Types.c +8 -2
- data/ext/ffi_c/Types.h +0 -1
- data/ext/ffi_c/Variadic.c +71 -26
- 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/LICENSE +1 -1
- data/ext/ffi_c/libffi/Makefile.am +28 -16
- data/ext/ffi_c/libffi/Makefile.in +138 -84
- data/ext/ffi_c/libffi/README.md +189 -108
- data/ext/ffi_c/libffi/acinclude.m4 +16 -112
- data/ext/ffi_c/libffi/{.travis/compile → compile} +4 -7
- data/ext/ffi_c/libffi/config.guess +695 -570
- data/ext/ffi_c/libffi/config.sub +217 -95
- data/ext/ffi_c/libffi/configure +4642 -3901
- data/ext/ffi_c/libffi/configure.ac +83 -33
- data/ext/ffi_c/libffi/configure.host +31 -12
- data/ext/ffi_c/libffi/doc/Makefile.in +13 -6
- data/ext/ffi_c/libffi/doc/libffi.texi +108 -36
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/fficonfig.h.in +15 -50
- data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +144 -60
- data/ext/ffi_c/libffi/include/Makefile.am +1 -1
- data/ext/ffi_c/libffi/include/Makefile.in +14 -9
- data/ext/ffi_c/libffi/include/ffi.h.in +73 -60
- data/ext/ffi_c/libffi/include/ffi_cfi.h +23 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +50 -2
- data/ext/ffi_c/libffi/include/tramp.h +45 -0
- data/ext/ffi_c/libffi/install-sh +92 -69
- data/ext/ffi_c/libffi/libffi.map.in +18 -1
- data/ext/ffi_c/libffi/libtool-version +2 -2
- data/ext/ffi_c/libffi/ltmain.sh +518 -333
- data/ext/ffi_c/libffi/m4/asmcfi.m4 +28 -11
- 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_check_compile_flag.m4 +13 -3
- 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 +13 -6
- data/ext/ffi_c/libffi/missing +1 -1
- data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +2 -2
- data/ext/ffi_c/libffi/msvcc.sh +1 -1
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +177 -57
- data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/aarch64/internal.h +78 -0
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +347 -93
- data/ext/ffi_c/libffi/src/arc/arcompact.S +169 -94
- data/ext/ffi_c/libffi/src/arc/ffi.c +328 -147
- 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 +114 -43
- data/ext/ffi_c/libffi/src/closures.c +137 -51
- data/ext/ffi_c/libffi/src/debug.c +2 -2
- data/ext/ffi_c/libffi/src/dlmalloc.c +7 -1
- 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 +624 -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 +250 -67
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +9 -4
- data/ext/ffi_c/libffi/src/mips/n32.S +197 -33
- data/ext/ffi_c/libffi/src/mips/o32.S +65 -4
- data/ext/ffi_c/libffi/src/moxie/ffi.c +47 -22
- data/ext/ffi_c/libffi/src/or1k/ffi.c +27 -14
- 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 +86 -35
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +19 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +36 -24
- data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +27 -20
- data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +26 -16
- data/ext/ffi_c/libffi/src/powerpc/internal.h +10 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +2 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +49 -0
- data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +24 -0
- data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
- data/ext/ffi_c/libffi/src/prep_cif.c +22 -5
- data/ext/ffi_c/libffi/src/riscv/ffi.c +74 -18
- data/ext/ffi_c/libffi/src/riscv/internal.h +7 -0
- data/ext/ffi_c/libffi/src/riscv/sysv.S +24 -0
- data/ext/ffi_c/libffi/src/s390/ffi.c +28 -1
- data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
- data/ext/ffi_c/libffi/src/s390/sysv.S +38 -0
- data/ext/ffi_c/libffi/src/sparc/ffi.c +16 -0
- data/ext/ffi_c/libffi/src/sparc/ffi64.c +23 -1
- data/ext/ffi_c/libffi/src/tramp.c +721 -0
- data/ext/ffi_c/libffi/src/types.c +26 -6
- data/ext/ffi_c/libffi/src/wasm/ffi.c +798 -0
- data/ext/ffi_c/libffi/src/wasm/ffitarget.h +79 -0
- data/ext/ffi_c/libffi/src/x86/ffi.c +102 -37
- data/ext/ffi_c/libffi/src/x86/ffi64.c +71 -13
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +6 -5
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +44 -1
- 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 +173 -41
- data/ext/ffi_c/libffi/src/x86/sysv_intel.S +92 -91
- 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.in +95 -121
- data/ext/ffi_c/libffi.bsd.mk +2 -2
- data/ext/ffi_c/libffi.darwin.mk +2 -2
- data/ext/ffi_c/libffi.gnu.mk +2 -2
- data/ext/ffi_c/libffi.mk +5 -0
- data/ext/ffi_c/rbffi.h +1 -1
- data/ffi.gemspec +9 -8
- data/lib/ffi/autopointer.rb +14 -31
- data/lib/ffi/compat.rb +54 -0
- data/lib/ffi/data_converter.rb +2 -2
- data/lib/ffi/dynamic_library.rb +118 -0
- data/lib/ffi/enum.rb +18 -12
- data/lib/ffi/ffi.rb +62 -0
- data/lib/ffi/function.rb +94 -0
- data/lib/ffi/io.rb +2 -2
- data/lib/ffi/library.rb +88 -88
- data/lib/ffi/library_path.rb +109 -0
- data/lib/ffi/managedstruct.rb +1 -1
- data/lib/ffi/platform/aarch64-linux/types.conf +74 -3
- 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/pointer.rb +6 -6
- data/lib/ffi/struct.rb +6 -5
- data/lib/ffi/struct_by_reference.rb +1 -1
- data/lib/ffi/struct_layout.rb +3 -3
- data/lib/ffi/struct_layout_builder.rb +9 -9
- data/lib/ffi/types.rb +65 -37
- data/lib/ffi/variadic.rb +19 -8
- data/lib/ffi/version.rb +1 -1
- data/samples/hello_ractor.rb +19 -0
- data/samples/qsort_ractor.rb +36 -0
- data/sig/ffi/abstract_memory.rbs +165 -0
- data/sig/ffi/auto_pointer.rbs +26 -0
- data/sig/ffi/buffer.rbs +18 -0
- data/sig/ffi/data_converter.rbs +10 -0
- data/sig/ffi/dynamic_library.rbs +9 -0
- data/sig/ffi/enum.rbs +38 -0
- data/sig/ffi/errno.rbs +8 -0
- data/sig/ffi/function.rbs +39 -0
- data/sig/ffi/library.rbs +42 -0
- data/sig/ffi/native_type.rbs +86 -0
- data/sig/ffi/platform.rbs +49 -0
- data/sig/ffi/pointer.rbs +42 -0
- data/sig/ffi/struct.rbs +76 -0
- data/sig/ffi/struct_by_reference.rbs +11 -0
- data/sig/ffi/struct_by_value.rbs +7 -0
- data/sig/ffi/struct_layout.rbs +9 -0
- data/sig/ffi/struct_layout_builder.rbs +5 -0
- data/sig/ffi/type.rbs +39 -0
- data/sig/ffi.rbs +29 -0
- data.tar.gz.sig +0 -0
- metadata +79 -299
- metadata.gz.sig +0 -0
- data/ext/ffi_c/libffi/.appveyor.yml +0 -66
- data/ext/ffi_c/libffi/.gitattributes +0 -4
- data/ext/ffi_c/libffi/.github/issue_template.md +0 -10
- data/ext/ffi_c/libffi/.gitignore +0 -38
- data/ext/ffi_c/libffi/.travis/ar-lib +0 -270
- data/ext/ffi_c/libffi/.travis/bfin-sim.exp +0 -58
- data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +0 -14
- data/ext/ffi_c/libffi/.travis/build-in-container.sh +0 -12
- data/ext/ffi_c/libffi/.travis/build.sh +0 -142
- data/ext/ffi_c/libffi/.travis/install.sh +0 -71
- data/ext/ffi_c/libffi/.travis/m32r-sim.exp +0 -58
- data/ext/ffi_c/libffi/.travis/moxie-sim.exp +0 -60
- data/ext/ffi_c/libffi/.travis/or1k-sim.exp +0 -58
- data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +0 -58
- data/ext/ffi_c/libffi/.travis/site.exp +0 -27
- data/ext/ffi_c/libffi/.travis/wine-sim.exp +0 -55
- data/ext/ffi_c/libffi/.travis.yml +0 -83
- data/ext/ffi_c/libffi/src/nios2/ffi.c +0 -304
- data/ext/ffi_c/libffi/src/nios2/ffitarget.h +0 -52
- data/ext/ffi_c/libffi/src/nios2/sysv.S +0 -136
- data/ext/ffi_c/libffi/testsuite/Makefile.am +0 -122
- data/ext/ffi_c/libffi/testsuite/config/default.exp +0 -1
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +0 -660
- data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +0 -283
- data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +0 -45
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/Makefile +0 -28
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/README +0 -78
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/alignof.h +0 -50
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +0 -63
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +0 -1745
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +0 -2885
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +0 -743
- data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +0 -46
- data/ext/ffi_c/libffi/testsuite/libffi.call/align_stdcall.c +0 -46
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +0 -54
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +0 -26
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +0 -138
- data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +0 -59
- data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +0 -60
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +0 -61
- data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +0 -74
- data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +0 -62
- data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +0 -107
- data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +0 -59
- data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +0 -57
- data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +0 -70
- data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +0 -78
- data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +0 -52
- data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +0 -46
- data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +0 -127
- data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +0 -59
- data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +0 -114
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +0 -36
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +0 -43
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +0 -42
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +0 -35
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +0 -36
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +0 -49
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +0 -42
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +0 -34
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +0 -41
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +0 -43
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +0 -36
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +0 -38
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +0 -38
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +0 -38
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +0 -44
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +0 -49
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +0 -49
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +0 -55
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +0 -67
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +0 -57
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +0 -67
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +0 -60
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +0 -64
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +0 -66
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +0 -64
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +0 -74
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +0 -81
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +0 -68
- data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +0 -61
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +0 -196
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +0 -121
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +0 -123
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +0 -125
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure.exp +0 -67
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn0.c +0 -89
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn1.c +0 -81
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn2.c +0 -81
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn3.c +0 -82
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn4.c +0 -89
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn5.c +0 -92
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn6.c +0 -90
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_loc_fn0.c +0 -95
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_simple.c +0 -55
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_12byte.c +0 -94
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_16byte.c +0 -95
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_18byte.c +0 -96
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_19byte.c +0 -102
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_1_1byte.c +0 -89
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte.c +0 -91
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte1.c +0 -93
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_24byte.c +0 -113
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_2byte.c +0 -90
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3_1byte.c +0 -95
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte1.c +0 -90
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte2.c +0 -90
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +0 -95
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4_1byte.c +0 -98
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4byte.c +0 -90
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5_1_byte.c +0 -109
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5byte.c +0 -98
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_64byte.c +0 -124
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6_1_byte.c +0 -113
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6byte.c +0 -99
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7_1_byte.c +0 -117
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7byte.c +0 -97
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_8byte.c +0 -88
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte1.c +0 -90
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte2.c +0 -91
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_double.c +0 -93
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_float.c +0 -91
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble.c +0 -92
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split.c +0 -132
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split2.c +0 -115
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_pointer.c +0 -95
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint16.c +0 -91
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint32.c +0 -91
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint64.c +0 -92
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint16.c +0 -91
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint32.c +0 -91
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint64.c +0 -93
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_dbls_struct.c +0 -66
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_double.c +0 -43
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_double_va.c +0 -61
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_float.c +0 -42
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble.c +0 -105
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble_va.c +0 -61
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_many_mixed_args.c +0 -70
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_many_mixed_float_double.c +0 -55
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_schar.c +0 -74
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshort.c +0 -74
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshortchar.c +0 -86
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_uchar.c +0 -91
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushort.c +0 -74
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushortchar.c +0 -86
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer.c +0 -74
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer_stack.c +0 -142
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_schar.c +0 -44
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sint.c +0 -42
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sshort.c +0 -42
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +0 -114
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar.c +0 -42
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +0 -44
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint.c +0 -43
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +0 -45
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +0 -45
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulonglong.c +0 -47
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort.c +0 -43
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +0 -44
- data/ext/ffi_c/libffi/testsuite/libffi.closures/err_bad_abi.c +0 -36
- data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +0 -138
- data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +0 -343
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct.c +0 -152
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct1.c +0 -161
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct10.c +0 -134
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +0 -121
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct2.c +0 -110
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct3.c +0 -111
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct4.c +0 -111
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct5.c +0 -112
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct6.c +0 -131
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct7.c +0 -111
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct8.c +0 -131
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct9.c +0 -131
- data/ext/ffi_c/libffi/testsuite/libffi.closures/problem1.c +0 -90
- data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_large.c +0 -145
- data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_large2.c +0 -148
- data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium.c +0 -124
- data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium2.c +0 -125
- data/ext/ffi_c/libffi/testsuite/libffi.closures/testclosure.c +0 -70
- data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest.cc +0 -117
- data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest_ffi_call.cc +0 -54
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +0 -91
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +0 -42
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +0 -71
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +0 -80
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +0 -16
- data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.exp +0 -36
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +0 -51
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +0 -7
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +0 -7
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +0 -7
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +0 -86
- data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +0 -1
- data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +0 -78
- data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +0 -37
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +0 -41
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +0 -44
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +0 -10
- data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +0 -34
- data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +0 -28
- data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +0 -1
- data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +0 -36
- data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +0 -19
- data/lib/ffi/tools/types_generator.rb +0 -137
- data/rakelib/ffi_gem_helper.rb +0 -65
- /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,126 @@ 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
|
|
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
|
+
if (ctx) {
|
|
170
|
+
rb_gc_mark(ctx->thread);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static void
|
|
175
|
+
async_cb_dispatcher_free(void *ptr)
|
|
176
|
+
{
|
|
177
|
+
struct async_cb_dispatcher *ctx = (struct async_cb_dispatcher *)ptr;
|
|
178
|
+
if (ctx) {
|
|
179
|
+
xfree(ctx);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
struct rb_ractor_local_storage_type async_cb_dispatcher_key_type = {
|
|
184
|
+
async_cb_dispatcher_mark,
|
|
185
|
+
async_cb_dispatcher_free,
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
static rb_ractor_local_key_t async_cb_dispatcher_key;
|
|
189
|
+
|
|
190
|
+
static struct async_cb_dispatcher *
|
|
191
|
+
async_cb_dispatcher_get(void)
|
|
192
|
+
{
|
|
193
|
+
struct async_cb_dispatcher *ctx = (struct async_cb_dispatcher *)rb_ractor_local_storage_ptr(async_cb_dispatcher_key);
|
|
194
|
+
return ctx;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
static void
|
|
198
|
+
async_cb_dispatcher_set(struct async_cb_dispatcher *ctx)
|
|
199
|
+
{
|
|
200
|
+
rb_ractor_local_storage_ptr_set(async_cb_dispatcher_key, ctx);
|
|
201
|
+
}
|
|
202
|
+
#else
|
|
203
|
+
// for ruby 2.x
|
|
204
|
+
static struct async_cb_dispatcher *async_cb_dispatcher = NULL;
|
|
205
|
+
|
|
206
|
+
static struct async_cb_dispatcher *
|
|
207
|
+
async_cb_dispatcher_get(void)
|
|
208
|
+
{
|
|
209
|
+
return async_cb_dispatcher;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
static void
|
|
213
|
+
async_cb_dispatcher_set(struct async_cb_dispatcher *ctx)
|
|
214
|
+
{
|
|
215
|
+
async_cb_dispatcher = ctx;
|
|
216
|
+
}
|
|
217
|
+
#endif
|
|
218
|
+
|
|
219
|
+
static void
|
|
220
|
+
async_cb_dispatcher_initialize(struct async_cb_dispatcher *ctx)
|
|
221
|
+
{
|
|
222
|
+
ctx->async_cb_list = NULL;
|
|
223
|
+
|
|
224
|
+
#if !defined(_WIN32)
|
|
225
|
+
/* n.b. we _used_ to try and destroy the mutex/cond before initializing here,
|
|
226
|
+
* but it's undefined what happens if you try and destory an unitialized cond.
|
|
227
|
+
* glibc in particular seems to wait for any concurrent waiters to finish before
|
|
228
|
+
* destroying a condvar, trying to destroy a condvar after fork that someone was
|
|
229
|
+
* waiting on pre-fork won't work. Just re-init he memory directly. */
|
|
230
|
+
pthread_mutex_init(&ctx->async_cb_mutex, NULL);
|
|
231
|
+
pthread_cond_init(&ctx->async_cb_cond, NULL);
|
|
232
|
+
#else
|
|
233
|
+
InitializeCriticalSection(&ctx->async_cb_lock);
|
|
234
|
+
ctx->async_cb_cond = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
133
235
|
#endif
|
|
236
|
+
ctx->thread = rb_thread_create(async_cb_event, ctx);
|
|
237
|
+
|
|
238
|
+
/* Name thread, for better debugging */
|
|
239
|
+
rb_funcall(ctx->thread, rb_intern("name="), 1, rb_str_new2("FFI Callback Dispatcher"));
|
|
240
|
+
/* Advise multi-threaded app servers to ignore this thread for the purposes of fork safety warnings */
|
|
241
|
+
rb_funcall(ctx->thread, rb_intern("thread_variable_set"), 2, ID2SYM(rb_intern("fork_safe")), Qtrue);
|
|
242
|
+
}
|
|
134
243
|
|
|
244
|
+
static struct async_cb_dispatcher *
|
|
245
|
+
async_cb_dispatcher_ensure_created(void)
|
|
246
|
+
{
|
|
247
|
+
struct async_cb_dispatcher *ctx = async_cb_dispatcher_get();
|
|
248
|
+
if (ctx == NULL) {
|
|
249
|
+
ctx = (struct async_cb_dispatcher*)ALLOC(struct async_cb_dispatcher);
|
|
250
|
+
async_cb_dispatcher_initialize(ctx);
|
|
251
|
+
async_cb_dispatcher_set(ctx);
|
|
252
|
+
}
|
|
253
|
+
return ctx;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
static VALUE
|
|
258
|
+
async_cb_dispatcher_atfork_child(VALUE self)
|
|
259
|
+
{
|
|
260
|
+
struct async_cb_dispatcher *ctx = async_cb_dispatcher_get();
|
|
261
|
+
if (ctx) {
|
|
262
|
+
async_cb_dispatcher_initialize(ctx);
|
|
263
|
+
}
|
|
264
|
+
return Qnil;
|
|
265
|
+
}
|
|
266
|
+
#endif
|
|
135
267
|
|
|
136
268
|
static VALUE
|
|
137
269
|
function_allocate(VALUE klass)
|
|
@@ -139,28 +271,39 @@ function_allocate(VALUE klass)
|
|
|
139
271
|
Function *fn;
|
|
140
272
|
VALUE obj;
|
|
141
273
|
|
|
142
|
-
obj =
|
|
274
|
+
obj = TypedData_Make_Struct(klass, Function, &function_data_type, fn);
|
|
143
275
|
|
|
144
276
|
fn->base.memory.flags = MEM_RD;
|
|
145
|
-
fn->base.rbParent
|
|
146
|
-
fn->rbProc
|
|
147
|
-
fn->rbFunctionInfo
|
|
277
|
+
RB_OBJ_WRITE(obj, &fn->base.rbParent, Qnil);
|
|
278
|
+
RB_OBJ_WRITE(obj, &fn->rbProc, Qnil);
|
|
279
|
+
RB_OBJ_WRITE(obj, &fn->rbFunctionInfo, Qnil);
|
|
148
280
|
fn->autorelease = true;
|
|
149
281
|
|
|
150
282
|
return obj;
|
|
151
283
|
}
|
|
152
284
|
|
|
153
285
|
static void
|
|
154
|
-
function_mark(
|
|
286
|
+
function_mark(void *data)
|
|
155
287
|
{
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
288
|
+
Function *fn = (Function *)data;
|
|
289
|
+
rb_gc_mark_movable(fn->base.rbParent);
|
|
290
|
+
rb_gc_mark_movable(fn->rbProc);
|
|
291
|
+
rb_gc_mark_movable(fn->rbFunctionInfo);
|
|
159
292
|
}
|
|
160
293
|
|
|
161
294
|
static void
|
|
162
|
-
|
|
295
|
+
function_compact(void *data)
|
|
163
296
|
{
|
|
297
|
+
Function *fn = (Function *)data;
|
|
298
|
+
ffi_gc_location(fn->base.rbParent);
|
|
299
|
+
ffi_gc_location(fn->rbProc);
|
|
300
|
+
ffi_gc_location(fn->rbFunctionInfo);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
static void
|
|
304
|
+
function_free(void *data)
|
|
305
|
+
{
|
|
306
|
+
Function *fn = (Function *)data;
|
|
164
307
|
if (fn->methodHandle != NULL) {
|
|
165
308
|
rbffi_MethodHandle_Free(fn->methodHandle);
|
|
166
309
|
}
|
|
@@ -172,6 +315,20 @@ function_free(Function *fn)
|
|
|
172
315
|
xfree(fn);
|
|
173
316
|
}
|
|
174
317
|
|
|
318
|
+
static size_t
|
|
319
|
+
function_memsize(const void *data)
|
|
320
|
+
{
|
|
321
|
+
const Function *fn = (const Function *)data;
|
|
322
|
+
size_t memsize = sizeof(Function);
|
|
323
|
+
|
|
324
|
+
// Would be nice to better account for MethodHandle and Closure too.
|
|
325
|
+
if (fn->closure) {
|
|
326
|
+
memsize += sizeof(Closure);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return memsize;
|
|
330
|
+
}
|
|
331
|
+
|
|
175
332
|
/*
|
|
176
333
|
* @param [Type, Symbol] return_type return type for the function
|
|
177
334
|
* @param [Array<Type, Symbol>] param_types array of parameters types
|
|
@@ -254,7 +411,7 @@ rbffi_Function_ForProc(VALUE rbFunctionInfo, VALUE proc)
|
|
|
254
411
|
/* If the first callback reference has the same function function signature, use it */
|
|
255
412
|
if (cbref != Qnil && CLASS_OF(cbref) == rbffi_FunctionClass) {
|
|
256
413
|
Function* fp;
|
|
257
|
-
|
|
414
|
+
TypedData_Get_Struct(cbref, Function, &function_data_type, fp);
|
|
258
415
|
if (fp->rbFunctionInfo == rbFunctionInfo) {
|
|
259
416
|
return cbref;
|
|
260
417
|
}
|
|
@@ -282,33 +439,22 @@ rbffi_Function_ForProc(VALUE rbFunctionInfo, VALUE proc)
|
|
|
282
439
|
return callback;
|
|
283
440
|
}
|
|
284
441
|
|
|
285
|
-
#if !defined(_WIN32) && defined(DEFER_ASYNC_CALLBACK)
|
|
286
|
-
static void
|
|
287
|
-
after_fork_callback(void)
|
|
288
|
-
{
|
|
289
|
-
/* Ensure that a new dispatcher thread is started in a forked process */
|
|
290
|
-
async_cb_thread = Qnil;
|
|
291
|
-
pthread_mutex_init(&async_cb_mutex, NULL);
|
|
292
|
-
pthread_cond_init(&async_cb_cond, NULL);
|
|
293
|
-
}
|
|
294
|
-
#endif
|
|
295
|
-
|
|
296
442
|
static VALUE
|
|
297
443
|
function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
298
444
|
{
|
|
299
445
|
Function* fn = NULL;
|
|
300
446
|
|
|
301
|
-
|
|
447
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
|
302
448
|
|
|
303
|
-
fn->rbFunctionInfo
|
|
449
|
+
RB_OBJ_WRITE(self, &fn->rbFunctionInfo, rbFunctionInfo);
|
|
304
450
|
|
|
305
|
-
|
|
451
|
+
TypedData_Get_Struct(fn->rbFunctionInfo, FunctionType, &rbffi_fntype_data_type, fn->info);
|
|
306
452
|
|
|
307
453
|
if (rb_obj_is_kind_of(rbProc, rbffi_PointerClass)) {
|
|
308
454
|
Pointer* orig;
|
|
309
|
-
|
|
455
|
+
TypedData_Get_Struct(rbProc, Pointer, &rbffi_pointer_data_type, orig);
|
|
310
456
|
fn->base.memory = orig->memory;
|
|
311
|
-
fn->base.rbParent
|
|
457
|
+
RB_OBJ_WRITE(self, &fn->base.rbParent, rbProc);
|
|
312
458
|
|
|
313
459
|
} else if (rb_obj_is_kind_of(rbProc, rb_cProc) || rb_respond_to(rbProc, id_call)) {
|
|
314
460
|
if (fn->info->closurePool == NULL) {
|
|
@@ -319,18 +465,7 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
|
319
465
|
}
|
|
320
466
|
|
|
321
467
|
#if defined(DEFER_ASYNC_CALLBACK)
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
#if !defined(_WIN32)
|
|
325
|
-
if( pthread_atfork(NULL, NULL, after_fork_callback) ){
|
|
326
|
-
rb_warn("FFI: unable to register fork callback");
|
|
327
|
-
}
|
|
328
|
-
#endif
|
|
329
|
-
|
|
330
|
-
async_cb_thread = rb_thread_create(async_cb_event, NULL);
|
|
331
|
-
/* Name thread, for better debugging */
|
|
332
|
-
rb_funcall(async_cb_thread, rb_intern("name="), 1, rb_str_new2("FFI Callback Dispatcher"));
|
|
333
|
-
}
|
|
468
|
+
fn->dispatcher = async_cb_dispatcher_ensure_created();
|
|
334
469
|
#endif
|
|
335
470
|
|
|
336
471
|
fn->closure = rbffi_Closure_Alloc(fn->info->closurePool);
|
|
@@ -344,7 +479,7 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
|
344
479
|
rb_obj_classname(rbProc));
|
|
345
480
|
}
|
|
346
481
|
|
|
347
|
-
fn->rbProc
|
|
482
|
+
RB_OBJ_WRITE(self, &fn->rbProc, rbProc);
|
|
348
483
|
|
|
349
484
|
return self;
|
|
350
485
|
}
|
|
@@ -360,7 +495,7 @@ function_call(int argc, VALUE* argv, VALUE self)
|
|
|
360
495
|
{
|
|
361
496
|
Function* fn;
|
|
362
497
|
|
|
363
|
-
|
|
498
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
|
364
499
|
|
|
365
500
|
return (*fn->info->invoke)(argc, argv, fn->base.memory.address, fn->info);
|
|
366
501
|
}
|
|
@@ -376,9 +511,9 @@ static VALUE
|
|
|
376
511
|
function_attach(VALUE self, VALUE module, VALUE name)
|
|
377
512
|
{
|
|
378
513
|
Function* fn;
|
|
379
|
-
char var[1024];
|
|
380
514
|
|
|
381
|
-
|
|
515
|
+
StringValue(name);
|
|
516
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
|
382
517
|
|
|
383
518
|
if (fn->info->parameterCount == -1) {
|
|
384
519
|
rb_raise(rb_eRuntimeError, "cannot attach variadic functions");
|
|
@@ -394,12 +529,6 @@ function_attach(VALUE self, VALUE module, VALUE name)
|
|
|
394
529
|
fn->methodHandle = rbffi_MethodHandle_Alloc(fn->info, fn->base.memory.address);
|
|
395
530
|
}
|
|
396
531
|
|
|
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
532
|
rb_define_singleton_method(module, StringValueCStr(name),
|
|
404
533
|
rbffi_MethodHandle_CodeAddress(fn->methodHandle), -1);
|
|
405
534
|
|
|
@@ -421,7 +550,8 @@ function_set_autorelease(VALUE self, VALUE autorelease)
|
|
|
421
550
|
{
|
|
422
551
|
Function* fn;
|
|
423
552
|
|
|
424
|
-
|
|
553
|
+
rb_check_frozen(self);
|
|
554
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
|
425
555
|
|
|
426
556
|
fn->autorelease = RTEST(autorelease);
|
|
427
557
|
|
|
@@ -433,11 +563,21 @@ function_autorelease_p(VALUE self)
|
|
|
433
563
|
{
|
|
434
564
|
Function* fn;
|
|
435
565
|
|
|
436
|
-
|
|
566
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
|
437
567
|
|
|
438
568
|
return fn->autorelease ? Qtrue : Qfalse;
|
|
439
569
|
}
|
|
440
570
|
|
|
571
|
+
static VALUE
|
|
572
|
+
function_type(VALUE self)
|
|
573
|
+
{
|
|
574
|
+
Function* fn;
|
|
575
|
+
|
|
576
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
|
577
|
+
|
|
578
|
+
return fn->rbFunctionInfo;
|
|
579
|
+
}
|
|
580
|
+
|
|
441
581
|
/*
|
|
442
582
|
* call-seq: free
|
|
443
583
|
* @return [self]
|
|
@@ -448,7 +588,7 @@ function_release(VALUE self)
|
|
|
448
588
|
{
|
|
449
589
|
Function* fn;
|
|
450
590
|
|
|
451
|
-
|
|
591
|
+
TypedData_Get_Struct(self, Function, &function_data_type, fn);
|
|
452
592
|
|
|
453
593
|
if (fn->closure == NULL) {
|
|
454
594
|
rb_raise(rb_eRuntimeError, "cannot free function which was not allocated");
|
|
@@ -463,6 +603,7 @@ function_release(VALUE self)
|
|
|
463
603
|
static void
|
|
464
604
|
callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
465
605
|
{
|
|
606
|
+
Function* fn;
|
|
466
607
|
struct gvl_callback cb = { 0 };
|
|
467
608
|
|
|
468
609
|
cb.closure = (Closure *) user_data;
|
|
@@ -470,6 +611,7 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
|
470
611
|
cb.parameters = parameters;
|
|
471
612
|
cb.done = false;
|
|
472
613
|
cb.frame = rbffi_frame_current();
|
|
614
|
+
fn = (Function *) cb.closure->info;
|
|
473
615
|
|
|
474
616
|
if (cb.frame != NULL) cb.frame->exc = Qnil;
|
|
475
617
|
|
|
@@ -482,18 +624,19 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
|
482
624
|
#if defined(DEFER_ASYNC_CALLBACK) && !defined(_WIN32)
|
|
483
625
|
} else {
|
|
484
626
|
bool empty = false;
|
|
627
|
+
struct async_cb_dispatcher *ctx = fn->dispatcher;
|
|
485
628
|
|
|
486
629
|
pthread_mutex_init(&cb.async_mutex, NULL);
|
|
487
630
|
pthread_cond_init(&cb.async_cond, NULL);
|
|
488
631
|
|
|
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;
|
|
632
|
+
/* Now signal the async callback dispatcher thread */
|
|
633
|
+
pthread_mutex_lock(&ctx->async_cb_mutex);
|
|
634
|
+
empty = ctx->async_cb_list == NULL;
|
|
635
|
+
cb.next = ctx->async_cb_list;
|
|
636
|
+
ctx->async_cb_list = &cb;
|
|
494
637
|
|
|
495
|
-
pthread_cond_signal(&async_cb_cond);
|
|
496
|
-
pthread_mutex_unlock(&async_cb_mutex);
|
|
638
|
+
pthread_cond_signal(&ctx->async_cb_cond);
|
|
639
|
+
pthread_mutex_unlock(&ctx->async_cb_mutex);
|
|
497
640
|
|
|
498
641
|
/* Wait for the thread executing the ruby callback to signal it is done */
|
|
499
642
|
pthread_mutex_lock(&cb.async_mutex);
|
|
@@ -507,17 +650,18 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
|
507
650
|
#elif defined(DEFER_ASYNC_CALLBACK) && defined(_WIN32)
|
|
508
651
|
} else {
|
|
509
652
|
bool empty = false;
|
|
653
|
+
struct async_cb_dispatcher *ctx = fn->dispatcher;
|
|
510
654
|
|
|
511
655
|
cb.async_event = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
512
656
|
|
|
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);
|
|
657
|
+
/* Now signal the async callback dispatcher thread */
|
|
658
|
+
EnterCriticalSection(&ctx->async_cb_lock);
|
|
659
|
+
empty = ctx->async_cb_list == NULL;
|
|
660
|
+
cb.next = ctx->async_cb_list;
|
|
661
|
+
ctx->async_cb_list = &cb;
|
|
662
|
+
LeaveCriticalSection(&ctx->async_cb_lock);
|
|
519
663
|
|
|
520
|
-
SetEvent(async_cb_cond);
|
|
664
|
+
SetEvent(ctx->async_cb_cond);
|
|
521
665
|
|
|
522
666
|
/* Wait for the thread executing the ruby callback to signal it is done */
|
|
523
667
|
WaitForSingleObject(cb.async_event, INFINITE);
|
|
@@ -528,6 +672,7 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
|
528
672
|
|
|
529
673
|
#if defined(DEFER_ASYNC_CALLBACK)
|
|
530
674
|
struct async_wait {
|
|
675
|
+
struct async_cb_dispatcher *dispatcher;
|
|
531
676
|
void* cb;
|
|
532
677
|
bool stop;
|
|
533
678
|
};
|
|
@@ -536,9 +681,10 @@ static void * async_cb_wait(void *);
|
|
|
536
681
|
static void async_cb_stop(void *);
|
|
537
682
|
|
|
538
683
|
static VALUE
|
|
539
|
-
async_cb_event(void*
|
|
684
|
+
async_cb_event(void* ptr)
|
|
540
685
|
{
|
|
541
|
-
struct
|
|
686
|
+
struct async_cb_dispatcher *ctx = (struct async_cb_dispatcher *)ptr;
|
|
687
|
+
struct async_wait w = { ctx };
|
|
542
688
|
|
|
543
689
|
w.stop = false;
|
|
544
690
|
while (!w.stop) {
|
|
@@ -559,23 +705,24 @@ static void *
|
|
|
559
705
|
async_cb_wait(void *data)
|
|
560
706
|
{
|
|
561
707
|
struct async_wait* w = (struct async_wait *) data;
|
|
708
|
+
struct async_cb_dispatcher *ctx = w->dispatcher;
|
|
562
709
|
|
|
563
710
|
w->cb = NULL;
|
|
564
711
|
|
|
565
|
-
EnterCriticalSection(&async_cb_lock);
|
|
712
|
+
EnterCriticalSection(&ctx->async_cb_lock);
|
|
566
713
|
|
|
567
|
-
while (!w->stop && async_cb_list == NULL) {
|
|
568
|
-
LeaveCriticalSection(&async_cb_lock);
|
|
569
|
-
WaitForSingleObject(async_cb_cond, INFINITE);
|
|
570
|
-
EnterCriticalSection(&async_cb_lock);
|
|
714
|
+
while (!w->stop && ctx->async_cb_list == NULL) {
|
|
715
|
+
LeaveCriticalSection(&ctx->async_cb_lock);
|
|
716
|
+
WaitForSingleObject(ctx->async_cb_cond, INFINITE);
|
|
717
|
+
EnterCriticalSection(&ctx->async_cb_lock);
|
|
571
718
|
}
|
|
572
719
|
|
|
573
|
-
if (async_cb_list != NULL) {
|
|
574
|
-
w->cb = async_cb_list;
|
|
575
|
-
async_cb_list = async_cb_list->next;
|
|
720
|
+
if (ctx->async_cb_list != NULL) {
|
|
721
|
+
w->cb = ctx->async_cb_list;
|
|
722
|
+
ctx->async_cb_list = ctx->async_cb_list->next;
|
|
576
723
|
}
|
|
577
724
|
|
|
578
|
-
LeaveCriticalSection(&async_cb_lock);
|
|
725
|
+
LeaveCriticalSection(&ctx->async_cb_lock);
|
|
579
726
|
|
|
580
727
|
return NULL;
|
|
581
728
|
}
|
|
@@ -584,11 +731,12 @@ static void
|
|
|
584
731
|
async_cb_stop(void *data)
|
|
585
732
|
{
|
|
586
733
|
struct async_wait* w = (struct async_wait *) data;
|
|
734
|
+
struct async_cb_dispatcher *ctx = w->dispatcher;
|
|
587
735
|
|
|
588
|
-
EnterCriticalSection(&async_cb_lock);
|
|
736
|
+
EnterCriticalSection(&ctx->async_cb_lock);
|
|
589
737
|
w->stop = true;
|
|
590
|
-
LeaveCriticalSection(&async_cb_lock);
|
|
591
|
-
SetEvent(async_cb_cond);
|
|
738
|
+
LeaveCriticalSection(&ctx->async_cb_lock);
|
|
739
|
+
SetEvent(ctx->async_cb_cond);
|
|
592
740
|
}
|
|
593
741
|
|
|
594
742
|
#else
|
|
@@ -596,21 +744,22 @@ static void *
|
|
|
596
744
|
async_cb_wait(void *data)
|
|
597
745
|
{
|
|
598
746
|
struct async_wait* w = (struct async_wait *) data;
|
|
747
|
+
struct async_cb_dispatcher *ctx = w->dispatcher;
|
|
599
748
|
|
|
600
749
|
w->cb = NULL;
|
|
601
750
|
|
|
602
|
-
pthread_mutex_lock(&async_cb_mutex);
|
|
751
|
+
pthread_mutex_lock(&ctx->async_cb_mutex);
|
|
603
752
|
|
|
604
|
-
while (!w->stop && async_cb_list == NULL) {
|
|
605
|
-
pthread_cond_wait(&async_cb_cond, &async_cb_mutex);
|
|
753
|
+
while (!w->stop && ctx->async_cb_list == NULL) {
|
|
754
|
+
pthread_cond_wait(&ctx->async_cb_cond, &ctx->async_cb_mutex);
|
|
606
755
|
}
|
|
607
756
|
|
|
608
|
-
if (async_cb_list != NULL) {
|
|
609
|
-
w->cb = async_cb_list;
|
|
610
|
-
async_cb_list = async_cb_list->next;
|
|
757
|
+
if (ctx->async_cb_list != NULL) {
|
|
758
|
+
w->cb = ctx->async_cb_list;
|
|
759
|
+
ctx->async_cb_list = ctx->async_cb_list->next;
|
|
611
760
|
}
|
|
612
761
|
|
|
613
|
-
pthread_mutex_unlock(&async_cb_mutex);
|
|
762
|
+
pthread_mutex_unlock(&ctx->async_cb_mutex);
|
|
614
763
|
|
|
615
764
|
return NULL;
|
|
616
765
|
}
|
|
@@ -619,11 +768,12 @@ static void
|
|
|
619
768
|
async_cb_stop(void *data)
|
|
620
769
|
{
|
|
621
770
|
struct async_wait* w = (struct async_wait *) data;
|
|
771
|
+
struct async_cb_dispatcher *ctx = w->dispatcher;
|
|
622
772
|
|
|
623
|
-
pthread_mutex_lock(&async_cb_mutex);
|
|
773
|
+
pthread_mutex_lock(&ctx->async_cb_mutex);
|
|
624
774
|
w->stop = true;
|
|
625
|
-
pthread_cond_signal(&async_cb_cond);
|
|
626
|
-
pthread_mutex_unlock(&async_cb_mutex);
|
|
775
|
+
pthread_cond_signal(&ctx->async_cb_cond);
|
|
776
|
+
pthread_mutex_unlock(&ctx->async_cb_mutex);
|
|
627
777
|
}
|
|
628
778
|
#endif
|
|
629
779
|
|
|
@@ -796,7 +946,9 @@ invoke_callback(VALUE data)
|
|
|
796
946
|
break;
|
|
797
947
|
case NATIVE_POINTER:
|
|
798
948
|
if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_PointerClass)) {
|
|
799
|
-
|
|
949
|
+
AbstractMemory* memory;
|
|
950
|
+
TypedData_Get_Struct(rbReturnValue, AbstractMemory, &rbffi_abstract_memory_data_type, memory);
|
|
951
|
+
*((void **) retval) = memory->address;
|
|
800
952
|
} else {
|
|
801
953
|
/* Default to returning NULL if not a value pointer object. handles nil case as well */
|
|
802
954
|
*((void **) retval) = NULL;
|
|
@@ -809,15 +961,20 @@ invoke_callback(VALUE data)
|
|
|
809
961
|
|
|
810
962
|
case NATIVE_FUNCTION:
|
|
811
963
|
if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_PointerClass)) {
|
|
964
|
+
AbstractMemory* memory;
|
|
965
|
+
TypedData_Get_Struct(rbReturnValue, AbstractMemory, &rbffi_abstract_memory_data_type, memory);
|
|
812
966
|
|
|
813
|
-
*((void **) retval) =
|
|
967
|
+
*((void **) retval) = memory->address;
|
|
814
968
|
|
|
815
969
|
} else if (rb_obj_is_kind_of(rbReturnValue, rb_cProc) || rb_respond_to(rbReturnValue, id_call)) {
|
|
816
970
|
VALUE function;
|
|
971
|
+
AbstractMemory* memory;
|
|
817
972
|
|
|
818
973
|
function = rbffi_Function_ForProc(rbReturnType, rbReturnValue);
|
|
819
974
|
|
|
820
|
-
|
|
975
|
+
TypedData_Get_Struct(function, AbstractMemory, &rbffi_abstract_memory_data_type, memory);
|
|
976
|
+
|
|
977
|
+
*((void **) retval) = memory->address;
|
|
821
978
|
} else {
|
|
822
979
|
*((void **) retval) = NULL;
|
|
823
980
|
}
|
|
@@ -825,7 +982,11 @@ invoke_callback(VALUE data)
|
|
|
825
982
|
|
|
826
983
|
case NATIVE_STRUCT:
|
|
827
984
|
if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_StructClass)) {
|
|
828
|
-
|
|
985
|
+
Struct* s;
|
|
986
|
+
AbstractMemory* memory;
|
|
987
|
+
|
|
988
|
+
TypedData_Get_Struct(rbReturnValue, Struct, &rbffi_struct_data_type, s);
|
|
989
|
+
memory = s->pointer;
|
|
829
990
|
|
|
830
991
|
if (memory->address != NULL) {
|
|
831
992
|
memcpy(retval, memory->address, returnType->ffiType->size);
|
|
@@ -891,6 +1052,7 @@ rbffi_Function_Init(VALUE moduleFFI)
|
|
|
891
1052
|
rb_define_method(rbffi_FunctionClass, "attach", function_attach, 2);
|
|
892
1053
|
rb_define_method(rbffi_FunctionClass, "free", function_release, 0);
|
|
893
1054
|
rb_define_method(rbffi_FunctionClass, "autorelease=", function_set_autorelease, 1);
|
|
1055
|
+
rb_define_private_method(rbffi_FunctionClass, "type", function_type, 0);
|
|
894
1056
|
/*
|
|
895
1057
|
* call-seq: autorelease
|
|
896
1058
|
* @return [Boolean]
|
|
@@ -910,8 +1072,12 @@ rbffi_Function_Init(VALUE moduleFFI)
|
|
|
910
1072
|
id_cb_ref = rb_intern("@__ffi_callback__");
|
|
911
1073
|
id_to_native = rb_intern("to_native");
|
|
912
1074
|
id_from_native = rb_intern("from_native");
|
|
913
|
-
#if defined(
|
|
914
|
-
|
|
915
|
-
|
|
1075
|
+
#if defined(DEFER_ASYNC_CALLBACK) && defined(HAVE_RB_EXT_RACTOR_SAFE)
|
|
1076
|
+
async_cb_dispatcher_key = rb_ractor_local_storage_ptr_newkey(&async_cb_dispatcher_key_type);
|
|
1077
|
+
#endif
|
|
1078
|
+
#ifdef DEFER_ASYNC_CALLBACK
|
|
1079
|
+
/* Ruby code will call this method in a Process._fork patch */
|
|
1080
|
+
rb_define_singleton_method(moduleFFI, "_async_cb_dispatcher_atfork_child",
|
|
1081
|
+
async_cb_dispatcher_atfork_child, 0);
|
|
916
1082
|
#endif
|
|
917
1083
|
}
|