ffi 1.9.24 → 1.16.3
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 +348 -0
- data/Gemfile +4 -5
- data/README.md +44 -17
- data/Rakefile +74 -148
- data/ext/ffi_c/AbstractMemory.c +89 -70
- 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 +90 -38
- data/ext/ffi_c/Call.c +55 -56
- data/ext/ffi_c/Call.h +12 -6
- data/ext/ffi_c/ClosurePool.c +333 -0
- data/ext/ffi_c/{Closure.h → ClosurePool.h} +25 -13
- data/ext/ffi_c/DynamicLibrary.c +91 -33
- data/ext/ffi_c/Function.c +306 -235
- data/ext/ffi_c/Function.h +3 -5
- data/ext/ffi_c/FunctionInfo.c +87 -32
- data/ext/ffi_c/LastError.c +74 -15
- data/ext/ffi_c/LongDouble.c +12 -10
- data/ext/ffi_c/LongDouble.h +0 -4
- data/ext/ffi_c/MappedType.c +66 -23
- data/ext/ffi_c/MappedType.h +0 -2
- data/ext/ffi_c/MemoryPointer.c +37 -15
- data/ext/ffi_c/MemoryPointer.h +0 -4
- data/ext/ffi_c/MethodHandle.c +265 -38
- data/ext/ffi_c/MethodHandle.h +3 -2
- data/ext/ffi_c/Platform.c +5 -56
- data/ext/ffi_c/Pointer.c +93 -55
- data/ext/ffi_c/Pointer.h +1 -4
- data/ext/ffi_c/Struct.c +202 -134
- data/ext/ffi_c/Struct.h +18 -9
- data/ext/ffi_c/StructByValue.c +50 -23
- data/ext/ffi_c/StructLayout.c +135 -64
- data/ext/ffi_c/Thread.c +4 -228
- data/ext/ffi_c/Thread.h +1 -20
- data/ext/ffi_c/Type.c +105 -55
- data/ext/ffi_c/Type.h +3 -2
- data/ext/ffi_c/Types.c +8 -9
- data/ext/ffi_c/Types.h +3 -4
- data/ext/ffi_c/Variadic.c +88 -47
- data/ext/ffi_c/compat.h +26 -22
- data/ext/ffi_c/extconf.rb +75 -32
- data/ext/ffi_c/ffi.c +9 -10
- 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 +53 -19
- data/ext/ffi_c/libffi/.ci/bfin-sim.exp +58 -0
- data/ext/ffi_c/libffi/.ci/build-cross-in-container.sh +18 -0
- data/ext/ffi_c/libffi/.ci/build-in-container.sh +10 -0
- data/ext/ffi_c/libffi/.ci/build.sh +124 -0
- data/ext/ffi_c/libffi/.ci/install.sh +78 -0
- data/ext/ffi_c/libffi/.ci/m32r-sim.exp +58 -0
- data/ext/ffi_c/libffi/{.travis → .ci}/moxie-sim.exp +1 -1
- data/ext/ffi_c/libffi/.ci/msvs-detect +1103 -0
- data/ext/ffi_c/libffi/.ci/or1k-sim.exp +58 -0
- data/ext/ffi_c/libffi/.ci/powerpc-eabisim.exp +58 -0
- data/ext/ffi_c/libffi/.ci/site.exp +29 -0
- data/ext/ffi_c/libffi/.ci/wine-sim.exp +55 -0
- data/ext/ffi_c/libffi/.circleci/config.yml +156 -0
- data/ext/ffi_c/libffi/.gitattributes +4 -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/{ChangeLog.libffi-3.1 → ChangeLog.old} +1407 -0
- data/ext/ffi_c/libffi/LICENSE +1 -1
- data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +5 -4
- data/ext/ffi_c/libffi/Makefile.am +64 -73
- data/ext/ffi_c/libffi/Makefile.in +553 -235
- data/ext/ffi_c/libffi/README.md +165 -100
- data/ext/ffi_c/libffi/acinclude.m4 +10 -112
- data/ext/ffi_c/libffi/compile +348 -0
- data/ext/ffi_c/libffi/config.guess +950 -662
- data/ext/ffi_c/libffi/config.sub +1362 -1306
- data/ext/ffi_c/libffi/configure +4909 -4096
- data/ext/ffi_c/libffi/configure.ac +93 -32
- data/ext/ffi_c/libffi/configure.host +76 -28
- data/ext/ffi_c/libffi/doc/Makefile.in +15 -8
- data/ext/ffi_c/libffi/doc/libffi.texi +107 -46
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/fficonfig.h.in +22 -44
- data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +165 -56
- data/ext/ffi_c/libffi/include/Makefile.am +1 -1
- data/ext/ffi_c/libffi/include/Makefile.in +17 -12
- data/ext/ffi_c/libffi/include/ffi.h.in +64 -48
- data/ext/ffi_c/libffi/include/ffi_cfi.h +21 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +34 -1
- data/ext/ffi_c/libffi/include/tramp.h +45 -0
- data/ext/ffi_c/libffi/install-sh +107 -74
- data/ext/ffi_c/libffi/libffi.map.in +8 -12
- data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +2 -48
- data/ext/ffi_c/libffi/libtool-version +2 -2
- data/ext/ffi_c/libffi/ltmain.sh +576 -284
- data/ext/ffi_c/libffi/m4/asmcfi.m4 +1 -1
- data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +5 -26
- data/ext/ffi_c/libffi/m4/ax_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 +5 -26
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +76 -44
- data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +5 -26
- data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +7 -3
- data/ext/ffi_c/libffi/m4/ax_prepend_flag.m4 +51 -0
- data/ext/ffi_c/libffi/make_sunver.pl +333 -0
- data/ext/ffi_c/libffi/man/Makefile.in +15 -8
- data/ext/ffi_c/libffi/missing +8 -8
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.sln +33 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj +130 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.filters +57 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user +4 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +511 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/fficonfig.h +219 -0
- data/ext/ffi_c/libffi/msvcc.sh +39 -14
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +286 -98
- data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +19 -3
- data/ext/ffi_c/libffi/src/aarch64/internal.h +33 -0
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +142 -37
- data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
- 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 +112 -10
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +8 -1
- data/ext/ffi_c/libffi/src/arm/internal.h +10 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +117 -44
- data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
- data/ext/ffi_c/libffi/src/closures.c +189 -48
- data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
- data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
- data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
- data/ext/ffi_c/libffi/src/dlmalloc.c +6 -1
- data/ext/ffi_c/libffi/src/frv/ffi.c +1 -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/kvx/asm.h +5 -0
- data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
- data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
- data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
- data/ext/ffi_c/libffi/src/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/metag/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/mips/ffi.c +245 -66
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +8 -1
- data/ext/ffi_c/libffi/src/mips/n32.S +137 -28
- data/ext/ffi_c/libffi/src/mips/o32.S +63 -4
- data/ext/ffi_c/libffi/src/moxie/ffi.c +48 -23
- data/ext/ffi_c/libffi/src/or1k/ffi.c +25 -12
- data/ext/ffi_c/libffi/src/pa/ffi.c +62 -108
- data/ext/ffi_c/libffi/src/pa/ffi64.c +614 -0
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +20 -11
- data/ext/ffi_c/libffi/src/pa/hpux32.S +87 -38
- data/ext/ffi_c/libffi/src/pa/hpux64.S +681 -0
- data/ext/ffi_c/libffi/src/pa/linux.S +109 -39
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +6 -4
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +13 -1
- data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +211 -32
- data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +18 -7
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +10 -4
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +93 -28
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +83 -5
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
- data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
- data/ext/ffi_c/libffi/src/prep_cif.c +26 -4
- data/ext/ffi_c/libffi/src/riscv/ffi.c +79 -10
- data/ext/ffi_c/libffi/src/riscv/ffitarget.h +1 -0
- data/ext/ffi_c/libffi/src/riscv/sysv.S +86 -7
- data/ext/ffi_c/libffi/src/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 +128 -49
- data/ext/ffi_c/libffi/src/x86/ffi64.c +89 -23
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +21 -4
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +63 -10
- 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 +274 -45
- data/ext/ffi_c/libffi/src/x86/sysv_intel.S +998 -0
- data/ext/ffi_c/libffi/src/x86/unix64.S +190 -4
- data/ext/ffi_c/libffi/src/x86/win64.S +32 -10
- data/ext/ffi_c/libffi/src/x86/win64_intel.S +3 -2
- 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 -109
- data/ext/ffi_c/libffi/testsuite/Makefile.in +144 -88
- 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 +71 -25
- data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +7 -2
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +5 -4
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2 -2
- 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/call.exp +12 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +28 -3
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +9 -8
- 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.exp +67 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn0.c +3 -2
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn1.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn2.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn3.c +21 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn4.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn5.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn6.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_loc_fn0.c +7 -6
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_simple.c +6 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_12byte.c +18 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_16byte.c +22 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_18byte.c +24 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_19byte.c +29 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_1_1byte.c +4 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte1.c +21 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_24byte.c +35 -3
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_2byte.c +13 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3_1byte.c +19 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte1.c +13 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte2.c +13 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3float.c +18 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4_1byte.c +22 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4byte.c +13 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5_1_byte.c +29 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5byte.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_64byte.c +24 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6_1_byte.c +28 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6byte.c +24 -2
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7_1_byte.c +39 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7byte.c +25 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_8byte.c +14 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte1.c +14 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte2.c +14 -2
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_double.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_float.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble.c +20 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split.c +40 -25
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split2.c +40 -3
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_pointer.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint16.c +18 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint32.c +18 -3
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint64.c +18 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint16.c +18 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint32.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint64.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_dbls_struct.c +3 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double_va.c +9 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_float.c +4 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble.c +11 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble_va.c +22 -3
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_schar.c +5 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshort.c +6 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshortchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_uchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushort.c +6 -2
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushortchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer.c +5 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer_stack.c +10 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_schar.c +3 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sint.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sshort.c +3 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_struct_va1.c +11 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar.c +3 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint.c +4 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint_va.c +4 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulong_va.c +4 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulonglong.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +1 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/huge_struct.c +24 -22
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct.c +32 -9
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct1.c +1 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct10.c +12 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → 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.call → libffi.closures}/nested_struct2.c +10 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct3.c +10 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct4.c +9 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct5.c +9 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct6.c +11 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct7.c +9 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct8.c +11 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → 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.call → libffi.closures}/stret_medium.c +1 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium2.c +1 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/testclosure.c +6 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest.cc +2 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest_ffi_call.cc +1 -0
- data/ext/ffi_c/libffi.bsd.mk +2 -2
- data/ext/ffi_c/libffi.darwin.mk +1 -1
- data/ext/ffi_c/libffi.gnu.mk +2 -2
- data/ext/ffi_c/rbffi.h +1 -3
- data/ffi.gemspec +15 -9
- data/lib/ffi/abstract_memory.rb +44 -0
- data/lib/ffi/autopointer.rb +8 -23
- data/lib/ffi/compat.rb +43 -0
- data/lib/ffi/data_converter.rb +67 -0
- data/lib/ffi/dynamic_library.rb +89 -0
- data/lib/ffi/enum.rb +18 -11
- data/lib/ffi/ffi.rb +6 -0
- data/lib/ffi/function.rb +71 -0
- data/lib/ffi/io.rb +3 -3
- data/lib/ffi/library.rb +65 -77
- data/lib/ffi/library_path.rb +109 -0
- data/lib/ffi/managedstruct.rb +3 -3
- data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
- data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
- data/lib/ffi/platform/aarch64-freebsd12/types.conf +181 -0
- data/lib/ffi/platform/aarch64-linux/types.conf +81 -81
- data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
- data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
- data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
- data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
- data/lib/ffi/platform/arm-linux/types.conf +110 -82
- data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
- data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
- data/lib/ffi/platform/i386-cygwin/types.conf +1 -1
- data/lib/ffi/platform/i386-darwin/types.conf +63 -63
- data/lib/ffi/platform/i386-freebsd/types.conf +89 -89
- data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
- data/lib/ffi/platform/i386-gnu/types.conf +84 -84
- data/lib/ffi/platform/i386-linux/types.conf +77 -77
- data/lib/ffi/platform/i386-netbsd/types.conf +87 -87
- data/lib/ffi/platform/i386-openbsd/types.conf +89 -89
- data/lib/ffi/platform/i386-solaris/types.conf +96 -96
- data/lib/ffi/platform/i386-windows/types.conf +43 -96
- data/lib/ffi/platform/ia64-linux/types.conf +79 -79
- data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
- data/lib/ffi/platform/mips-linux/types.conf +79 -79
- data/lib/ffi/platform/mips64-linux/types.conf +81 -81
- data/lib/ffi/platform/mips64el-linux/types.conf +81 -81
- data/lib/ffi/platform/mipsel-linux/types.conf +79 -79
- data/lib/ffi/platform/mipsisa32r6-linux/types.conf +79 -79
- data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +79 -79
- data/lib/ffi/platform/mipsisa64r6-linux/types.conf +81 -81
- data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +81 -81
- data/lib/ffi/platform/powerpc-aix/types.conf +155 -155
- data/lib/ffi/platform/powerpc-darwin/types.conf +63 -63
- data/lib/ffi/platform/powerpc-linux/types.conf +108 -78
- data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
- data/lib/ffi/platform/powerpc64-linux/types.conf +81 -81
- data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
- data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
- data/lib/ffi/platform/s390-linux/types.conf +79 -79
- data/lib/ffi/platform/s390x-linux/types.conf +79 -79
- data/lib/ffi/platform/sparc-linux/types.conf +79 -79
- data/lib/ffi/platform/sparc-solaris/types.conf +103 -103
- data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
- data/lib/ffi/platform/sparcv9-solaris/types.conf +103 -103
- data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
- data/lib/ffi/platform/x86_64-cygwin/types.conf +1 -1
- data/lib/ffi/platform/x86_64-darwin/types.conf +88 -84
- data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
- data/lib/ffi/platform/x86_64-freebsd/types.conf +90 -90
- data/lib/ffi/platform/x86_64-freebsd12/types.conf +158 -0
- data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
- data/lib/ffi/platform/x86_64-linux/types.conf +107 -77
- data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
- data/lib/ffi/platform/x86_64-netbsd/types.conf +89 -89
- data/lib/ffi/platform/x86_64-openbsd/types.conf +86 -86
- data/lib/ffi/platform/x86_64-solaris/types.conf +96 -96
- data/lib/ffi/platform/x86_64-windows/types.conf +42 -110
- data/lib/ffi/platform.rb +43 -20
- data/lib/ffi/pointer.rb +26 -20
- data/lib/ffi/struct.rb +14 -68
- data/lib/ffi/struct_by_reference.rb +72 -0
- data/lib/ffi/struct_layout.rb +96 -0
- data/lib/ffi/struct_layout_builder.rb +1 -1
- data/lib/ffi/tools/const_generator.rb +11 -8
- data/lib/ffi/tools/generator.rb +47 -2
- data/lib/ffi/tools/generator_task.rb +13 -17
- data/lib/ffi/tools/struct_generator.rb +6 -5
- data/lib/ffi/tools/types_generator.rb +7 -4
- data/lib/ffi/types.rb +33 -7
- data/lib/ffi/variadic.rb +20 -18
- data/lib/ffi/version.rb +1 -1
- data/lib/ffi.rb +10 -3
- data/rakelib/ffi_gem_helper.rb +65 -0
- data/samples/getlogin.rb +1 -1
- data/samples/getpid.rb +1 -1
- data/samples/gettimeofday.rb +8 -8
- data/samples/hello.rb +2 -1
- data/samples/hello_ractor.rb +11 -0
- data/samples/inotify.rb +1 -1
- data/samples/pty.rb +1 -2
- data/samples/qsort.rb +0 -1
- data/samples/qsort_ractor.rb +28 -0
- data.tar.gz.sig +0 -0
- metadata +252 -153
- metadata.gz.sig +0 -0
- data/.gitignore +0 -22
- data/.gitmodules +0 -3
- data/.travis.yml +0 -52
- data/.yardopts +0 -5
- data/appveyor.yml +0 -22
- data/ext/ffi_c/Closure.c +0 -54
- data/ext/ffi_c/DataConverter.c +0 -91
- data/ext/ffi_c/StructByReference.c +0 -190
- data/ext/ffi_c/StructByReference.h +0 -50
- data/ext/ffi_c/libffi/.travis/build.sh +0 -34
- data/ext/ffi_c/libffi/.travis/install.sh +0 -22
- data/ext/ffi_c/libffi/.travis/site.exp +0 -18
- data/ext/ffi_c/libffi/.travis.yml +0 -34
- data/ext/ffi_c/libffi/ChangeLog.libffi +0 -584
- data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
- data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar_va.c +0 -44
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort_va.c +0 -44
- data/ext/ffi_c/win32/stdbool.h +0 -8
- data/ext/ffi_c/win32/stdint.h +0 -201
- data/samples/sample_helper.rb +0 -6
- data/ext/ffi_c/libffi/{.travis → .ci}/ar-lib +0 -0
- data/ext/ffi_c/libffi/{.travis → .ci}/compile +0 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_args.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_float_double.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/err_bad_abi.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/problem1.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large2.c +0 -0
- data/lib/ffi/platform/{sparc64-linux → sparcv9-linux}/types.conf +79 -79
data/ext/ffi_c/Struct.h
CHANGED
@@ -34,11 +34,7 @@
|
|
34
34
|
#include "extconf.h"
|
35
35
|
#include "AbstractMemory.h"
|
36
36
|
#include "Type.h"
|
37
|
-
#ifdef RUBY_1_9
|
38
37
|
#include <ruby/st.h>
|
39
|
-
#else
|
40
|
-
#include <st.h>
|
41
|
-
#endif
|
42
38
|
|
43
39
|
#ifdef __cplusplus
|
44
40
|
extern "C" {
|
@@ -46,6 +42,9 @@ extern "C" {
|
|
46
42
|
|
47
43
|
extern void rbffi_Struct_Init(VALUE ffiModule);
|
48
44
|
extern void rbffi_StructLayout_Init(VALUE ffiModule);
|
45
|
+
extern const rb_data_type_t rbffi_struct_layout_data_type;
|
46
|
+
extern const rb_data_type_t rbffi_struct_field_data_type;
|
47
|
+
|
49
48
|
typedef struct StructField_ StructField;
|
50
49
|
typedef struct StructLayout_ StructLayout;
|
51
50
|
typedef struct Struct_ Struct;
|
@@ -60,9 +59,6 @@ extern "C" {
|
|
60
59
|
VALUE rbType;
|
61
60
|
VALUE rbName;
|
62
61
|
|
63
|
-
VALUE (*get)(StructField* field, Struct* s);
|
64
|
-
void (*put)(StructField* field, Struct* s, VALUE value);
|
65
|
-
|
66
62
|
MemoryOp* memoryOp;
|
67
63
|
};
|
68
64
|
|
@@ -73,11 +69,22 @@ extern "C" {
|
|
73
69
|
int size;
|
74
70
|
int align;
|
75
71
|
ffi_type** ffiTypes;
|
76
|
-
|
72
|
+
|
73
|
+
/*
|
74
|
+
* We use the fieldName's minor 8 Bits as index to a 256 entry cache.
|
75
|
+
* This avoids full ruby hash lookups for repeated lookups.
|
76
|
+
*/
|
77
|
+
#define FIELD_CACHE_LOOKUP(this, sym) ( &(this)->cache_row[((sym) >> 8) & 0xff] )
|
78
|
+
#define FIELD_CACHE_ROWS 0x100
|
79
|
+
|
80
|
+
struct field_cache_entry {
|
81
|
+
VALUE fieldName;
|
82
|
+
StructField *field;
|
83
|
+
} cache_row[FIELD_CACHE_ROWS];
|
77
84
|
|
78
85
|
/** The number of reference tracking fields in this struct */
|
79
86
|
int referenceFieldCount;
|
80
|
-
|
87
|
+
|
81
88
|
VALUE rbFieldNames;
|
82
89
|
VALUE rbFieldMap;
|
83
90
|
VALUE rbFields;
|
@@ -92,6 +99,8 @@ extern "C" {
|
|
92
99
|
VALUE rbPointer;
|
93
100
|
};
|
94
101
|
|
102
|
+
extern const rb_data_type_t rbffi_struct_data_type;
|
103
|
+
extern const rb_data_type_t rbffi_struct_field_data_type;
|
95
104
|
extern VALUE rbffi_StructClass, rbffi_StructLayoutClass;
|
96
105
|
extern VALUE rbffi_StructLayoutFieldClass, rbffi_StructLayoutFunctionFieldClass;
|
97
106
|
extern VALUE rbffi_StructLayoutArrayFieldClass;
|
data/ext/ffi_c/StructByValue.c
CHANGED
@@ -32,13 +32,8 @@
|
|
32
32
|
#endif
|
33
33
|
#include <sys/types.h>
|
34
34
|
#include <stdio.h>
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# include <stdbool.h>
|
38
|
-
#else
|
39
|
-
# include "win32/stdbool.h"
|
40
|
-
# include "win32/stdint.h"
|
41
|
-
#endif
|
35
|
+
#include <stdint.h>
|
36
|
+
#include <stdbool.h>
|
42
37
|
#include <errno.h>
|
43
38
|
#include <ruby.h>
|
44
39
|
|
@@ -54,20 +49,36 @@
|
|
54
49
|
|
55
50
|
static VALUE sbv_allocate(VALUE);
|
56
51
|
static VALUE sbv_initialize(VALUE, VALUE);
|
57
|
-
static void sbv_mark(
|
58
|
-
static void
|
52
|
+
static void sbv_mark(void *);
|
53
|
+
static void sbv_compact(void *);
|
54
|
+
static void sbv_free(void *);
|
55
|
+
static size_t sbv_memsize(const void *);
|
59
56
|
|
60
57
|
VALUE rbffi_StructByValueClass = Qnil;
|
61
58
|
|
59
|
+
static const rb_data_type_t sbv_type_data_type = {
|
60
|
+
.wrap_struct_name = "FFI::StructByValue",
|
61
|
+
.function = {
|
62
|
+
.dmark = sbv_mark,
|
63
|
+
.dfree = sbv_free,
|
64
|
+
.dsize = sbv_memsize,
|
65
|
+
ffi_compact_callback( sbv_compact )
|
66
|
+
},
|
67
|
+
.parent = &rbffi_type_data_type,
|
68
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
69
|
+
// macro to update VALUE references, as to trigger write barriers.
|
70
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
71
|
+
};
|
72
|
+
|
62
73
|
static VALUE
|
63
74
|
sbv_allocate(VALUE klass)
|
64
75
|
{
|
65
76
|
StructByValue* sbv;
|
66
77
|
|
67
|
-
VALUE obj =
|
78
|
+
VALUE obj = TypedData_Make_Struct(klass, StructByValue, &sbv_type_data_type, sbv);
|
68
79
|
|
69
|
-
sbv->rbStructClass
|
70
|
-
sbv->rbStructLayout
|
80
|
+
RB_OBJ_WRITE(obj, &sbv->rbStructClass, Qnil);
|
81
|
+
RB_OBJ_WRITE(obj, &sbv->rbStructLayout, Qnil);
|
71
82
|
sbv->base.nativeType = NATIVE_STRUCT;
|
72
83
|
|
73
84
|
sbv->base.ffiType = xcalloc(1, sizeof(*sbv->base.ffiType));
|
@@ -90,38 +101,54 @@ sbv_initialize(VALUE self, VALUE rbStructClass)
|
|
90
101
|
rb_raise(rb_eTypeError, "wrong type in @layout ivar (expected FFI::StructLayout)");
|
91
102
|
}
|
92
103
|
|
93
|
-
|
94
|
-
|
95
|
-
sbv->rbStructClass
|
96
|
-
sbv->rbStructLayout
|
104
|
+
TypedData_Get_Struct(rbLayout, StructLayout, &rbffi_struct_layout_data_type, layout);
|
105
|
+
TypedData_Get_Struct(self, StructByValue, &sbv_type_data_type, sbv);
|
106
|
+
RB_OBJ_WRITE(self, &sbv->rbStructClass, rbStructClass);
|
107
|
+
RB_OBJ_WRITE(self, &sbv->rbStructLayout, rbLayout);
|
97
108
|
|
98
109
|
/* We can just use everything from the ffi_type directly */
|
99
110
|
*sbv->base.ffiType = *layout->base.ffiType;
|
100
|
-
|
111
|
+
|
101
112
|
return self;
|
102
113
|
}
|
103
114
|
|
104
115
|
static void
|
105
|
-
sbv_mark(
|
116
|
+
sbv_mark(void *data)
|
117
|
+
{
|
118
|
+
StructByValue *sbv = (StructByValue *)data;
|
119
|
+
rb_gc_mark_movable(sbv->rbStructClass);
|
120
|
+
rb_gc_mark_movable(sbv->rbStructLayout);
|
121
|
+
}
|
122
|
+
|
123
|
+
static void
|
124
|
+
sbv_compact(void *data)
|
106
125
|
{
|
107
|
-
|
108
|
-
|
126
|
+
StructByValue *sbv = (StructByValue *)data;
|
127
|
+
ffi_gc_location(sbv->rbStructClass);
|
128
|
+
ffi_gc_location(sbv->rbStructLayout);
|
109
129
|
}
|
110
130
|
|
111
131
|
static void
|
112
|
-
sbv_free(
|
132
|
+
sbv_free(void *data)
|
113
133
|
{
|
134
|
+
StructByValue *sbv = (StructByValue *)data;
|
114
135
|
xfree(sbv->base.ffiType);
|
115
136
|
xfree(sbv);
|
116
137
|
}
|
117
138
|
|
139
|
+
static size_t
|
140
|
+
sbv_memsize(const void *data)
|
141
|
+
{
|
142
|
+
const StructByValue *sbv = (const StructByValue *)data;
|
143
|
+
return sizeof(StructByValue) + sizeof(*sbv->base.ffiType);
|
144
|
+
}
|
118
145
|
|
119
146
|
static VALUE
|
120
147
|
sbv_layout(VALUE self)
|
121
148
|
{
|
122
149
|
StructByValue* sbv;
|
123
150
|
|
124
|
-
|
151
|
+
TypedData_Get_Struct(self, StructByValue, &sbv_type_data_type, sbv);
|
125
152
|
return sbv->rbStructLayout;
|
126
153
|
}
|
127
154
|
|
@@ -130,7 +157,7 @@ sbv_struct_class(VALUE self)
|
|
130
157
|
{
|
131
158
|
StructByValue* sbv;
|
132
159
|
|
133
|
-
|
160
|
+
TypedData_Get_Struct(self, StructByValue, &sbv_type_data_type, sbv);
|
134
161
|
|
135
162
|
return sbv->rbStructClass;
|
136
163
|
}
|
data/ext/ffi_c/StructLayout.c
CHANGED
@@ -32,12 +32,9 @@
|
|
32
32
|
|
33
33
|
#ifndef _MSC_VER
|
34
34
|
# include <sys/param.h>
|
35
|
-
# include <stdint.h>
|
36
|
-
# include <stdbool.h>
|
37
|
-
#else
|
38
|
-
# include "win32/stdbool.h"
|
39
|
-
# include "win32/stdint.h"
|
40
35
|
#endif
|
36
|
+
#include <stdint.h>
|
37
|
+
#include <stdbool.h>
|
41
38
|
#include <ruby.h>
|
42
39
|
#include "rbffi.h"
|
43
40
|
#include "compat.h"
|
@@ -54,9 +51,13 @@
|
|
54
51
|
|
55
52
|
#define FFI_ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
|
56
53
|
|
57
|
-
static void struct_layout_mark(
|
58
|
-
static void
|
59
|
-
static void
|
54
|
+
static void struct_layout_mark(void *);
|
55
|
+
static void struct_layout_compact(void *);
|
56
|
+
static void struct_layout_free(void *);
|
57
|
+
static size_t struct_layout_memsize(const void *);
|
58
|
+
static void struct_field_mark(void *);
|
59
|
+
static void struct_field_compact(void *);
|
60
|
+
static size_t struct_field_memsize(const void *);
|
60
61
|
|
61
62
|
VALUE rbffi_StructLayoutFieldClass = Qnil;
|
62
63
|
VALUE rbffi_StructLayoutNumberFieldClass = Qnil, rbffi_StructLayoutPointerFieldClass = Qnil;
|
@@ -65,6 +66,33 @@ VALUE rbffi_StructLayoutFunctionFieldClass = Qnil, rbffi_StructLayoutArrayFieldC
|
|
65
66
|
|
66
67
|
VALUE rbffi_StructLayoutClass = Qnil;
|
67
68
|
|
69
|
+
const rb_data_type_t rbffi_struct_layout_data_type = { /* extern */
|
70
|
+
.wrap_struct_name = "FFI::StructLayout",
|
71
|
+
.function = {
|
72
|
+
.dmark = struct_layout_mark,
|
73
|
+
.dfree = struct_layout_free,
|
74
|
+
.dsize = struct_layout_memsize,
|
75
|
+
ffi_compact_callback( struct_layout_compact )
|
76
|
+
},
|
77
|
+
.parent = &rbffi_type_data_type,
|
78
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
79
|
+
// macro to update VALUE references, as to trigger write barriers.
|
80
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
81
|
+
};
|
82
|
+
|
83
|
+
const rb_data_type_t rbffi_struct_field_data_type = { /* extern */
|
84
|
+
.wrap_struct_name = "FFI::StructField",
|
85
|
+
.function = {
|
86
|
+
.dmark = struct_field_mark,
|
87
|
+
.dfree = RUBY_TYPED_DEFAULT_FREE,
|
88
|
+
.dsize = struct_field_memsize,
|
89
|
+
ffi_compact_callback( struct_field_compact )
|
90
|
+
},
|
91
|
+
.parent = &rbffi_type_data_type,
|
92
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
93
|
+
// macro to update VALUE references, as to trigger write barriers.
|
94
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
95
|
+
};
|
68
96
|
|
69
97
|
static VALUE
|
70
98
|
struct_field_allocate(VALUE klass)
|
@@ -72,18 +100,33 @@ struct_field_allocate(VALUE klass)
|
|
72
100
|
StructField* field;
|
73
101
|
VALUE obj;
|
74
102
|
|
75
|
-
obj =
|
76
|
-
field->rbType
|
77
|
-
field->rbName
|
103
|
+
obj = TypedData_Make_Struct(klass, StructField, &rbffi_struct_field_data_type, field);
|
104
|
+
RB_OBJ_WRITE(obj, &field->rbType, Qnil);
|
105
|
+
RB_OBJ_WRITE(obj, &field->rbName, Qnil);
|
78
106
|
|
79
107
|
return obj;
|
80
108
|
}
|
81
109
|
|
82
110
|
static void
|
83
|
-
struct_field_mark(
|
111
|
+
struct_field_mark(void *data)
|
112
|
+
{
|
113
|
+
StructField *f = (StructField *)data;
|
114
|
+
rb_gc_mark_movable(f->rbType);
|
115
|
+
rb_gc_mark_movable(f->rbName);
|
116
|
+
}
|
117
|
+
|
118
|
+
static void
|
119
|
+
struct_field_compact(void *data)
|
120
|
+
{
|
121
|
+
StructField *f = (StructField *)data;
|
122
|
+
ffi_gc_location(f->rbType);
|
123
|
+
ffi_gc_location(f->rbName);
|
124
|
+
}
|
125
|
+
|
126
|
+
static size_t
|
127
|
+
struct_field_memsize(const void *data)
|
84
128
|
{
|
85
|
-
|
86
|
-
rb_gc_mark(f->rbName);
|
129
|
+
return sizeof(StructField);
|
87
130
|
}
|
88
131
|
|
89
132
|
/*
|
@@ -101,7 +144,7 @@ struct_field_initialize(int argc, VALUE* argv, VALUE self)
|
|
101
144
|
StructField* field;
|
102
145
|
int nargs;
|
103
146
|
|
104
|
-
|
147
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, field);
|
105
148
|
|
106
149
|
nargs = rb_scan_args(argc, argv, "3", &rbName, &rbOffset, &rbType);
|
107
150
|
|
@@ -118,15 +161,14 @@ struct_field_initialize(int argc, VALUE* argv, VALUE self)
|
|
118
161
|
}
|
119
162
|
|
120
163
|
field->offset = NUM2UINT(rbOffset);
|
121
|
-
field->rbName
|
122
|
-
field->rbType
|
123
|
-
|
164
|
+
RB_OBJ_WRITE(self, &field->rbName, (TYPE(rbName) == T_SYMBOL) ? rbName : rb_str_intern(rbName));
|
165
|
+
RB_OBJ_WRITE(self, &field->rbType, rbType);
|
166
|
+
TypedData_Get_Struct(field->rbType, Type, &rbffi_type_data_type, field->type);
|
124
167
|
field->memoryOp = get_memory_op(field->type);
|
125
168
|
field->referenceIndex = -1;
|
126
169
|
|
127
170
|
switch (field->type->nativeType == NATIVE_MAPPED ? ((MappedType *) field->type)->type->nativeType : field->type->nativeType) {
|
128
171
|
case NATIVE_FUNCTION:
|
129
|
-
case NATIVE_CALLBACK:
|
130
172
|
case NATIVE_POINTER:
|
131
173
|
field->referenceRequired = true;
|
132
174
|
break;
|
@@ -138,7 +180,9 @@ struct_field_initialize(int argc, VALUE* argv, VALUE self)
|
|
138
180
|
&& RTEST(rb_funcall2(rbType, rb_intern("reference_required?"), 0, NULL)));
|
139
181
|
break;
|
140
182
|
}
|
141
|
-
|
183
|
+
|
184
|
+
rb_obj_freeze(self);
|
185
|
+
|
142
186
|
return self;
|
143
187
|
}
|
144
188
|
|
@@ -151,7 +195,7 @@ static VALUE
|
|
151
195
|
struct_field_offset(VALUE self)
|
152
196
|
{
|
153
197
|
StructField* field;
|
154
|
-
|
198
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, field);
|
155
199
|
return UINT2NUM(field->offset);
|
156
200
|
}
|
157
201
|
|
@@ -164,7 +208,7 @@ static VALUE
|
|
164
208
|
struct_field_size(VALUE self)
|
165
209
|
{
|
166
210
|
StructField* field;
|
167
|
-
|
211
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, field);
|
168
212
|
return UINT2NUM(field->type->ffiType->size);
|
169
213
|
}
|
170
214
|
|
@@ -177,7 +221,7 @@ static VALUE
|
|
177
221
|
struct_field_alignment(VALUE self)
|
178
222
|
{
|
179
223
|
StructField* field;
|
180
|
-
|
224
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, field);
|
181
225
|
return UINT2NUM(field->type->ffiType->alignment);
|
182
226
|
}
|
183
227
|
|
@@ -190,7 +234,7 @@ static VALUE
|
|
190
234
|
struct_field_type(VALUE self)
|
191
235
|
{
|
192
236
|
StructField* field;
|
193
|
-
|
237
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, field);
|
194
238
|
|
195
239
|
return field->rbType;
|
196
240
|
}
|
@@ -204,7 +248,7 @@ static VALUE
|
|
204
248
|
struct_field_name(VALUE self)
|
205
249
|
{
|
206
250
|
StructField* field;
|
207
|
-
|
251
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, field);
|
208
252
|
return field->rbName;
|
209
253
|
}
|
210
254
|
|
@@ -219,7 +263,7 @@ struct_field_get(VALUE self, VALUE pointer)
|
|
219
263
|
{
|
220
264
|
StructField* f;
|
221
265
|
|
222
|
-
|
266
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, f);
|
223
267
|
if (f->memoryOp == NULL) {
|
224
268
|
rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(f->rbType));
|
225
269
|
return Qnil;
|
@@ -239,8 +283,8 @@ static VALUE
|
|
239
283
|
struct_field_put(VALUE self, VALUE pointer, VALUE value)
|
240
284
|
{
|
241
285
|
StructField* f;
|
242
|
-
|
243
|
-
|
286
|
+
|
287
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, f);
|
244
288
|
if (f->memoryOp == NULL) {
|
245
289
|
rb_raise(rb_eArgError, "put not supported for %s", rb_obj_classname(f->rbType));
|
246
290
|
return self;
|
@@ -261,8 +305,8 @@ static VALUE
|
|
261
305
|
function_field_get(VALUE self, VALUE pointer)
|
262
306
|
{
|
263
307
|
StructField* f;
|
264
|
-
|
265
|
-
|
308
|
+
|
309
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, f);
|
266
310
|
|
267
311
|
return rbffi_Function_NewInstance(f->rbType, (*rbffi_AbstractMemoryOps.pointer->get)(MEMORY(pointer), f->offset));
|
268
312
|
}
|
@@ -272,7 +316,7 @@ function_field_get(VALUE self, VALUE pointer)
|
|
272
316
|
* @param [AbstractMemory] pointer pointer to a {Struct}
|
273
317
|
* @param [Function, Proc] proc
|
274
318
|
* @return [Function]
|
275
|
-
* Set a {Function} to memory pointed by +pointer+ as a function.
|
319
|
+
* Set a {Function} to memory pointed by +pointer+ as a function.
|
276
320
|
*
|
277
321
|
* If a Proc is submitted as +proc+, it is automatically transformed to a {Function}.
|
278
322
|
*/
|
@@ -282,7 +326,7 @@ function_field_put(VALUE self, VALUE pointer, VALUE proc)
|
|
282
326
|
StructField* f;
|
283
327
|
VALUE value = Qnil;
|
284
328
|
|
285
|
-
|
329
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, f);
|
286
330
|
|
287
331
|
if (NIL_P(proc) || rb_obj_is_kind_of(proc, rbffi_FunctionClass)) {
|
288
332
|
value = proc;
|
@@ -317,8 +361,8 @@ array_field_get(VALUE self, VALUE pointer)
|
|
317
361
|
ArrayType* array;
|
318
362
|
VALUE argv[2];
|
319
363
|
|
320
|
-
|
321
|
-
|
364
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, f);
|
365
|
+
TypedData_Get_Struct(f->rbType, ArrayType, &rbffi_array_type_data_type, array);
|
322
366
|
|
323
367
|
argv[0] = pointer;
|
324
368
|
argv[1] = self;
|
@@ -339,19 +383,23 @@ array_field_put(VALUE self, VALUE pointer, VALUE value)
|
|
339
383
|
{
|
340
384
|
StructField* f;
|
341
385
|
ArrayType* array;
|
342
|
-
|
343
386
|
|
344
|
-
|
345
|
-
|
346
|
-
|
387
|
+
TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, f);
|
388
|
+
TypedData_Get_Struct(f->rbType, ArrayType, &rbffi_array_type_data_type, array);
|
389
|
+
|
347
390
|
if (isCharArray(array) && rb_obj_is_instance_of(value, rb_cString)) {
|
348
391
|
VALUE argv[2];
|
349
392
|
|
350
393
|
argv[0] = INT2FIX(f->offset);
|
351
394
|
argv[1] = value;
|
352
395
|
|
353
|
-
|
354
|
-
|
396
|
+
if (RSTRING_LEN(value) < array->length) {
|
397
|
+
rb_funcall2(pointer, rb_intern("put_string"), 2, argv);
|
398
|
+
} else if (RSTRING_LEN(value) == array->length) {
|
399
|
+
rb_funcall2(pointer, rb_intern("put_bytes"), 2, argv);
|
400
|
+
} else {
|
401
|
+
rb_raise(rb_eIndexError, "String is longer (%ld bytes) than the char array (%d bytes)", RSTRING_LEN(value), array->length);
|
402
|
+
}
|
355
403
|
} else {
|
356
404
|
#ifdef notyet
|
357
405
|
MemoryOp* op;
|
@@ -384,12 +432,8 @@ array_field_put(VALUE self, VALUE pointer, VALUE value)
|
|
384
432
|
VALUE entry = rb_ary_entry(value, i);
|
385
433
|
Struct* s;
|
386
434
|
|
387
|
-
|
388
|
-
rb_raise(rb_eTypeError, "array element not an instance of FFI::Struct");
|
389
|
-
break;
|
390
|
-
}
|
435
|
+
TypedData_Get_Struct(entry, Struct, &rbffi_struct_data_type, s);
|
391
436
|
|
392
|
-
Data_Get_Struct(entry, Struct, s);
|
393
437
|
checkRead(s->pointer);
|
394
438
|
checkBounds(s->pointer, 0, array->componentType->ffiType->size);
|
395
439
|
|
@@ -415,11 +459,10 @@ struct_layout_allocate(VALUE klass)
|
|
415
459
|
StructLayout* layout;
|
416
460
|
VALUE obj;
|
417
461
|
|
418
|
-
obj =
|
462
|
+
obj = TypedData_Make_Struct(klass, StructLayout, &rbffi_struct_layout_data_type, layout);
|
419
463
|
layout->rbFieldMap = Qnil;
|
420
464
|
layout->rbFieldNames = Qnil;
|
421
465
|
layout->rbFields = Qnil;
|
422
|
-
layout->fieldSymbolTable = st_init_numtable();
|
423
466
|
layout->base.ffiType = xcalloc(1, sizeof(*layout->base.ffiType));
|
424
467
|
layout->base.ffiType->size = 0;
|
425
468
|
layout->base.ffiType->alignment = 0;
|
@@ -443,7 +486,7 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align)
|
|
443
486
|
ffi_type* ltype;
|
444
487
|
int i;
|
445
488
|
|
446
|
-
|
489
|
+
TypedData_Get_Struct(self, StructLayout, &rbffi_struct_layout_data_type, layout);
|
447
490
|
layout->fieldCount = (int) RARRAY_LEN(fields);
|
448
491
|
layout->rbFieldMap = rb_hash_new();
|
449
492
|
layout->rbFieldNames = rb_ary_new2(layout->fieldCount);
|
@@ -470,7 +513,7 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align)
|
|
470
513
|
}
|
471
514
|
rbName = rb_funcall2(rbField, rb_intern("name"), 0, NULL);
|
472
515
|
|
473
|
-
|
516
|
+
TypedData_Get_Struct(rbField, StructField, &rbffi_struct_field_data_type, field);
|
474
517
|
layout->fields[i] = field;
|
475
518
|
|
476
519
|
if (field->type == NULL || field->type->ffiType == NULL) {
|
@@ -488,7 +531,6 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align)
|
|
488
531
|
|
489
532
|
|
490
533
|
layout->ffiTypes[i] = ftype->size > 0 ? ftype : NULL;
|
491
|
-
st_insert(layout->fieldSymbolTable, rbName, rbField);
|
492
534
|
rb_hash_aset(layout->rbFieldMap, rbName, rbField);
|
493
535
|
rb_ary_push(layout->rbFields, rbField);
|
494
536
|
rb_ary_push(layout->rbFieldNames, rbName);
|
@@ -498,17 +540,22 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align)
|
|
498
540
|
rb_raise(rb_eRuntimeError, "Struct size is zero");
|
499
541
|
}
|
500
542
|
|
543
|
+
rb_obj_freeze(layout->rbFieldMap);
|
544
|
+
rb_obj_freeze(layout->rbFields);
|
545
|
+
rb_obj_freeze(layout->rbFieldNames);
|
546
|
+
rb_obj_freeze(self);
|
547
|
+
|
501
548
|
return self;
|
502
549
|
}
|
503
550
|
|
504
|
-
/*
|
551
|
+
/*
|
505
552
|
* call-seq: [](field)
|
506
553
|
* @param [Symbol] field
|
507
554
|
* @return [StructLayout::Field]
|
508
555
|
* Get a field from the layout.
|
509
556
|
*/
|
510
557
|
static VALUE
|
511
|
-
struct_layout_union_bang(VALUE self)
|
558
|
+
struct_layout_union_bang(VALUE self)
|
512
559
|
{
|
513
560
|
const ffi_type *alignment_types[] = { &ffi_type_sint8, &ffi_type_sint16, &ffi_type_sint32, &ffi_type_sint64,
|
514
561
|
&ffi_type_float, &ffi_type_double, &ffi_type_longdouble, NULL };
|
@@ -516,7 +563,7 @@ struct_layout_union_bang(VALUE self)
|
|
516
563
|
ffi_type *t = NULL;
|
517
564
|
int count, i;
|
518
565
|
|
519
|
-
|
566
|
+
TypedData_Get_Struct(self, StructLayout, &rbffi_struct_layout_data_type, layout);
|
520
567
|
|
521
568
|
for (i = 0; alignment_types[i] != NULL; ++i) {
|
522
569
|
if (alignment_types[i]->alignment == layout->align) {
|
@@ -546,7 +593,7 @@ struct_layout_aref(VALUE self, VALUE field)
|
|
546
593
|
{
|
547
594
|
StructLayout* layout;
|
548
595
|
|
549
|
-
|
596
|
+
TypedData_Get_Struct(self, StructLayout, &rbffi_struct_layout_data_type, layout);
|
550
597
|
|
551
598
|
return rb_hash_aref(layout->rbFieldMap, field);
|
552
599
|
}
|
@@ -561,7 +608,7 @@ struct_layout_fields(VALUE self)
|
|
561
608
|
{
|
562
609
|
StructLayout* layout;
|
563
610
|
|
564
|
-
|
611
|
+
TypedData_Get_Struct(self, StructLayout, &rbffi_struct_layout_data_type, layout);
|
565
612
|
|
566
613
|
return rb_ary_dup(layout->rbFields);
|
567
614
|
}
|
@@ -576,7 +623,7 @@ struct_layout_members(VALUE self)
|
|
576
623
|
{
|
577
624
|
StructLayout* layout;
|
578
625
|
|
579
|
-
|
626
|
+
TypedData_Get_Struct(self, StructLayout, &rbffi_struct_layout_data_type, layout);
|
580
627
|
|
581
628
|
return rb_ary_dup(layout->rbFieldNames);
|
582
629
|
}
|
@@ -591,30 +638,54 @@ struct_layout_to_a(VALUE self)
|
|
591
638
|
{
|
592
639
|
StructLayout* layout;
|
593
640
|
|
594
|
-
|
641
|
+
TypedData_Get_Struct(self, StructLayout, &rbffi_struct_layout_data_type, layout);
|
595
642
|
|
596
643
|
return rb_ary_dup(layout->rbFields);
|
597
644
|
}
|
598
645
|
|
599
646
|
static void
|
600
|
-
struct_layout_mark(
|
647
|
+
struct_layout_mark(void *data)
|
601
648
|
{
|
602
|
-
|
603
|
-
|
604
|
-
|
649
|
+
StructLayout *layout = (StructLayout *)data;
|
650
|
+
rb_gc_mark_movable(layout->rbFieldMap);
|
651
|
+
rb_gc_mark_movable(layout->rbFieldNames);
|
652
|
+
rb_gc_mark_movable(layout->rbFields);
|
653
|
+
/* The values stored in layout->cache_row.fieldName are primary stored in layout->rbFieldMap and are marked there */
|
605
654
|
}
|
606
655
|
|
607
656
|
static void
|
608
|
-
|
657
|
+
struct_layout_compact(void *data)
|
609
658
|
{
|
659
|
+
StructLayout *layout = (StructLayout *)data;
|
660
|
+
ffi_gc_location(layout->rbFieldMap);
|
661
|
+
ffi_gc_location(layout->rbFieldNames);
|
662
|
+
ffi_gc_location(layout->rbFields);
|
663
|
+
|
664
|
+
/* Clear the cache, to be safe from changes of fieldName VALUE by GC.compact */
|
665
|
+
memset(&layout->cache_row, 0, sizeof(layout->cache_row));
|
666
|
+
}
|
667
|
+
|
668
|
+
static void
|
669
|
+
struct_layout_free(void *data)
|
670
|
+
{
|
671
|
+
StructLayout *layout = (StructLayout *)data;
|
610
672
|
xfree(layout->ffiTypes);
|
611
673
|
xfree(layout->base.ffiType);
|
612
674
|
xfree(layout->fields);
|
613
|
-
st_free_table(layout->fieldSymbolTable);
|
614
675
|
xfree(layout);
|
615
676
|
}
|
616
677
|
|
617
678
|
|
679
|
+
static size_t
|
680
|
+
struct_layout_memsize(const void * data)
|
681
|
+
{
|
682
|
+
const StructLayout *layout = (const StructLayout *)data;
|
683
|
+
size_t memsize = sizeof(StructLayout);
|
684
|
+
memsize += layout->fieldCount * (sizeof(StructField *) + sizeof(ffi_type *));
|
685
|
+
memsize += sizeof(*layout->base.ffiType);
|
686
|
+
return memsize;
|
687
|
+
}
|
688
|
+
|
618
689
|
void
|
619
690
|
rbffi_StructLayout_Init(VALUE moduleFFI)
|
620
691
|
{
|
@@ -627,7 +698,7 @@ rbffi_StructLayout_Init(VALUE moduleFFI)
|
|
627
698
|
*/
|
628
699
|
rbffi_StructLayoutClass = rb_define_class_under(moduleFFI, "StructLayout", ffi_Type);
|
629
700
|
rb_global_variable(&rbffi_StructLayoutClass);
|
630
|
-
|
701
|
+
|
631
702
|
/*
|
632
703
|
* Document-class: FFI::StructLayout::Field
|
633
704
|
* A field in a {StructLayout}.
|