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/AbstractMemory.c
CHANGED
@@ -32,12 +32,9 @@
|
|
32
32
|
#include <sys/types.h>
|
33
33
|
#ifndef _MSC_VER
|
34
34
|
# include <sys/param.h>
|
35
|
-
# include <stdint.h>
|
36
|
-
# include <stdbool.h>
|
37
|
-
#else
|
38
|
-
# include "win32/stdbool.h"
|
39
|
-
# include "win32/stdint.h"
|
40
35
|
#endif
|
36
|
+
#include <stdint.h>
|
37
|
+
#include <stdbool.h>
|
41
38
|
|
42
39
|
#include <limits.h>
|
43
40
|
#include <ruby.h>
|
@@ -58,21 +55,30 @@
|
|
58
55
|
# define RB_OBJ_STRING(obj) StringValueCStr(obj)
|
59
56
|
#endif
|
60
57
|
|
58
|
+
static size_t memsize(const void *data);
|
61
59
|
static inline char* memory_address(VALUE self);
|
62
60
|
VALUE rbffi_AbstractMemoryClass = Qnil;
|
63
61
|
static VALUE NullPointerErrorClass = Qnil;
|
64
62
|
static ID id_to_ptr = 0, id_plus = 0, id_call = 0;
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
{
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
64
|
+
const rb_data_type_t rbffi_abstract_memory_data_type = { /* extern */
|
65
|
+
.wrap_struct_name = "FFI::AbstractMemory",
|
66
|
+
.function = {
|
67
|
+
.dmark = NULL,
|
68
|
+
.dfree = RUBY_TYPED_DEFAULT_FREE,
|
69
|
+
.dsize = memsize,
|
70
|
+
},
|
71
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
72
|
+
// macro to update VALUE references, as to trigger write barriers.
|
73
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
74
|
+
};
|
73
75
|
|
74
|
-
|
76
|
+
static size_t
|
77
|
+
memsize(const void *data)
|
78
|
+
{
|
79
|
+
return sizeof(AbstractMemory);
|
75
80
|
}
|
81
|
+
|
76
82
|
#define VAL(x, swap) (unlikely(((memory->flags & MEM_SWAP) != 0)) ? swap((x)) : (x))
|
77
83
|
|
78
84
|
#define NUM_OP(name, type, toNative, fromNative, swap) \
|
@@ -90,7 +96,7 @@ static VALUE \
|
|
90
96
|
memory_put_##name(VALUE self, VALUE offset, VALUE value) \
|
91
97
|
{ \
|
92
98
|
AbstractMemory* memory; \
|
93
|
-
|
99
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, memory); \
|
94
100
|
memory_op_put_##name(memory, NUM2LONG(offset), value); \
|
95
101
|
return self; \
|
96
102
|
} \
|
@@ -99,7 +105,7 @@ static VALUE \
|
|
99
105
|
memory_write_##name(VALUE self, VALUE value) \
|
100
106
|
{ \
|
101
107
|
AbstractMemory* memory; \
|
102
|
-
|
108
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, memory); \
|
103
109
|
memory_op_put_##name(memory, 0, value); \
|
104
110
|
return self; \
|
105
111
|
} \
|
@@ -118,7 +124,7 @@ static VALUE \
|
|
118
124
|
memory_get_##name(VALUE self, VALUE offset) \
|
119
125
|
{ \
|
120
126
|
AbstractMemory* memory; \
|
121
|
-
|
127
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, memory); \
|
122
128
|
return memory_op_get_##name(memory, NUM2LONG(offset)); \
|
123
129
|
} \
|
124
130
|
static VALUE memory_read_##name(VALUE self); \
|
@@ -126,7 +132,7 @@ static VALUE \
|
|
126
132
|
memory_read_##name(VALUE self) \
|
127
133
|
{ \
|
128
134
|
AbstractMemory* memory; \
|
129
|
-
|
135
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, memory); \
|
130
136
|
return memory_op_get_##name(memory, 0); \
|
131
137
|
} \
|
132
138
|
static MemoryOp memory_op_##name = { memory_op_get_##name, memory_op_put_##name }; \
|
@@ -135,14 +141,16 @@ static VALUE memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary); \
|
|
135
141
|
static VALUE \
|
136
142
|
memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \
|
137
143
|
{ \
|
138
|
-
long count
|
144
|
+
long count; \
|
139
145
|
long off = NUM2LONG(offset); \
|
140
146
|
AbstractMemory* memory = MEMORY(self); \
|
141
147
|
long i; \
|
142
|
-
|
148
|
+
Check_Type(ary, T_ARRAY); \
|
149
|
+
count = RARRAY_LEN(ary); \
|
150
|
+
if (likely(count > 0)) checkWrite(memory); \
|
143
151
|
checkBounds(memory, off, count * sizeof(type)); \
|
144
152
|
for (i = 0; i < count; i++) { \
|
145
|
-
type tmp = (type) VAL(toNative(
|
153
|
+
type tmp = (type) VAL(toNative(RARRAY_AREF(ary, i)), swap); \
|
146
154
|
memcpy(memory->address + off + (i * sizeof(type)), &tmp, sizeof(tmp)); \
|
147
155
|
} \
|
148
156
|
return self; \
|
@@ -162,7 +170,7 @@ memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length) \
|
|
162
170
|
AbstractMemory* memory = MEMORY(self); \
|
163
171
|
VALUE retVal = rb_ary_new2(count); \
|
164
172
|
long i; \
|
165
|
-
checkRead(memory); \
|
173
|
+
if (likely(count > 0)) checkRead(memory); \
|
166
174
|
checkBounds(memory, off, count * sizeof(type)); \
|
167
175
|
for (i = 0; i < count; ++i) { \
|
168
176
|
type tmp; \
|
@@ -209,13 +217,13 @@ SWAPU16(uint16_t x)
|
|
209
217
|
((x >> 40) & 0x000000000000ff00ULL) | \
|
210
218
|
((x >> 56) & 0x00000000000000ffULL))
|
211
219
|
|
212
|
-
static inline int32_t
|
220
|
+
static inline int32_t
|
213
221
|
SWAPS32(int32_t x)
|
214
222
|
{
|
215
223
|
return bswap32(x);
|
216
224
|
}
|
217
225
|
|
218
|
-
static inline uint32_t
|
226
|
+
static inline uint32_t
|
219
227
|
SWAPU32(uint32_t x)
|
220
228
|
{
|
221
229
|
return bswap32(x);
|
@@ -308,6 +316,7 @@ static VALUE
|
|
308
316
|
memory_clear(VALUE self)
|
309
317
|
{
|
310
318
|
AbstractMemory* ptr = MEMORY(self);
|
319
|
+
checkWrite(ptr);
|
311
320
|
memset(ptr->address, 0, ptr->size);
|
312
321
|
return self;
|
313
322
|
}
|
@@ -322,7 +331,7 @@ memory_size(VALUE self)
|
|
322
331
|
{
|
323
332
|
AbstractMemory* ptr;
|
324
333
|
|
325
|
-
|
334
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
|
326
335
|
|
327
336
|
return LONG2NUM(ptr->size);
|
328
337
|
}
|
@@ -341,14 +350,15 @@ memory_get(VALUE self, VALUE type_name, VALUE offset)
|
|
341
350
|
AbstractMemory* ptr;
|
342
351
|
VALUE nType;
|
343
352
|
Type *type;
|
353
|
+
MemoryOp *op;
|
344
354
|
|
345
355
|
nType = rbffi_Type_Lookup(type_name);
|
346
356
|
if(NIL_P(nType)) goto undefined_type;
|
347
357
|
|
348
|
-
|
349
|
-
|
358
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
|
359
|
+
TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
|
350
360
|
|
351
|
-
|
361
|
+
op = get_memory_op(type);
|
352
362
|
if(op == NULL) goto undefined_type;
|
353
363
|
|
354
364
|
return op->get(ptr, NUM2LONG(offset));
|
@@ -373,14 +383,15 @@ memory_put(VALUE self, VALUE type_name, VALUE offset, VALUE value)
|
|
373
383
|
AbstractMemory* ptr;
|
374
384
|
VALUE nType;
|
375
385
|
Type *type;
|
386
|
+
MemoryOp *op;
|
376
387
|
|
377
388
|
nType = rbffi_Type_Lookup(type_name);
|
378
389
|
if(NIL_P(nType)) goto undefined_type;
|
379
390
|
|
380
|
-
|
381
|
-
|
391
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
|
392
|
+
TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
|
382
393
|
|
383
|
-
|
394
|
+
op = get_memory_op(type);
|
384
395
|
if(op == NULL) goto undefined_type;
|
385
396
|
|
386
397
|
op->put(ptr, NUM2LONG(offset), value);
|
@@ -417,7 +428,7 @@ memory_get_string(int argc, VALUE* argv, VALUE self)
|
|
417
428
|
checkBounds(ptr, off, len);
|
418
429
|
|
419
430
|
end = memchr(ptr->address + off, 0, len);
|
420
|
-
return
|
431
|
+
return rb_str_new((char *) ptr->address + off,
|
421
432
|
(end != NULL ? end - ptr->address - off : len));
|
422
433
|
}
|
423
434
|
|
@@ -443,17 +454,17 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
443
454
|
count = (countnum == Qnil ? 0 : NUM2INT(countnum));
|
444
455
|
retVal = rb_ary_new2(count);
|
445
456
|
|
446
|
-
|
457
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
|
447
458
|
checkRead(ptr);
|
448
459
|
|
449
460
|
if (countnum != Qnil) {
|
450
461
|
int i;
|
451
462
|
|
452
463
|
checkBounds(ptr, off, count * sizeof (char*));
|
453
|
-
|
464
|
+
|
454
465
|
for (i = 0; i < count; ++i) {
|
455
466
|
const char* strptr = *((const char**) (ptr->address + off) + i);
|
456
|
-
rb_ary_push(retVal, (strptr == NULL ? Qnil :
|
467
|
+
rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_str_new2(strptr)));
|
457
468
|
}
|
458
469
|
|
459
470
|
} else {
|
@@ -463,7 +474,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
463
474
|
if (strptr == NULL) {
|
464
475
|
break;
|
465
476
|
}
|
466
|
-
rb_ary_push(retVal,
|
477
|
+
rb_ary_push(retVal, rb_str_new2(strptr));
|
467
478
|
}
|
468
479
|
}
|
469
480
|
|
@@ -477,7 +488,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
477
488
|
* @param [Numeric] count number of strings to get. If nil, return all strings
|
478
489
|
* @return [Array<String>]
|
479
490
|
*/
|
480
|
-
static VALUE
|
491
|
+
static VALUE
|
481
492
|
memory_read_array_of_string(int argc, VALUE* argv, VALUE self)
|
482
493
|
{
|
483
494
|
VALUE* rargv = ALLOCA_N(VALUE, argc + 1);
|
@@ -535,14 +546,14 @@ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
|
|
535
546
|
{
|
536
547
|
AbstractMemory* ptr = MEMORY(self);
|
537
548
|
long off, len;
|
538
|
-
|
549
|
+
|
539
550
|
off = NUM2LONG(offset);
|
540
551
|
len = NUM2LONG(length);
|
541
552
|
|
542
553
|
checkRead(ptr);
|
543
554
|
checkBounds(ptr, off, len);
|
544
|
-
|
545
|
-
return
|
555
|
+
|
556
|
+
return rb_str_new((char *) ptr->address + off, len);
|
546
557
|
}
|
547
558
|
|
548
559
|
/*
|
@@ -583,10 +594,6 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
|
|
583
594
|
checkWrite(ptr);
|
584
595
|
checkBounds(ptr, off, len);
|
585
596
|
|
586
|
-
if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
|
587
|
-
rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
|
588
|
-
return Qnil;
|
589
|
-
}
|
590
597
|
memcpy(ptr->address + off, RSTRING_PTR(str) + idx, len);
|
591
598
|
|
592
599
|
return self;
|
@@ -599,7 +606,7 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
|
|
599
606
|
* equivalent to :
|
600
607
|
* memory.get_bytes(0, length)
|
601
608
|
*/
|
602
|
-
static VALUE
|
609
|
+
static VALUE
|
603
610
|
memory_read_bytes(VALUE self, VALUE length)
|
604
611
|
{
|
605
612
|
return memory_get_bytes(self, INT2FIX(0), length);
|
@@ -614,7 +621,7 @@ memory_read_bytes(VALUE self, VALUE length)
|
|
614
621
|
* equivalent to :
|
615
622
|
* memory.put_bytes(0, str, index, length)
|
616
623
|
*/
|
617
|
-
static VALUE
|
624
|
+
static VALUE
|
618
625
|
memory_write_bytes(int argc, VALUE* argv, VALUE self)
|
619
626
|
{
|
620
627
|
VALUE* wargv = ALLOCA_N(VALUE, argc + 1);
|
@@ -638,7 +645,7 @@ memory_type_size(VALUE self)
|
|
638
645
|
{
|
639
646
|
AbstractMemory* ptr;
|
640
647
|
|
641
|
-
|
648
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
|
642
649
|
|
643
650
|
return INT2NUM(ptr->typeSize);
|
644
651
|
}
|
@@ -647,7 +654,7 @@ memory_type_size(VALUE self)
|
|
647
654
|
* Document-method: []
|
648
655
|
* call-seq: memory[idx]
|
649
656
|
* @param [Numeric] idx index to access in memory
|
650
|
-
* @return
|
657
|
+
* @return
|
651
658
|
* Memory read accessor.
|
652
659
|
*/
|
653
660
|
static VALUE
|
@@ -656,7 +663,7 @@ memory_aref(VALUE self, VALUE idx)
|
|
656
663
|
AbstractMemory* ptr;
|
657
664
|
VALUE rbOffset = Qnil;
|
658
665
|
|
659
|
-
|
666
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
|
660
667
|
|
661
668
|
rbOffset = ULONG2NUM(NUM2ULONG(idx) * ptr->typeSize);
|
662
669
|
|
@@ -666,7 +673,9 @@ memory_aref(VALUE self, VALUE idx)
|
|
666
673
|
static inline char*
|
667
674
|
memory_address(VALUE obj)
|
668
675
|
{
|
669
|
-
|
676
|
+
AbstractMemory *mem;
|
677
|
+
TypedData_Get_Struct(obj, AbstractMemory, &rbffi_abstract_memory_data_type, mem);
|
678
|
+
return mem->address;
|
670
679
|
}
|
671
680
|
|
672
681
|
static VALUE
|
@@ -674,24 +683,33 @@ memory_copy_from(VALUE self, VALUE rbsrc, VALUE rblen)
|
|
674
683
|
{
|
675
684
|
AbstractMemory* dst;
|
676
685
|
|
677
|
-
|
686
|
+
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, dst);
|
678
687
|
|
679
|
-
memcpy(dst->address, rbffi_AbstractMemory_Cast(rbsrc,
|
688
|
+
memcpy(dst->address, rbffi_AbstractMemory_Cast(rbsrc, &rbffi_abstract_memory_data_type)->address, NUM2INT(rblen));
|
680
689
|
|
681
690
|
return self;
|
682
691
|
}
|
683
692
|
|
684
|
-
|
685
|
-
|
693
|
+
/*
|
694
|
+
* call-seq:
|
695
|
+
* res.freeze
|
696
|
+
*
|
697
|
+
* Freeze the AbstractMemory object and unset the writable flag.
|
698
|
+
*/
|
699
|
+
static VALUE
|
700
|
+
memory_freeze(VALUE self)
|
686
701
|
{
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
}
|
702
|
+
AbstractMemory* ptr = MEMORY(self);
|
703
|
+
ptr->flags &= ~MEM_WR;
|
704
|
+
return rb_call_super(0, NULL);
|
705
|
+
}
|
692
706
|
|
693
|
-
|
694
|
-
|
707
|
+
AbstractMemory*
|
708
|
+
rbffi_AbstractMemory_Cast(VALUE obj, const rb_data_type_t *data_type)
|
709
|
+
{
|
710
|
+
AbstractMemory* memory;
|
711
|
+
TypedData_Get_Struct(obj, AbstractMemory, data_type, memory);
|
712
|
+
return memory;
|
695
713
|
}
|
696
714
|
|
697
715
|
void
|
@@ -718,7 +736,7 @@ memory_op_get_strptr(AbstractMemory* ptr, long offset)
|
|
718
736
|
memcpy(&tmp, ptr->address + offset, sizeof(tmp));
|
719
737
|
}
|
720
738
|
|
721
|
-
return tmp != NULL ?
|
739
|
+
return tmp != NULL ? rb_str_new2(tmp) : Qnil;
|
722
740
|
}
|
723
741
|
|
724
742
|
static void
|
@@ -752,9 +770,9 @@ MemoryOps rbffi_AbstractMemoryOps = {
|
|
752
770
|
void
|
753
771
|
rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
754
772
|
{
|
755
|
-
/*
|
773
|
+
/*
|
756
774
|
* Document-class: FFI::AbstractMemory
|
757
|
-
*
|
775
|
+
*
|
758
776
|
* {AbstractMemory} is the base class for many memory management classes such as {Buffer}.
|
759
777
|
*
|
760
778
|
* This class has a lot of methods to work with integers :
|
@@ -782,11 +800,11 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
782
800
|
*/
|
783
801
|
VALUE classMemory = rb_define_class_under(moduleFFI, "AbstractMemory", rb_cObject);
|
784
802
|
rbffi_AbstractMemoryClass = classMemory;
|
785
|
-
/*
|
786
|
-
* Document-variable: FFI::AbstractMemory
|
803
|
+
/*
|
804
|
+
* Document-variable: FFI::AbstractMemory
|
787
805
|
*/
|
788
806
|
rb_global_variable(&rbffi_AbstractMemoryClass);
|
789
|
-
|
807
|
+
rb_undef_alloc_func(classMemory);
|
790
808
|
|
791
809
|
NullPointerErrorClass = rb_define_class_under(moduleFFI, "NullPointerError", rb_eRuntimeError);
|
792
810
|
/* Document-variable: NullPointerError */
|
@@ -811,13 +829,13 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
811
829
|
rb_define_method(classMemory, "read_array_of_" #type, memory_read_array_of_##type, 1); \
|
812
830
|
rb_define_method(classMemory, "write_array_of_u" #type, memory_write_array_of_u##type, 1); \
|
813
831
|
rb_define_method(classMemory, "read_array_of_u" #type, memory_read_array_of_u##type, 1);
|
814
|
-
|
832
|
+
|
815
833
|
INT(int8);
|
816
834
|
INT(int16);
|
817
835
|
INT(int32);
|
818
836
|
INT(int64);
|
819
837
|
INT(long);
|
820
|
-
|
838
|
+
|
821
839
|
#define ALIAS(name, old) \
|
822
840
|
rb_define_alias(classMemory, "put_" #name, "put_" #old); \
|
823
841
|
rb_define_alias(classMemory, "get_" #name, "get_" #old); \
|
@@ -835,12 +853,12 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
835
853
|
rb_define_alias(classMemory, "read_array_of_" #name, "read_array_of_" #old); \
|
836
854
|
rb_define_alias(classMemory, "write_array_of_u" #name, "write_array_of_u" #old); \
|
837
855
|
rb_define_alias(classMemory, "read_array_of_u" #name, "read_array_of_u" #old);
|
838
|
-
|
856
|
+
|
839
857
|
ALIAS(char, int8);
|
840
858
|
ALIAS(short, int16);
|
841
859
|
ALIAS(int, int32);
|
842
860
|
ALIAS(long_long, int64);
|
843
|
-
|
861
|
+
|
844
862
|
/*
|
845
863
|
* Document-method: put_float32
|
846
864
|
* call-seq: memory.put_float32offset, value)
|
@@ -1101,6 +1119,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
1101
1119
|
rb_define_method(classMemory, "type_size", memory_type_size, 0);
|
1102
1120
|
rb_define_method(classMemory, "[]", memory_aref, 1);
|
1103
1121
|
rb_define_method(classMemory, "__copy_from__", memory_copy_from, 2);
|
1122
|
+
rb_define_method(classMemory, "freeze", memory_freeze, 0 );
|
1104
1123
|
|
1105
1124
|
id_to_ptr = rb_intern("to_ptr");
|
1106
1125
|
id_call = rb_intern("call");
|
data/ext/ffi_c/AbstractMemory.h
CHANGED
@@ -86,12 +86,13 @@ struct AbstractMemory_ {
|
|
86
86
|
};
|
87
87
|
|
88
88
|
|
89
|
+
extern const rb_data_type_t rbffi_abstract_memory_data_type;
|
89
90
|
extern VALUE rbffi_AbstractMemoryClass;
|
90
91
|
extern MemoryOps rbffi_AbstractMemoryOps;
|
91
92
|
|
92
93
|
extern void rbffi_AbstractMemory_Init(VALUE ffiModule);
|
93
94
|
|
94
|
-
extern AbstractMemory* rbffi_AbstractMemory_Cast(VALUE obj,
|
95
|
+
extern AbstractMemory* rbffi_AbstractMemory_Cast(VALUE obj, const rb_data_type_t *data_type);
|
95
96
|
|
96
97
|
extern void rbffi_AbstractMemory_Error(AbstractMemory *, int op);
|
97
98
|
|
@@ -161,7 +162,7 @@ get_memory_op(Type* type)
|
|
161
162
|
}
|
162
163
|
}
|
163
164
|
|
164
|
-
#define MEMORY(obj) rbffi_AbstractMemory_Cast((obj),
|
165
|
+
#define MEMORY(obj) rbffi_AbstractMemory_Cast((obj), &rbffi_abstract_memory_data_type)
|
165
166
|
#define MEMORY_PTR(obj) MEMORY((obj))->address
|
166
167
|
#define MEMORY_LEN(obj) MEMORY((obj))->size
|
167
168
|
|
data/ext/ffi_c/ArrayType.c
CHANGED
@@ -29,12 +29,30 @@
|
|
29
29
|
|
30
30
|
#include <ruby.h>
|
31
31
|
#include <ffi.h>
|
32
|
+
#include "compat.h"
|
32
33
|
#include "ArrayType.h"
|
33
34
|
|
34
35
|
static VALUE array_type_s_allocate(VALUE klass);
|
35
36
|
static VALUE array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength);
|
36
|
-
static void array_type_mark(
|
37
|
-
static void
|
37
|
+
static void array_type_mark(void *);
|
38
|
+
static void array_type_compact(void *);
|
39
|
+
static void array_type_free(void *);
|
40
|
+
static size_t array_type_memsize(const void *);
|
41
|
+
|
42
|
+
const rb_data_type_t rbffi_array_type_data_type = { /* extern */
|
43
|
+
.wrap_struct_name = "FFI::ArrayType",
|
44
|
+
.function = {
|
45
|
+
.dmark = array_type_mark,
|
46
|
+
.dfree = array_type_free,
|
47
|
+
.dsize = array_type_memsize,
|
48
|
+
ffi_compact_callback( array_type_compact )
|
49
|
+
},
|
50
|
+
.parent = &rbffi_type_data_type,
|
51
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
52
|
+
// macro to update VALUE references, as to trigger write barriers.
|
53
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
54
|
+
};
|
55
|
+
|
38
56
|
|
39
57
|
VALUE rbffi_ArrayTypeClass = Qnil;
|
40
58
|
|
@@ -44,32 +62,50 @@ array_type_s_allocate(VALUE klass)
|
|
44
62
|
ArrayType* array;
|
45
63
|
VALUE obj;
|
46
64
|
|
47
|
-
obj =
|
65
|
+
obj = TypedData_Make_Struct(klass, ArrayType, &rbffi_array_type_data_type, array);
|
48
66
|
|
49
67
|
array->base.nativeType = NATIVE_ARRAY;
|
50
68
|
array->base.ffiType = xcalloc(1, sizeof(*array->base.ffiType));
|
51
69
|
array->base.ffiType->type = FFI_TYPE_STRUCT;
|
52
70
|
array->base.ffiType->size = 0;
|
53
71
|
array->base.ffiType->alignment = 0;
|
54
|
-
array->rbComponentType
|
72
|
+
RB_OBJ_WRITE(obj, &array->rbComponentType, Qnil);
|
55
73
|
|
56
74
|
return obj;
|
57
75
|
}
|
58
76
|
|
59
77
|
static void
|
60
|
-
array_type_mark(
|
78
|
+
array_type_mark(void *data)
|
79
|
+
{
|
80
|
+
ArrayType *array = (ArrayType *)data;
|
81
|
+
rb_gc_mark_movable(array->rbComponentType);
|
82
|
+
}
|
83
|
+
|
84
|
+
static void
|
85
|
+
array_type_compact(void *data)
|
61
86
|
{
|
62
|
-
|
87
|
+
ArrayType *array = (ArrayType *)data;
|
88
|
+
ffi_gc_location(array->rbComponentType);
|
63
89
|
}
|
64
90
|
|
65
91
|
static void
|
66
|
-
array_type_free(
|
92
|
+
array_type_free(void *data)
|
67
93
|
{
|
94
|
+
ArrayType *array = (ArrayType *)data;
|
68
95
|
xfree(array->base.ffiType);
|
69
96
|
xfree(array->ffiTypes);
|
70
97
|
xfree(array);
|
71
98
|
}
|
72
99
|
|
100
|
+
static size_t
|
101
|
+
array_type_memsize(const void *data)
|
102
|
+
{
|
103
|
+
const ArrayType *array = (const ArrayType *)data;
|
104
|
+
size_t memsize = sizeof(ArrayType);
|
105
|
+
memsize += array->length * sizeof(*array->ffiTypes);
|
106
|
+
memsize += sizeof(*array->base.ffiType);
|
107
|
+
return memsize;
|
108
|
+
}
|
73
109
|
|
74
110
|
/*
|
75
111
|
* call-seq: initialize(component_type, length)
|
@@ -84,12 +120,12 @@ array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength)
|
|
84
120
|
ArrayType* array;
|
85
121
|
int i;
|
86
122
|
|
87
|
-
|
123
|
+
TypedData_Get_Struct(self, ArrayType, &rbffi_array_type_data_type, array);
|
88
124
|
|
89
125
|
array->length = NUM2UINT(rbLength);
|
90
|
-
array->rbComponentType
|
91
|
-
|
92
|
-
|
126
|
+
RB_OBJ_WRITE(self, &array->rbComponentType, rbComponentType);
|
127
|
+
TypedData_Get_Struct(rbComponentType, Type, &rbffi_type_data_type, array->componentType);
|
128
|
+
|
93
129
|
array->ffiTypes = xcalloc(array->length + 1, sizeof(*array->ffiTypes));
|
94
130
|
array->base.ffiType->elements = array->ffiTypes;
|
95
131
|
array->base.ffiType->size = array->componentType->ffiType->size * array->length;
|
@@ -112,7 +148,7 @@ array_type_length(VALUE self)
|
|
112
148
|
{
|
113
149
|
ArrayType* array;
|
114
150
|
|
115
|
-
|
151
|
+
TypedData_Get_Struct(self, ArrayType, &rbffi_array_type_data_type, array);
|
116
152
|
|
117
153
|
return UINT2NUM(array->length);
|
118
154
|
}
|
@@ -127,7 +163,7 @@ array_type_element_type(VALUE self)
|
|
127
163
|
{
|
128
164
|
ArrayType* array;
|
129
165
|
|
130
|
-
|
166
|
+
TypedData_Get_Struct(self, ArrayType, &rbffi_array_type_data_type, array);
|
131
167
|
|
132
168
|
return array->rbComponentType;
|
133
169
|
}
|