ffi 1.15.5 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +118 -0
- data/Gemfile +10 -3
- data/README.md +4 -3
- data/Rakefile +25 -10
- data/ext/ffi_c/AbstractMemory.c +99 -74
- data/ext/ffi_c/AbstractMemory.h +3 -2
- data/ext/ffi_c/ArrayType.c +51 -15
- data/ext/ffi_c/ArrayType.h +1 -0
- data/ext/ffi_c/Buffer.c +90 -33
- data/ext/ffi_c/Call.c +29 -12
- data/ext/ffi_c/Call.h +3 -2
- data/ext/ffi_c/DynamicLibrary.c +90 -27
- data/ext/ffi_c/Function.c +244 -98
- data/ext/ffi_c/Function.h +1 -0
- data/ext/ffi_c/FunctionInfo.c +81 -25
- data/ext/ffi_c/LastError.c +29 -11
- data/ext/ffi_c/MappedType.c +66 -23
- data/ext/ffi_c/MappedType.h +0 -2
- data/ext/ffi_c/MemoryPointer.c +36 -9
- data/ext/ffi_c/MethodHandle.c +3 -1
- data/ext/ffi_c/Pointer.c +82 -40
- data/ext/ffi_c/Pointer.h +1 -0
- data/ext/ffi_c/Struct.c +166 -84
- data/ext/ffi_c/Struct.h +7 -4
- data/ext/ffi_c/StructByValue.c +48 -16
- data/ext/ffi_c/StructLayout.c +130 -61
- data/ext/ffi_c/Type.c +120 -51
- data/ext/ffi_c/Type.h +3 -1
- data/ext/ffi_c/Types.c +8 -2
- data/ext/ffi_c/Types.h +0 -1
- data/ext/ffi_c/Variadic.c +71 -26
- data/ext/ffi_c/compat.h +22 -22
- data/ext/ffi_c/extconf.rb +19 -2
- data/ext/ffi_c/ffi.c +4 -0
- data/ext/ffi_c/libffi/.allow-ai-service +0 -0
- data/ext/ffi_c/libffi/.appveyor/site.exp +16 -0
- data/ext/ffi_c/libffi/.appveyor/unix-noexec.exp +7 -0
- data/ext/ffi_c/libffi/.appveyor.yml +27 -9
- data/ext/ffi_c/libffi/.ci/build-cross-in-container.sh +18 -0
- data/ext/ffi_c/libffi/{.travis → .ci}/build-in-container.sh +4 -6
- data/ext/ffi_c/libffi/.ci/build.sh +124 -0
- data/ext/ffi_c/libffi/{.travis → .ci}/install.sh +14 -7
- data/ext/ffi_c/libffi/.ci/msvs-detect +1103 -0
- data/ext/ffi_c/libffi/{.travis → .ci}/site.exp +5 -3
- data/ext/ffi_c/libffi/.circleci/config.yml +156 -0
- data/ext/ffi_c/libffi/.github/workflows/build.yml +479 -0
- data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +172 -0
- data/ext/ffi_c/libffi/.gitignore +10 -2
- data/ext/ffi_c/libffi/LICENSE +1 -1
- data/ext/ffi_c/libffi/Makefile.am +12 -5
- data/ext/ffi_c/libffi/Makefile.in +118 -51
- data/ext/ffi_c/libffi/README.md +150 -105
- data/ext/ffi_c/libffi/acinclude.m4 +10 -112
- data/ext/ffi_c/libffi/compile +348 -0
- data/ext/ffi_c/libffi/config.guess +623 -556
- data/ext/ffi_c/libffi/config.sub +75 -34
- data/ext/ffi_c/libffi/configure +4571 -3830
- data/ext/ffi_c/libffi/configure.ac +64 -28
- data/ext/ffi_c/libffi/configure.host +26 -7
- data/ext/ffi_c/libffi/doc/Makefile.in +9 -6
- data/ext/ffi_c/libffi/doc/libffi.texi +82 -33
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/fficonfig.h.in +12 -47
- data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +163 -52
- data/ext/ffi_c/libffi/include/Makefile.am +1 -1
- data/ext/ffi_c/libffi/include/Makefile.in +10 -9
- data/ext/ffi_c/libffi/include/ffi.h.in +55 -60
- data/ext/ffi_c/libffi/include/ffi_cfi.h +21 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +33 -2
- data/ext/ffi_c/libffi/include/tramp.h +45 -0
- data/ext/ffi_c/libffi/install-sh +92 -69
- data/ext/ffi_c/libffi/libffi.map.in +5 -0
- data/ext/ffi_c/libffi/libtool-version +2 -2
- data/ext/ffi_c/libffi/ltmain.sh +518 -333
- data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +18 -14
- data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +108 -72
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +76 -45
- data/ext/ffi_c/libffi/m4/ax_prepend_flag.m4 +51 -0
- data/ext/ffi_c/libffi/man/Makefile.in +9 -6
- data/ext/ffi_c/libffi/missing +1 -1
- data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +2 -2
- data/ext/ffi_c/libffi/msvcc.sh +1 -1
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +172 -55
- data/ext/ffi_c/libffi/src/aarch64/internal.h +32 -0
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +331 -87
- data/ext/ffi_c/libffi/src/arc/arcompact.S +169 -94
- data/ext/ffi_c/libffi/src/arc/ffi.c +325 -148
- data/ext/ffi_c/libffi/src/arc/ffitarget.h +14 -0
- data/ext/ffi_c/libffi/src/arm/ffi.c +62 -17
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +3 -3
- data/ext/ffi_c/libffi/src/arm/internal.h +10 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +113 -42
- data/ext/ffi_c/libffi/src/closures.c +136 -50
- data/ext/ffi_c/libffi/src/debug.c +2 -2
- data/ext/ffi_c/libffi/src/dlmalloc.c +6 -1
- data/ext/ffi_c/libffi/src/ia64/ffi.c +12 -0
- data/ext/ffi_c/libffi/src/ia64/unix.S +20 -2
- data/ext/ffi_c/libffi/src/loongarch64/ffi.c +624 -0
- data/ext/ffi_c/libffi/src/loongarch64/ffitarget.h +82 -0
- data/ext/ffi_c/libffi/src/loongarch64/sysv.S +327 -0
- data/ext/ffi_c/libffi/src/m32r/ffi.c +31 -14
- data/ext/ffi_c/libffi/src/mips/ffi.c +250 -67
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +7 -0
- data/ext/ffi_c/libffi/src/mips/n32.S +193 -33
- data/ext/ffi_c/libffi/src/mips/o32.S +61 -4
- data/ext/ffi_c/libffi/src/moxie/ffi.c +47 -22
- data/ext/ffi_c/libffi/src/or1k/ffi.c +25 -12
- data/ext/ffi_c/libffi/src/pa/ffi.c +32 -33
- data/ext/ffi_c/libffi/src/pa/ffi64.c +614 -0
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +22 -8
- data/ext/ffi_c/libffi/src/pa/hpux32.S +83 -36
- data/ext/ffi_c/libffi/src/pa/hpux64.S +681 -0
- data/ext/ffi_c/libffi/src/pa/linux.S +82 -35
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +36 -24
- data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1 -1
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +2 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +2 -0
- data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
- data/ext/ffi_c/libffi/src/prep_cif.c +22 -2
- data/ext/ffi_c/libffi/src/riscv/ffi.c +37 -4
- data/ext/ffi_c/libffi/src/sparc/ffi64.c +23 -1
- data/ext/ffi_c/libffi/src/tramp.c +716 -0
- data/ext/ffi_c/libffi/src/types.c +4 -6
- data/ext/ffi_c/libffi/src/wasm32/ffi.c +947 -0
- data/ext/ffi_c/libffi/src/wasm32/ffitarget.h +62 -0
- data/ext/ffi_c/libffi/src/x86/ffi.c +99 -37
- data/ext/ffi_c/libffi/src/x86/ffi64.c +67 -12
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +9 -5
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +44 -1
- data/ext/ffi_c/libffi/src/x86/internal.h +14 -0
- data/ext/ffi_c/libffi/src/x86/internal64.h +14 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +172 -38
- data/ext/ffi_c/libffi/src/x86/sysv_intel.S +91 -88
- data/ext/ffi_c/libffi/src/x86/unix64.S +96 -6
- data/ext/ffi_c/libffi/src/x86/win64.S +20 -7
- data/ext/ffi_c/libffi/src/xtensa/ffi.c +16 -8
- data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +4 -0
- data/ext/ffi_c/libffi/src/xtensa/sysv.S +26 -16
- data/ext/ffi_c/libffi/testsuite/Makefile.am +79 -114
- data/ext/ffi_c/libffi/testsuite/Makefile.in +89 -121
- data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +54 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +63 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +86 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +48 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/test.html +7 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/test_libffi.py +51 -0
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +43 -21
- data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +5 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/bpo_38748.c +41 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/callback.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/callback2.c +108 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/callback3.c +114 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/callback4.c +119 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +28 -3
- data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +5 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/s55.c +60 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +8 -9
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_2.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3f.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4f.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_big.c +93 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_small.c +61 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_2H.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_8H.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -119
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_2.c +220 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_3.c +154 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +15 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn0.c +3 -2
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn1.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn2.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn3.c +21 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn4.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn5.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn6.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_loc_fn0.c +7 -6
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_simple.c +6 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_12byte.c +18 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_16byte.c +22 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_18byte.c +24 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_19byte.c +29 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_1_1byte.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte1.c +21 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_24byte.c +35 -3
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_2byte.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3_1byte.c +19 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte1.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte2.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +18 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4_1byte.c +22 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4byte.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5_1_byte.c +29 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5byte.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_64byte.c +24 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6_1_byte.c +28 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6byte.c +24 -2
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7_1_byte.c +39 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7byte.c +25 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_8byte.c +14 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte1.c +14 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte2.c +14 -2
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_double.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_float.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble.c +20 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split.c +40 -25
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split2.c +40 -3
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_pointer.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint16.c +18 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint32.c +18 -3
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint64.c +18 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint16.c +18 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint32.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint64.c +19 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_dbls_struct.c +3 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_double_va.c +9 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_float.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble.c +11 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble_va.c +22 -3
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_schar.c +5 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshort.c +6 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshortchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_uchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushort.c +6 -2
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushortchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer.c +5 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer_stack.c +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_schar.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sint.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sshort.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulonglong.c +2 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +1 -138
- data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +21 -21
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct.c +32 -9
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct1.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct10.c +12 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +21 -5
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct12.c +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct13.c +115 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct2.c +10 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct3.c +10 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct4.c +9 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct5.c +9 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct6.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct7.c +9 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct8.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct9.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs1.c +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs2.c +102 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs3.c +101 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium2.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/testclosure.c +6 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest.cc +2 -1
- data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest_ffi_call.cc +1 -0
- data/ext/ffi_c/libffi.bsd.mk +2 -2
- data/ext/ffi_c/libffi.darwin.mk +2 -2
- data/ext/ffi_c/libffi.gnu.mk +2 -2
- data/ext/ffi_c/rbffi.h +1 -1
- data/ffi.gemspec +3 -3
- data/lib/ffi/autopointer.rb +8 -31
- data/lib/ffi/compat.rb +43 -0
- data/lib/ffi/data_converter.rb +2 -2
- data/lib/ffi/dynamic_library.rb +118 -0
- data/lib/ffi/enum.rb +18 -12
- data/lib/ffi/ffi.rb +3 -0
- data/lib/ffi/function.rb +71 -0
- data/lib/ffi/io.rb +2 -2
- data/lib/ffi/library.rb +72 -88
- data/lib/ffi/library_path.rb +109 -0
- data/lib/ffi/managedstruct.rb +1 -1
- data/lib/ffi/platform/aarch64-linux/types.conf +74 -3
- data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
- data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
- data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
- data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
- data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
- data/lib/ffi/platform.rb +15 -13
- data/lib/ffi/pointer.rb +6 -6
- data/lib/ffi/struct.rb +6 -5
- data/lib/ffi/struct_layout.rb +3 -3
- data/lib/ffi/struct_layout_builder.rb +9 -9
- data/lib/ffi/types.rb +65 -37
- data/lib/ffi/variadic.rb +19 -8
- data/lib/ffi/version.rb +1 -1
- data/samples/hello_ractor.rb +11 -0
- data/samples/qsort_ractor.rb +28 -0
- data/sig/ffi/abstract_memory.rbs +165 -0
- data/sig/ffi/auto_pointer.rbs +27 -0
- data/sig/ffi/buffer.rbs +18 -0
- data/sig/ffi/data_converter.rbs +10 -0
- data/sig/ffi/dynamic_library.rbs +9 -0
- data/sig/ffi/enum.rbs +38 -0
- data/sig/ffi/function.rbs +39 -0
- data/sig/ffi/library.rbs +42 -0
- data/sig/ffi/native_type.rbs +86 -0
- data/sig/ffi/pointer.rbs +42 -0
- data/sig/ffi/struct.rbs +76 -0
- data/sig/ffi/struct_by_reference.rbs +11 -0
- data/sig/ffi/struct_by_value.rbs +7 -0
- data/sig/ffi/struct_layout.rbs +9 -0
- data/sig/ffi/struct_layout_builder.rbs +5 -0
- data/sig/ffi/type.rbs +39 -0
- data/sig/ffi.rbs +26 -0
- data.tar.gz.sig +0 -0
- metadata +122 -28
- metadata.gz.sig +1 -0
- data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +0 -14
- data/ext/ffi_c/libffi/.travis/build.sh +0 -142
- data/ext/ffi_c/libffi/.travis.yml +0 -83
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +0 -44
- data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +0 -44
- /data/ext/ffi_c/libffi/{.travis → .ci}/ar-lib +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/bfin-sim.exp +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/compile +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/m32r-sim.exp +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/moxie-sim.exp +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/or1k-sim.exp +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/powerpc-eabisim.exp +0 -0
- /data/ext/ffi_c/libffi/{.travis → .ci}/wine-sim.exp +0 -0
- /data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
- /data/lib/ffi/platform/{sparc64-linux → sparcv9-linux}/types.conf +0 -0
data/ext/ffi_c/Buffer.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright (c) 2008-2010 Wayne Meissner
|
3
3
|
* Copyright (C) 2009 Aman Gupta <aman@tmm1.net>
|
4
|
-
*
|
4
|
+
*
|
5
5
|
* Copyright (c) 2008-2013, Ruby FFI project contributors
|
6
6
|
* All rights reserved.
|
7
7
|
*
|
@@ -39,7 +39,7 @@
|
|
39
39
|
#define BUFFER_EMBED_MAXLEN (8)
|
40
40
|
typedef struct Buffer {
|
41
41
|
AbstractMemory memory;
|
42
|
-
|
42
|
+
|
43
43
|
union {
|
44
44
|
VALUE rbParent; /* link to parent buffer */
|
45
45
|
char* storage; /* start of malloc area */
|
@@ -49,9 +49,40 @@ typedef struct Buffer {
|
|
49
49
|
|
50
50
|
static VALUE buffer_allocate(VALUE klass);
|
51
51
|
static VALUE buffer_initialize(int argc, VALUE* argv, VALUE self);
|
52
|
-
static void buffer_release(
|
53
|
-
static void buffer_mark(
|
52
|
+
static void buffer_release(void *data);
|
53
|
+
static void buffer_mark(void *data);
|
54
|
+
static void buffer_compact(void *data);
|
54
55
|
static VALUE buffer_free(VALUE self);
|
56
|
+
static size_t allocated_buffer_memsize(const void *data);
|
57
|
+
static size_t buffer_memsize(const void *data);
|
58
|
+
|
59
|
+
static const rb_data_type_t buffer_data_type = {
|
60
|
+
.wrap_struct_name = "FFI::Buffer",
|
61
|
+
.function = {
|
62
|
+
.dmark = buffer_mark,
|
63
|
+
.dfree = RUBY_TYPED_DEFAULT_FREE,
|
64
|
+
.dsize = buffer_memsize,
|
65
|
+
ffi_compact_callback( buffer_compact )
|
66
|
+
},
|
67
|
+
.parent = &rbffi_abstract_memory_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
|
+
|
73
|
+
static const rb_data_type_t allocated_buffer_data_type = {
|
74
|
+
.wrap_struct_name = "FFI::Buffer(allocated)",
|
75
|
+
.function = {
|
76
|
+
.dmark = NULL,
|
77
|
+
.dfree = buffer_release,
|
78
|
+
.dsize = allocated_buffer_memsize,
|
79
|
+
},
|
80
|
+
.parent = &buffer_data_type,
|
81
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
82
|
+
// macro to update VALUE references, as to trigger write barriers.
|
83
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
84
|
+
};
|
85
|
+
|
55
86
|
|
56
87
|
static VALUE BufferClass = Qnil;
|
57
88
|
|
@@ -61,28 +92,29 @@ buffer_allocate(VALUE klass)
|
|
61
92
|
Buffer* buffer;
|
62
93
|
VALUE obj;
|
63
94
|
|
64
|
-
obj =
|
65
|
-
buffer->data.rbParent
|
95
|
+
obj = TypedData_Make_Struct(klass, Buffer, &allocated_buffer_data_type, buffer);
|
96
|
+
RB_OBJ_WRITE(obj, &buffer->data.rbParent, Qnil);
|
66
97
|
buffer->memory.flags = MEM_RD | MEM_WR;
|
67
98
|
|
68
99
|
return obj;
|
69
100
|
}
|
70
101
|
|
71
102
|
static void
|
72
|
-
buffer_release(
|
103
|
+
buffer_release(void *data)
|
73
104
|
{
|
105
|
+
Buffer *ptr = (Buffer *)data;
|
74
106
|
if ((ptr->memory.flags & MEM_EMBED) == 0 && ptr->data.storage != NULL) {
|
75
107
|
xfree(ptr->data.storage);
|
76
108
|
ptr->data.storage = NULL;
|
77
109
|
}
|
78
|
-
|
110
|
+
|
79
111
|
xfree(ptr);
|
80
112
|
}
|
81
113
|
|
82
114
|
/*
|
83
115
|
* call-seq: initialize(size, count=1, clear=false)
|
84
116
|
* @param [Integer, Symbol, #size] Type or size in bytes of a buffer cell
|
85
|
-
* @param [
|
117
|
+
* @param [Integer] count number of cell in the Buffer
|
86
118
|
* @param [Boolean] clear if true, set the buffer to all-zero
|
87
119
|
* @return [self]
|
88
120
|
* @raise {NoMemoryError} if failed to allocate memory for Buffer
|
@@ -95,7 +127,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
95
127
|
Buffer* p;
|
96
128
|
int nargs;
|
97
129
|
|
98
|
-
|
130
|
+
TypedData_Get_Struct(self, Buffer, &buffer_data_type, p);
|
99
131
|
|
100
132
|
nargs = rb_scan_args(argc, argv, "12", &rbSize, &rbCount, &rbClear);
|
101
133
|
p->memory.typeSize = rbffi_type_size(rbSize);
|
@@ -110,11 +142,11 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
110
142
|
|
111
143
|
/* ensure the memory is aligned on at least a 8 byte boundary */
|
112
144
|
p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7ULL);
|
113
|
-
|
145
|
+
|
114
146
|
if (p->memory.size > 0 && (nargs < 3 || RTEST(rbClear))) {
|
115
147
|
memset(p->memory.address, 0, p->memory.size);
|
116
148
|
}
|
117
|
-
|
149
|
+
|
118
150
|
} else {
|
119
151
|
p->memory.flags |= MEM_EMBED;
|
120
152
|
p->memory.address = (void *) &p->data.embed[0];
|
@@ -137,9 +169,9 @@ buffer_initialize_copy(VALUE self, VALUE other)
|
|
137
169
|
{
|
138
170
|
AbstractMemory* src;
|
139
171
|
Buffer* dst;
|
140
|
-
|
141
|
-
|
142
|
-
src = rbffi_AbstractMemory_Cast(other,
|
172
|
+
|
173
|
+
TypedData_Get_Struct(self, Buffer, &buffer_data_type, dst);
|
174
|
+
src = rbffi_AbstractMemory_Cast(other, &buffer_data_type);
|
143
175
|
if ((dst->memory.flags & MEM_EMBED) == 0 && dst->data.storage != NULL) {
|
144
176
|
xfree(dst->data.storage);
|
145
177
|
}
|
@@ -148,11 +180,11 @@ buffer_initialize_copy(VALUE self, VALUE other)
|
|
148
180
|
rb_raise(rb_eNoMemError, "failed to allocate memory size=%lu bytes", src->size);
|
149
181
|
return Qnil;
|
150
182
|
}
|
151
|
-
|
183
|
+
|
152
184
|
dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7ULL);
|
153
185
|
dst->memory.size = src->size;
|
154
186
|
dst->memory.typeSize = src->typeSize;
|
155
|
-
|
187
|
+
|
156
188
|
/* finally, copy the actual buffer contents */
|
157
189
|
memcpy(dst->memory.address, src->address, src->size);
|
158
190
|
|
@@ -171,23 +203,23 @@ slice(VALUE self, long offset, long len)
|
|
171
203
|
Buffer* ptr;
|
172
204
|
Buffer* result;
|
173
205
|
VALUE obj = Qnil;
|
174
|
-
|
175
|
-
|
206
|
+
|
207
|
+
TypedData_Get_Struct(self, Buffer, &buffer_data_type, ptr);
|
176
208
|
checkBounds(&ptr->memory, offset, len);
|
177
209
|
|
178
|
-
obj =
|
210
|
+
obj = TypedData_Make_Struct(BufferClass, Buffer, &buffer_data_type, result);
|
179
211
|
result->memory.address = ptr->memory.address + offset;
|
180
212
|
result->memory.size = len;
|
181
213
|
result->memory.flags = ptr->memory.flags;
|
182
214
|
result->memory.typeSize = ptr->memory.typeSize;
|
183
|
-
result->data.rbParent
|
215
|
+
RB_OBJ_WRITE(obj, &result->data.rbParent, self);
|
184
216
|
|
185
217
|
return obj;
|
186
218
|
}
|
187
219
|
|
188
220
|
/*
|
189
221
|
* call-seq: + offset
|
190
|
-
* @param [
|
222
|
+
* @param [Integer] offset
|
191
223
|
* @return [Buffer] a new instance of Buffer pointing from offset until end of previous buffer.
|
192
224
|
* Add a Buffer with an offset
|
193
225
|
*/
|
@@ -197,15 +229,15 @@ buffer_plus(VALUE self, VALUE rbOffset)
|
|
197
229
|
Buffer* ptr;
|
198
230
|
long offset = NUM2LONG(rbOffset);
|
199
231
|
|
200
|
-
|
232
|
+
TypedData_Get_Struct(self, Buffer, &buffer_data_type, ptr);
|
201
233
|
|
202
234
|
return slice(self, offset, ptr->memory.size - offset);
|
203
235
|
}
|
204
236
|
|
205
237
|
/*
|
206
238
|
* call-seq: slice(offset, length)
|
207
|
-
* @param [
|
208
|
-
* @param [
|
239
|
+
* @param [Integer] offset
|
240
|
+
* @param [Integer] length
|
209
241
|
* @return [Buffer] a new instance of Buffer
|
210
242
|
* Slice an existing Buffer.
|
211
243
|
*/
|
@@ -226,10 +258,10 @@ buffer_inspect(VALUE self)
|
|
226
258
|
char tmp[100];
|
227
259
|
Buffer* ptr;
|
228
260
|
|
229
|
-
|
261
|
+
TypedData_Get_Struct(self, Buffer, &buffer_data_type, ptr);
|
230
262
|
|
231
263
|
snprintf(tmp, sizeof(tmp), "#<FFI:Buffer:%p address=%p size=%ld>", ptr, ptr->memory.address, ptr->memory.size);
|
232
|
-
|
264
|
+
|
233
265
|
return rb_str_new2(tmp);
|
234
266
|
}
|
235
267
|
|
@@ -255,7 +287,7 @@ buffer_order(int argc, VALUE* argv, VALUE self)
|
|
255
287
|
{
|
256
288
|
Buffer* ptr;
|
257
289
|
|
258
|
-
|
290
|
+
TypedData_Get_Struct(self, Buffer, &buffer_data_type, ptr);
|
259
291
|
if (argc == 0) {
|
260
292
|
int order = (ptr->memory.flags & MEM_SWAP) == 0 ? BYTE_ORDER : SWAPPED_ORDER;
|
261
293
|
return order == BIG_ENDIAN ? ID2SYM(rb_intern("big")) : ID2SYM(rb_intern("little"));
|
@@ -279,7 +311,7 @@ buffer_order(int argc, VALUE* argv, VALUE self)
|
|
279
311
|
Buffer* p2;
|
280
312
|
VALUE retval = slice(self, 0, ptr->memory.size);
|
281
313
|
|
282
|
-
|
314
|
+
TypedData_Get_Struct(retval, Buffer, &buffer_data_type, p2);
|
283
315
|
p2->memory.flags |= MEM_SWAP;
|
284
316
|
return retval;
|
285
317
|
}
|
@@ -294,7 +326,7 @@ buffer_free(VALUE self)
|
|
294
326
|
{
|
295
327
|
Buffer* ptr;
|
296
328
|
|
297
|
-
|
329
|
+
TypedData_Get_Struct(self, Buffer, &buffer_data_type, ptr);
|
298
330
|
if ((ptr->memory.flags & MEM_EMBED) == 0 && ptr->data.storage != NULL) {
|
299
331
|
xfree(ptr->data.storage);
|
300
332
|
ptr->data.storage = NULL;
|
@@ -304,9 +336,34 @@ buffer_free(VALUE self)
|
|
304
336
|
}
|
305
337
|
|
306
338
|
static void
|
307
|
-
buffer_mark(
|
339
|
+
buffer_mark(void *data)
|
340
|
+
{
|
341
|
+
Buffer *ptr = (Buffer *)data;
|
342
|
+
rb_gc_mark_movable(ptr->data.rbParent);
|
343
|
+
}
|
344
|
+
|
345
|
+
static void
|
346
|
+
buffer_compact(void *data)
|
347
|
+
{
|
348
|
+
Buffer *ptr = (Buffer *)data;
|
349
|
+
ffi_gc_location(ptr->data.rbParent);
|
350
|
+
}
|
351
|
+
|
352
|
+
static size_t
|
353
|
+
buffer_memsize(const void *data)
|
308
354
|
{
|
309
|
-
|
355
|
+
return sizeof(Buffer);
|
356
|
+
}
|
357
|
+
|
358
|
+
static size_t
|
359
|
+
allocated_buffer_memsize(const void *data)
|
360
|
+
{
|
361
|
+
const Buffer *ptr = (const Buffer *)data;
|
362
|
+
size_t memsize = sizeof(Buffer);
|
363
|
+
if ((ptr->memory.flags & MEM_EMBED) == 0 && ptr->data.storage != NULL) {
|
364
|
+
memsize += ptr->memory.size;
|
365
|
+
}
|
366
|
+
return memsize;
|
310
367
|
}
|
311
368
|
|
312
369
|
void
|
@@ -348,7 +405,7 @@ rbffi_Buffer_Init(VALUE moduleFFI)
|
|
348
405
|
rb_define_alias(rb_singleton_class(BufferClass), "new_in", "alloc_in");
|
349
406
|
rb_define_alias(rb_singleton_class(BufferClass), "new_out", "alloc_out");
|
350
407
|
rb_define_alias(rb_singleton_class(BufferClass), "new_inout", "alloc_inout");
|
351
|
-
|
408
|
+
|
352
409
|
rb_define_method(BufferClass, "initialize", buffer_initialize, -1);
|
353
410
|
rb_define_method(BufferClass, "initialize_copy", buffer_initialize_copy, 1);
|
354
411
|
rb_define_method(BufferClass, "order", buffer_order, -1);
|
data/ext/ffi_c/Call.c
CHANGED
@@ -86,10 +86,11 @@ static inline void* getPointer(VALUE value, int type);
|
|
86
86
|
|
87
87
|
static ID id_to_ptr, id_map_symbol, id_to_native;
|
88
88
|
|
89
|
-
|
89
|
+
VALUE
|
90
90
|
rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
91
91
|
FFIStorage* paramStorage, void** ffiValues,
|
92
|
-
VALUE* callbackParameters, int callbackCount,
|
92
|
+
VALUE* callbackParameters, int callbackCount,
|
93
|
+
VALUE enums)
|
93
94
|
{
|
94
95
|
VALUE callbackProc = Qnil;
|
95
96
|
FFIStorage* param = ¶mStorage[0];
|
@@ -327,6 +328,7 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
327
328
|
rb_raise(rb_eArgError, "Invalid parameter type: %d", paramType->nativeType);
|
328
329
|
}
|
329
330
|
}
|
331
|
+
return callbackProc;
|
330
332
|
}
|
331
333
|
|
332
334
|
static void *
|
@@ -362,6 +364,7 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
362
364
|
FFIStorage* params;
|
363
365
|
VALUE rbReturnValue;
|
364
366
|
rbffi_frame_t frame = { 0 };
|
367
|
+
VALUE callbackProc;
|
365
368
|
|
366
369
|
retval = alloca(MAX(fnInfo->ffi_cif.rtype->size, FFI_SIZEOF_ARG));
|
367
370
|
|
@@ -379,9 +382,10 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
379
382
|
bc->params = params;
|
380
383
|
bc->frame = &frame;
|
381
384
|
|
382
|
-
rbffi_SetupCallParams(argc, argv,
|
385
|
+
callbackProc = rbffi_SetupCallParams(argc, argv,
|
383
386
|
fnInfo->parameterCount, fnInfo->parameterTypes, params, ffiValues,
|
384
|
-
fnInfo->callbackParameters, fnInfo->callbackCount,
|
387
|
+
fnInfo->callbackParameters, fnInfo->callbackCount,
|
388
|
+
fnInfo->rbEnums);
|
385
389
|
|
386
390
|
rbffi_frame_push(&frame);
|
387
391
|
rb_rescue2(rbffi_do_blocking_call, (VALUE) bc, rbffi_save_frame_exception, (VALUE) &frame, rb_eException, (VALUE) 0);
|
@@ -392,14 +396,16 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
392
396
|
ffiValues = ALLOCA_N(void *, fnInfo->parameterCount);
|
393
397
|
params = ALLOCA_N(FFIStorage, fnInfo->parameterCount);
|
394
398
|
|
395
|
-
rbffi_SetupCallParams(argc, argv,
|
399
|
+
callbackProc = rbffi_SetupCallParams(argc, argv,
|
396
400
|
fnInfo->parameterCount, fnInfo->parameterTypes, params, ffiValues,
|
397
|
-
fnInfo->callbackParameters, fnInfo->callbackCount,
|
401
|
+
fnInfo->callbackParameters, fnInfo->callbackCount,
|
402
|
+
fnInfo->rbEnums);
|
398
403
|
|
399
404
|
rbffi_frame_push(&frame);
|
400
405
|
ffi_call(&fnInfo->ffi_cif, FFI_FN(function), retval, ffiValues);
|
401
406
|
rbffi_frame_pop(&frame);
|
402
407
|
}
|
408
|
+
RB_GC_GUARD(callbackProc);
|
403
409
|
|
404
410
|
if (unlikely(!fnInfo->ignoreErrno)) {
|
405
411
|
rbffi_save_errno();
|
@@ -420,11 +426,17 @@ getPointer(VALUE value, int type)
|
|
420
426
|
{
|
421
427
|
if (likely(type == T_DATA && rb_obj_is_kind_of(value, rbffi_AbstractMemoryClass))) {
|
422
428
|
|
423
|
-
|
429
|
+
AbstractMemory *mem;
|
430
|
+
TypedData_Get_Struct(value, AbstractMemory, &rbffi_abstract_memory_data_type, mem);
|
431
|
+
return mem->address;
|
424
432
|
|
425
433
|
} else if (type == T_DATA && rb_obj_is_kind_of(value, rbffi_StructClass)) {
|
426
434
|
|
427
|
-
|
435
|
+
Struct* s;
|
436
|
+
AbstractMemory* memory;
|
437
|
+
|
438
|
+
TypedData_Get_Struct(value, Struct, &rbffi_struct_data_type, s);
|
439
|
+
memory = s->pointer;
|
428
440
|
return memory != NULL ? memory->address : NULL;
|
429
441
|
|
430
442
|
} else if (type == T_STRING) {
|
@@ -439,7 +451,9 @@ getPointer(VALUE value, int type)
|
|
439
451
|
|
440
452
|
VALUE ptr = rb_funcall2(value, id_to_ptr, 0, NULL);
|
441
453
|
if (rb_obj_is_kind_of(ptr, rbffi_AbstractMemoryClass) && TYPE(ptr) == T_DATA) {
|
442
|
-
|
454
|
+
AbstractMemory *mem;
|
455
|
+
TypedData_Get_Struct(ptr, AbstractMemory, &rbffi_abstract_memory_data_type, mem);
|
456
|
+
return mem->address;
|
443
457
|
}
|
444
458
|
rb_raise(rb_eArgError, "to_ptr returned an invalid pointer");
|
445
459
|
}
|
@@ -458,7 +472,9 @@ rbffi_GetInvoker(FunctionType *fnInfo)
|
|
458
472
|
static void*
|
459
473
|
callback_param(VALUE proc, VALUE cbInfo)
|
460
474
|
{
|
461
|
-
VALUE callback
|
475
|
+
VALUE callback;
|
476
|
+
AbstractMemory *mem;
|
477
|
+
|
462
478
|
if (unlikely(proc == Qnil)) {
|
463
479
|
return NULL ;
|
464
480
|
}
|
@@ -466,14 +482,15 @@ callback_param(VALUE proc, VALUE cbInfo)
|
|
466
482
|
/* Handle Function pointers here */
|
467
483
|
if (rb_obj_is_kind_of(proc, rbffi_FunctionClass)) {
|
468
484
|
AbstractMemory* ptr;
|
469
|
-
|
485
|
+
TypedData_Get_Struct(proc, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
|
470
486
|
return ptr->address;
|
471
487
|
}
|
472
488
|
|
473
489
|
callback = rbffi_Function_ForProc(cbInfo, proc);
|
474
490
|
RB_GC_GUARD(callback);
|
475
491
|
|
476
|
-
|
492
|
+
TypedData_Get_Struct(callback, AbstractMemory, &rbffi_abstract_memory_data_type, mem);
|
493
|
+
return mem->address;
|
477
494
|
}
|
478
495
|
|
479
496
|
|
data/ext/ffi_c/Call.h
CHANGED
@@ -73,9 +73,10 @@ typedef union {
|
|
73
73
|
|
74
74
|
extern void rbffi_Call_Init(VALUE moduleFFI);
|
75
75
|
|
76
|
-
extern
|
76
|
+
extern VALUE rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
77
77
|
FFIStorage* paramStorage, void** ffiValues,
|
78
|
-
VALUE* callbackParameters, int callbackCount,
|
78
|
+
VALUE* callbackParameters, int callbackCount,
|
79
|
+
VALUE enums);
|
79
80
|
|
80
81
|
struct FunctionType_;
|
81
82
|
extern VALUE rbffi_CallFunction(int argc, VALUE* argv, void* function, struct FunctionType_* fnInfo);
|
data/ext/ffi_c/DynamicLibrary.c
CHANGED
@@ -50,17 +50,45 @@
|
|
50
50
|
|
51
51
|
typedef struct LibrarySymbol_ {
|
52
52
|
Pointer base;
|
53
|
-
VALUE library;
|
54
53
|
VALUE name;
|
55
54
|
} LibrarySymbol;
|
56
55
|
|
57
|
-
static VALUE library_initialize(VALUE self, VALUE libname, VALUE libflags);
|
58
|
-
static void library_free(Library* lib);
|
59
56
|
|
57
|
+
static VALUE library_initialize(VALUE self, VALUE libname, VALUE libflags);
|
58
|
+
static void library_free(void *);
|
59
|
+
static size_t library_memsize(const void *);
|
60
60
|
|
61
61
|
static VALUE symbol_allocate(VALUE klass);
|
62
62
|
static VALUE symbol_new(VALUE library, void* address, VALUE name);
|
63
|
-
static void symbol_mark(
|
63
|
+
static void symbol_mark(void *data);
|
64
|
+
static void symbol_compact(void *data);
|
65
|
+
static size_t symbol_memsize(const void *data);
|
66
|
+
|
67
|
+
static const rb_data_type_t rbffi_library_data_type = {
|
68
|
+
.wrap_struct_name = "FFI::DynamicLibrary",
|
69
|
+
.function = {
|
70
|
+
.dmark = NULL,
|
71
|
+
.dfree = library_free,
|
72
|
+
.dsize = library_memsize,
|
73
|
+
},
|
74
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
75
|
+
// macro to update VALUE references, as to trigger write barriers.
|
76
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
77
|
+
};
|
78
|
+
|
79
|
+
static const rb_data_type_t library_symbol_data_type = {
|
80
|
+
.wrap_struct_name = "FFI::DynamicLibrary::Symbol",
|
81
|
+
.function = {
|
82
|
+
.dmark = symbol_mark,
|
83
|
+
.dfree = RUBY_TYPED_DEFAULT_FREE,
|
84
|
+
.dsize = symbol_memsize,
|
85
|
+
ffi_compact_callback( symbol_compact )
|
86
|
+
},
|
87
|
+
.parent = &rbffi_pointer_data_type,
|
88
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
89
|
+
// macro to update VALUE references, as to trigger write barriers.
|
90
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
91
|
+
};
|
64
92
|
|
65
93
|
static VALUE LibraryClass = Qnil, SymbolClass = Qnil;
|
66
94
|
|
@@ -80,7 +108,7 @@ static VALUE
|
|
80
108
|
library_allocate(VALUE klass)
|
81
109
|
{
|
82
110
|
Library* library;
|
83
|
-
return
|
111
|
+
return TypedData_Make_Struct(klass, Library, &rbffi_library_data_type, library);
|
84
112
|
}
|
85
113
|
|
86
114
|
/*
|
@@ -100,7 +128,7 @@ library_open(VALUE klass, VALUE libname, VALUE libflags)
|
|
100
128
|
/*
|
101
129
|
* call-seq: initialize(libname, libflags)
|
102
130
|
* @param [String] libname name of library to open
|
103
|
-
* @param [
|
131
|
+
* @param [Integer] libflags flags for library to open
|
104
132
|
* @return [FFI::DynamicLibrary]
|
105
133
|
* @raise {LoadError} if +libname+ cannot be opened
|
106
134
|
* A new DynamicLibrary instance.
|
@@ -113,9 +141,9 @@ library_initialize(VALUE self, VALUE libname, VALUE libflags)
|
|
113
141
|
|
114
142
|
Check_Type(libflags, T_FIXNUM);
|
115
143
|
|
116
|
-
|
144
|
+
TypedData_Get_Struct(self, Library, &rbffi_library_data_type, library);
|
117
145
|
flags = libflags != Qnil ? NUM2UINT(libflags) : 0;
|
118
|
-
|
146
|
+
|
119
147
|
library->handle = dl_open(libname != Qnil ? StringValueCStr(libname) : NULL, flags);
|
120
148
|
if (library->handle == NULL) {
|
121
149
|
char errmsg[1024];
|
@@ -133,7 +161,9 @@ library_initialize(VALUE self, VALUE libname, VALUE libflags)
|
|
133
161
|
library->handle = RTLD_DEFAULT;
|
134
162
|
}
|
135
163
|
#endif
|
136
|
-
rb_iv_set(self, "@name", libname != Qnil ? libname : rb_str_new2("[current process]"));
|
164
|
+
rb_iv_set(self, "@name", libname != Qnil ? rb_str_new_frozen(libname) : rb_str_new2("[current process]"));
|
165
|
+
|
166
|
+
rb_obj_freeze(self);
|
137
167
|
return self;
|
138
168
|
}
|
139
169
|
|
@@ -144,9 +174,9 @@ library_dlsym(VALUE self, VALUE name)
|
|
144
174
|
void* address = NULL;
|
145
175
|
Check_Type(name, T_STRING);
|
146
176
|
|
147
|
-
|
177
|
+
TypedData_Get_Struct(self, Library, &rbffi_library_data_type, library);
|
148
178
|
address = dl_sym(library->handle, StringValueCStr(name));
|
149
|
-
|
179
|
+
|
150
180
|
return address != NULL ? symbol_new(self, address, name) : Qnil;
|
151
181
|
}
|
152
182
|
|
@@ -163,8 +193,10 @@ library_dlerror(VALUE self)
|
|
163
193
|
}
|
164
194
|
|
165
195
|
static void
|
166
|
-
library_free(
|
196
|
+
library_free(void *data)
|
167
197
|
{
|
198
|
+
Library *library = (Library*)data;
|
199
|
+
|
168
200
|
/* dlclose() on MacOS tends to segfault - avoid it */
|
169
201
|
#ifndef __APPLE__
|
170
202
|
if (library->handle != NULL) {
|
@@ -174,6 +206,12 @@ library_free(Library* library)
|
|
174
206
|
xfree(library);
|
175
207
|
}
|
176
208
|
|
209
|
+
static size_t
|
210
|
+
library_memsize(const void *data)
|
211
|
+
{
|
212
|
+
return sizeof(Library);
|
213
|
+
}
|
214
|
+
|
177
215
|
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(__CYGWIN__)
|
178
216
|
static void*
|
179
217
|
dl_open(const char* name, int flags)
|
@@ -189,8 +227,19 @@ dl_open(const char* name, int flags)
|
|
189
227
|
static void
|
190
228
|
dl_error(char* buf, int size)
|
191
229
|
{
|
192
|
-
|
193
|
-
|
230
|
+
// Get the last error code
|
231
|
+
DWORD error = GetLastError();
|
232
|
+
|
233
|
+
// Get the associated message
|
234
|
+
LPSTR message = NULL;
|
235
|
+
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
236
|
+
NULL, error, 0, (LPSTR)&message, 0, NULL);
|
237
|
+
|
238
|
+
// Update the passed in buffer
|
239
|
+
snprintf(buf, size, "Failed with error %d: %s", error, message);
|
240
|
+
|
241
|
+
// Free the allocated message
|
242
|
+
LocalFree(message);
|
194
243
|
}
|
195
244
|
#endif
|
196
245
|
|
@@ -198,10 +247,9 @@ static VALUE
|
|
198
247
|
symbol_allocate(VALUE klass)
|
199
248
|
{
|
200
249
|
LibrarySymbol* sym;
|
201
|
-
VALUE obj =
|
202
|
-
sym->
|
203
|
-
sym->
|
204
|
-
sym->base.rbParent = Qnil;
|
250
|
+
VALUE obj = TypedData_Make_Struct(klass, LibrarySymbol, &library_symbol_data_type, sym);
|
251
|
+
RB_OBJ_WRITE(obj, &sym->base.rbParent, Qnil);
|
252
|
+
RB_OBJ_WRITE(obj, &sym->name, Qnil);
|
205
253
|
|
206
254
|
return obj;
|
207
255
|
}
|
@@ -224,23 +272,39 @@ static VALUE
|
|
224
272
|
symbol_new(VALUE library, void* address, VALUE name)
|
225
273
|
{
|
226
274
|
LibrarySymbol* sym;
|
227
|
-
VALUE obj =
|
275
|
+
VALUE obj = TypedData_Make_Struct(SymbolClass, LibrarySymbol, &library_symbol_data_type, sym);
|
228
276
|
|
229
277
|
sym->base.memory.address = address;
|
230
278
|
sym->base.memory.size = LONG_MAX;
|
231
279
|
sym->base.memory.typeSize = 1;
|
232
280
|
sym->base.memory.flags = MEM_RD | MEM_WR;
|
233
|
-
sym->
|
234
|
-
sym->name
|
281
|
+
RB_OBJ_WRITE(obj, &sym->base.rbParent, library);
|
282
|
+
RB_OBJ_WRITE(obj, &sym->name, rb_str_new_frozen(name));
|
235
283
|
|
284
|
+
rb_obj_freeze(obj);
|
236
285
|
return obj;
|
237
286
|
}
|
238
287
|
|
239
288
|
static void
|
240
|
-
symbol_mark(
|
289
|
+
symbol_mark(void *data)
|
290
|
+
{
|
291
|
+
LibrarySymbol *sym = (LibrarySymbol *)data;
|
292
|
+
rb_gc_mark_movable(sym->base.rbParent);
|
293
|
+
rb_gc_mark_movable(sym->name);
|
294
|
+
}
|
295
|
+
|
296
|
+
static void
|
297
|
+
symbol_compact(void *data)
|
241
298
|
{
|
242
|
-
|
243
|
-
|
299
|
+
LibrarySymbol *sym = (LibrarySymbol *)data;
|
300
|
+
ffi_gc_location(sym->base.rbParent);
|
301
|
+
ffi_gc_location(sym->name);
|
302
|
+
}
|
303
|
+
|
304
|
+
static size_t
|
305
|
+
symbol_memsize(const void *data)
|
306
|
+
{
|
307
|
+
return sizeof(LibrarySymbol);
|
244
308
|
}
|
245
309
|
|
246
310
|
/*
|
@@ -254,8 +318,8 @@ symbol_inspect(VALUE self)
|
|
254
318
|
LibrarySymbol* sym;
|
255
319
|
char buf[256];
|
256
320
|
|
257
|
-
|
258
|
-
snprintf(buf, sizeof(buf), "#<FFI::
|
321
|
+
TypedData_Get_Struct(self, LibrarySymbol, &library_symbol_data_type, sym);
|
322
|
+
snprintf(buf, sizeof(buf), "#<FFI::DynamicLibrary::Symbol name=%s address=%p>",
|
259
323
|
StringValueCStr(sym->name), sym->base.memory.address);
|
260
324
|
return rb_str_new2(buf);
|
261
325
|
}
|
@@ -331,4 +395,3 @@ rbffi_DynamicLibrary_Init(VALUE moduleFFI)
|
|
331
395
|
#undef DEF
|
332
396
|
|
333
397
|
}
|
334
|
-
|