ffi 1.12.2-java → 1.14.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +82 -0
- data/Gemfile +17 -0
- data/LICENSE.SPECS +22 -0
- data/README.md +10 -2
- data/Rakefile +31 -43
- data/ffi.gemspec +43 -0
- data/lib/ffi.rb +28 -0
- data/lib/ffi/abstract_memory.rb +44 -0
- data/lib/ffi/autopointer.rb +203 -0
- data/lib/ffi/buffer.rb +4 -0
- data/lib/ffi/callback.rb +4 -0
- data/lib/ffi/data_converter.rb +67 -0
- data/lib/ffi/enum.rb +296 -0
- data/lib/ffi/errno.rb +43 -0
- data/lib/ffi/ffi.rb +47 -0
- data/lib/ffi/io.rb +62 -0
- data/lib/ffi/library.rb +592 -0
- data/lib/ffi/managedstruct.rb +84 -0
- data/lib/ffi/memorypointer.rb +1 -0
- data/lib/ffi/platform.rb +188 -0
- 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 +128 -0
- data/lib/ffi/platform/aarch64-linux/types.conf +104 -0
- data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -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 +132 -0
- data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
- data/lib/ffi/platform/i386-darwin/types.conf +100 -0
- data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
- data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
- data/lib/ffi/platform/i386-gnu/types.conf +107 -0
- data/lib/ffi/platform/i386-linux/types.conf +103 -0
- data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
- data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
- data/lib/ffi/platform/i386-solaris/types.conf +122 -0
- data/lib/ffi/platform/i386-windows/types.conf +52 -0
- data/lib/ffi/platform/ia64-linux/types.conf +104 -0
- data/lib/ffi/platform/mips-linux/types.conf +102 -0
- data/lib/ffi/platform/mips64-linux/types.conf +104 -0
- data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
- data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
- data/lib/ffi/platform/mipsisa32r6-linux/types.conf +102 -0
- data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +102 -0
- data/lib/ffi/platform/mipsisa64r6-linux/types.conf +104 -0
- data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +104 -0
- data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
- data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
- data/lib/ffi/platform/powerpc-linux/types.conf +130 -0
- data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
- data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
- data/lib/ffi/platform/s390-linux/types.conf +102 -0
- data/lib/ffi/platform/s390x-linux/types.conf +102 -0
- data/lib/ffi/platform/sparc-linux/types.conf +102 -0
- data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
- data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
- data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
- data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
- data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
- data/lib/ffi/platform/x86_64-darwin/types.conf +130 -0
- data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
- data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
- 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 +132 -0
- data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
- data/lib/ffi/platform/x86_64-netbsd/types.conf +128 -0
- data/lib/ffi/platform/x86_64-openbsd/types.conf +134 -0
- data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
- data/lib/ffi/platform/x86_64-windows/types.conf +52 -0
- data/lib/ffi/pointer.rb +167 -0
- data/lib/ffi/struct.rb +316 -0
- data/lib/ffi/struct_by_reference.rb +72 -0
- data/lib/ffi/struct_layout.rb +96 -0
- data/lib/ffi/struct_layout_builder.rb +227 -0
- data/lib/ffi/tools/const_generator.rb +230 -0
- data/lib/ffi/tools/generator.rb +105 -0
- data/lib/ffi/tools/generator_task.rb +32 -0
- data/lib/ffi/tools/struct_generator.rb +194 -0
- data/lib/ffi/tools/types_generator.rb +137 -0
- data/lib/ffi/types.rb +194 -0
- data/lib/ffi/union.rb +43 -0
- data/lib/ffi/variadic.rb +78 -0
- data/lib/ffi/version.rb +3 -0
- data/samples/getlogin.rb +8 -0
- data/samples/getpid.rb +8 -0
- data/samples/gettimeofday.rb +18 -0
- data/samples/hello.rb +8 -0
- data/samples/inotify.rb +60 -0
- data/samples/pty.rb +75 -0
- data/samples/qsort.rb +20 -0
- metadata +175 -29
- checksums.yaml.gz.sig +0 -3
- data.tar.gz.sig +0 -3
- metadata.gz.sig +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bff6b764ee96e1b33db643522c7b3f89c903ac1fc1422f41b66f1cf601711fc
|
4
|
+
data.tar.gz: 845a681f7537a7d3c5533d241456f6a430bd2f1cccba58b8c03f48bdf4dc8687
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0207509609d10fb9ebae3652e844ef33422812992fa9791ac39741fc93a75c6534a3a4c8951937e0a5af7968a7d3640de7f302faf946bf8ee37f39483c59d28
|
7
|
+
data.tar.gz: adc882521c77e61803b5cd3d4ecbb9543f9f6ab0beae7094350ce96cf69e5297cf8b2002b7c9957a8679c2d4fba95bf2f2d0638d211e1ed6be0d632c475caf12
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,85 @@
|
|
1
|
+
1.14.2 / 2020-12-21
|
2
|
+
-------------------
|
3
|
+
|
4
|
+
Fixed:
|
5
|
+
* Fix builtin libffi on newer Ubuntu caused by an outdated Makefile.in . #863
|
6
|
+
|
7
|
+
|
8
|
+
1.14.1 / 2020-12-19
|
9
|
+
-------------------
|
10
|
+
|
11
|
+
Changed:
|
12
|
+
* Revert changes to FFI::Pointer#write_string made in ffi-1.14.0.
|
13
|
+
It breaks compatibilty in a way that can cause hard to find errors. #857
|
14
|
+
|
15
|
+
|
16
|
+
1.14.0 / 2020-12-18
|
17
|
+
-------------------
|
18
|
+
|
19
|
+
Added:
|
20
|
+
* Add types.conf for x86_64-msys, x86_64-haiku, aarch64-openbsd and aarch64-darwin (alias arm64-darwin)
|
21
|
+
* Add method AbstractMemory#size_limit? . #829
|
22
|
+
* Add new extconf option --enable-libffi-alloc which is enabled per default on Apple M1 (arm64-darwin).
|
23
|
+
|
24
|
+
Changed:
|
25
|
+
* Do NULL pointer check only when array length > 0 . #305
|
26
|
+
* Raise an error on an unknown order argument. #830
|
27
|
+
* Change FFI::Pointer#write_string to terminate with a NUL byte like other string methods. #805
|
28
|
+
* Update bundled libffi to latest master.
|
29
|
+
|
30
|
+
Removed:
|
31
|
+
* Remove win32/stdint.h and stdbool.h because of copyright issue. #693
|
32
|
+
|
33
|
+
Fixed:
|
34
|
+
* Fix possible UTF-8 load error in loader script interpretation. #792
|
35
|
+
* Fix segfault on non-array argument to #write_array_of_*
|
36
|
+
* Fix memory leak in MethodHandle . #815
|
37
|
+
* Fix possible segfault in combination with fiddle or other libffi using gems . #835
|
38
|
+
* Fix possibility to use ffi ruby gem with JRuby-9.3 . #763
|
39
|
+
* Fix a GC issue, when a callback Proc is used on more than 2 callback signatures. #820
|
40
|
+
|
41
|
+
|
42
|
+
1.13.1 / 2020-06-09
|
43
|
+
-------------------
|
44
|
+
|
45
|
+
Changed:
|
46
|
+
* Revert use of `ucrtbase.dll` as default C library on Windows-MINGW.
|
47
|
+
`ucrtbase.dll` is still used on MSWIN target. #790
|
48
|
+
* Test for `ffi_prep_closure_loc()` to make sure we can use this function.
|
49
|
+
This fixes incorrect use of system libffi on MacOS Mojave (10.14). #787
|
50
|
+
* Update types.conf on x86_64-dragonflybsd
|
51
|
+
|
52
|
+
|
53
|
+
1.13.0 / 2020-06-01
|
54
|
+
-------------------
|
55
|
+
|
56
|
+
Added:
|
57
|
+
* Add TruffleRuby support. Almost all specs are running on TruffleRuby and succeed. #768
|
58
|
+
* Add ruby source files to the java gem. This allows to ship the Ruby library code per platform java gem and add it as a default gem to JRuby. #763
|
59
|
+
* Add FFI::Platform::LONG_DOUBLE_SIZE
|
60
|
+
* Add bounds checks for writing to an inline char[] . #756
|
61
|
+
* Add long double as callback return value. #771
|
62
|
+
* Update type definitions and add types from stdint.h and stddef.h on i386-windows, x86_64-windows, x86_64-darwin, x86_64-linux, arm-linux, powerpc-linux. #749
|
63
|
+
* Add new type definitions for powerpc-openbsd and sparcv9-openbsd. #775, #778
|
64
|
+
|
65
|
+
Changed:
|
66
|
+
* Raise required ruby version to >= 2.3.
|
67
|
+
* Lots of cleanups and improvements in library, specs and benchmarks.
|
68
|
+
* Fix a lot of compiler warnings at the C-extension
|
69
|
+
* Fix several install issues on MacOS:
|
70
|
+
* Look for libffi in SDK paths, since recent versions of macOS removed it from `/usr/include` . #757
|
71
|
+
* Fix error `ld: library not found for -lgcc_s.10.4`
|
72
|
+
* Don't built for i386 architecture as it is deprecated
|
73
|
+
* Several fixes for MSVC build on Windows. #779
|
74
|
+
* Use `ucrtbase.dll` as default C library on Windows instead of old `msvcrt.dll`. #779
|
75
|
+
* Update builtin libffi to fix a Powerpc issue with parameters of type long
|
76
|
+
* Allow unmodified sourcing of (the ruby code of) this gem in JRuby and TruffleRuby as a default gem. #747
|
77
|
+
* Improve check to detect if a module has a #find_type method suitable for FFI. This fixes compatibility with stdlib `mkmf` . #776
|
78
|
+
|
79
|
+
Removed:
|
80
|
+
* Reject callback with `:string` return type at definition, because it didn't work so far and is not save to use. #751, #782
|
81
|
+
|
82
|
+
|
1
83
|
1.12.2 / 2020-02-01
|
2
84
|
-------------------
|
3
85
|
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem 'rake', '~> 13.0'
|
5
|
+
gem 'rake-compiler', '~> 1.0.3'
|
6
|
+
gem 'rake-compiler-dock', '~> 1.0'
|
7
|
+
gem 'rspec', '~> 3.0'
|
8
|
+
# irb is a dependency of rubygems-tasks 0.2.5.
|
9
|
+
# irb versions > 1.1.1 depend on reline,
|
10
|
+
# which sometimes causes 'bundle install' to fail on Ruby <= 2.4: https://github.com/rubygems/rubygems/issues/3463
|
11
|
+
gem 'rubygems-tasks', '>= 0.2', '< 0.2.5', :require => 'rubygems/tasks'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :doc do
|
15
|
+
gem 'kramdown'
|
16
|
+
gem 'yard', '~> 0.9'
|
17
|
+
end
|
data/LICENSE.SPECS
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2008-2012 Ruby-FFI contributors
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Ruby-FFI https://github.com/ffi/ffi/wiki [![Build Status](https://travis-ci.
|
1
|
+
# Ruby-FFI https://github.com/ffi/ffi/wiki [![Build Status](https://travis-ci.com/ffi/ffi.svg?branch=master)](https://travis-ci.com/ffi/ffi) [![Build status Windows](https://ci.appveyor.com/api/projects/status/r8wxn1sd4s794gg1/branch/master?svg=true)](https://ci.appveyor.com/project/larskanis/ffi-aofqa/branch/master)
|
2
2
|
|
3
3
|
## Description
|
4
4
|
|
@@ -66,10 +66,18 @@ From rubygems:
|
|
66
66
|
or from the git repository on github:
|
67
67
|
|
68
68
|
git clone git://github.com/ffi/ffi.git
|
69
|
-
git submodule update --init --recursive
|
70
69
|
cd ffi
|
70
|
+
git submodule update --init --recursive
|
71
|
+
bundle install
|
71
72
|
rake install
|
72
73
|
|
74
|
+
### Install options:
|
75
|
+
|
76
|
+
* `--enable-system-libffi` : Force usage of system libffi
|
77
|
+
* `--disable-system-libffi` : Force usage of builtin libffi
|
78
|
+
* `--enable-libffi-alloc` : Force closure allocation by libffi
|
79
|
+
* `--disable-libffi-alloc` : Force closure allocation by builtin method
|
80
|
+
|
73
81
|
## License
|
74
82
|
|
75
83
|
The ffi library is covered by the BSD license, also see the LICENSE file.
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems/tasks'
|
2
2
|
require 'rbconfig'
|
3
3
|
require 'rake/clean'
|
4
|
-
|
4
|
+
require_relative "lib/ffi/version"
|
5
5
|
|
6
6
|
require 'date'
|
7
7
|
require 'fileutils'
|
@@ -9,10 +9,6 @@ require 'rbconfig'
|
|
9
9
|
require 'rspec/core/rake_task'
|
10
10
|
require 'rubygems/package_task'
|
11
11
|
|
12
|
-
def java?
|
13
|
-
/java/ === RUBY_PLATFORM
|
14
|
-
end
|
15
|
-
|
16
12
|
BUILD_DIR = "build"
|
17
13
|
BUILD_EXT_DIR = File.join(BUILD_DIR, "#{RbConfig::CONFIG['arch']}", 'ffi_c', RUBY_VERSION)
|
18
14
|
|
@@ -20,17 +16,8 @@ def gem_spec
|
|
20
16
|
@gem_spec ||= Gem::Specification.load('ffi.gemspec')
|
21
17
|
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
RSpec::Core::RakeTask.new(:spec) do |config|
|
26
|
-
config.rspec_opts = YAML.load_file 'spec/spec.opts'
|
27
|
-
end
|
28
|
-
else
|
29
|
-
RSpec::Core::RakeTask.new(:spec => :compile) do |config|
|
30
|
-
config.rspec_opts = YAML.load_file 'spec/spec.opts'
|
31
|
-
end
|
32
|
-
|
33
|
-
TEST_DEPS.unshift :compile
|
19
|
+
RSpec::Core::RakeTask.new(:spec => :compile) do |config|
|
20
|
+
config.rspec_opts = YAML.load_file 'spec/spec.opts'
|
34
21
|
end
|
35
22
|
|
36
23
|
desc "Build all packages"
|
@@ -50,6 +37,13 @@ CLEAN.include "pkg/ffi-*-{mingw32,java}"
|
|
50
37
|
CLEAN.include 'lib/1.*'
|
51
38
|
CLEAN.include 'lib/2.*'
|
52
39
|
|
40
|
+
# clean all shipped files, that are not in git
|
41
|
+
CLEAN.include(
|
42
|
+
gem_spec.files -
|
43
|
+
`git --git-dir ext/ffi_c/libffi/.git ls-files -z`.split("\x0").map { |f| File.join("ext/ffi_c/libffi", f) } -
|
44
|
+
`git ls-files -z`.split("\x0")
|
45
|
+
)
|
46
|
+
|
53
47
|
task :distclean => :clobber
|
54
48
|
|
55
49
|
desc "Test the extension"
|
@@ -58,37 +52,29 @@ task :test => [ :spec ]
|
|
58
52
|
|
59
53
|
namespace :bench do
|
60
54
|
ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000
|
61
|
-
|
62
|
-
bench_files = Dir["bench/bench_*.rb"].reject { |f| f == "bench/bench_helper.rb" }
|
55
|
+
bench_files = Dir["bench/bench_*.rb"].sort.reject { |f| f == "bench/bench_helper.rb" }
|
63
56
|
bench_files.each do |bench|
|
64
|
-
task File.basename(bench, ".rb")[6..-1] =>
|
65
|
-
sh %{#{Gem.ruby} #{
|
57
|
+
task File.basename(bench, ".rb")[6..-1] => :compile do
|
58
|
+
sh %{#{Gem.ruby} #{bench} #{ITER}}
|
66
59
|
end
|
67
60
|
end
|
68
|
-
task :all =>
|
61
|
+
task :all => :compile do
|
69
62
|
bench_files.each do |bench|
|
70
|
-
sh %{#{Gem.ruby} #{
|
63
|
+
sh %{#{Gem.ruby} #{bench}}
|
71
64
|
end
|
72
65
|
end
|
73
66
|
end
|
74
67
|
|
75
|
-
task 'spec:run' =>
|
76
|
-
task 'spec:specdoc' =>
|
68
|
+
task 'spec:run' => :compile
|
69
|
+
task 'spec:specdoc' => :compile
|
77
70
|
|
78
71
|
task :default => :spec
|
79
72
|
|
80
73
|
namespace 'java' do
|
81
74
|
|
82
|
-
java_gem_spec =
|
83
|
-
s.
|
84
|
-
s.
|
85
|
-
s.author = gem_spec.author
|
86
|
-
s.email = gem_spec.email
|
87
|
-
s.homepage = gem_spec.homepage
|
88
|
-
s.summary = gem_spec.summary
|
89
|
-
s.description = gem_spec.description
|
90
|
-
s.files = %w(LICENSE COPYING README.md CHANGELOG.md Rakefile)
|
91
|
-
s.license = gem_spec.license
|
75
|
+
java_gem_spec = gem_spec.dup.tap do |s|
|
76
|
+
s.files.reject! { |f| File.fnmatch?("ext/*", f) }
|
77
|
+
s.extensions = []
|
92
78
|
s.platform = 'java'
|
93
79
|
end
|
94
80
|
|
@@ -101,7 +87,7 @@ end
|
|
101
87
|
|
102
88
|
task 'gem:java' => 'java:gem'
|
103
89
|
|
104
|
-
|
90
|
+
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
|
105
91
|
require 'rake/extensiontask'
|
106
92
|
Rake::ExtensionTask.new('ffi_c', gem_spec) do |ext|
|
107
93
|
ext.name = 'ffi_c' # indicate the name of the extension.
|
@@ -124,13 +110,17 @@ unless java?
|
|
124
110
|
sh "x86_64-w64-mingw32-strip -S build/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
|
125
111
|
end
|
126
112
|
end
|
113
|
+
else
|
114
|
+
task :compile do
|
115
|
+
STDERR.puts "Nothing to compile on #{RUBY_ENGINE}"
|
116
|
+
end
|
127
117
|
end
|
128
118
|
|
129
119
|
desc "build a windows gem without all the ceremony"
|
130
120
|
task "gem:windows" do
|
131
121
|
require "rake_compiler_dock"
|
132
122
|
sh "bundle package"
|
133
|
-
RakeCompilerDock.sh "sudo apt-get update && sudo apt-get install -y libltdl-dev && bundle --local && rake cross native gem MAKE='nice make -j`nproc`'"
|
123
|
+
RakeCompilerDock.sh "sudo apt-get update && sudo apt-get install -y libltdl-dev && bundle --local && rake cross native gem MAKE='nice make -j`nproc`' RUBY_CC_VERSION=${RUBY_CC_VERSION/:2.2.2/}"
|
134
124
|
end
|
135
125
|
|
136
126
|
directory "ext/ffi_c/libffi"
|
@@ -158,16 +148,15 @@ end.each do |f|
|
|
158
148
|
end
|
159
149
|
end
|
160
150
|
|
161
|
-
|
162
|
-
require 'ffi/platform'
|
151
|
+
require_relative "lib/ffi/platform"
|
163
152
|
types_conf = File.expand_path(File.join(FFI::Platform::CONF_DIR, 'types.conf'))
|
164
153
|
logfile = File.join(File.dirname(__FILE__), 'types_log')
|
165
154
|
|
166
|
-
|
155
|
+
task types_conf do |task|
|
167
156
|
require 'fileutils'
|
168
|
-
|
157
|
+
require_relative "lib/ffi/tools/types_generator"
|
169
158
|
options = {}
|
170
|
-
FileUtils.mkdir_p(File.dirname(task.name),
|
159
|
+
FileUtils.mkdir_p(File.dirname(task.name), mode: 0755 )
|
171
160
|
File.open(task.name, File::CREAT|File::TRUNC|File::RDWR, 0644) do |f|
|
172
161
|
f.puts FFI::TypesGenerator.generate(options)
|
173
162
|
end
|
@@ -177,8 +166,7 @@ file types_conf => File.join("lib", "ffi", "version.rb") do |task|
|
|
177
166
|
end
|
178
167
|
|
179
168
|
desc "Create or update type information for platform #{FFI::Platform::NAME}"
|
180
|
-
task :types_conf => types_conf
|
181
|
-
end
|
169
|
+
task :types_conf => types_conf
|
182
170
|
|
183
171
|
Gem::Tasks.new do |t|
|
184
172
|
t.scm.tag.format = '%s'
|
data/ffi.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path("../lib/#{File.basename(__FILE__, '.gemspec')}/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'ffi'
|
5
|
+
s.version = FFI::VERSION
|
6
|
+
s.author = 'Wayne Meissner'
|
7
|
+
s.email = 'wmeissner@gmail.com'
|
8
|
+
s.homepage = 'https://github.com/ffi/ffi/wiki'
|
9
|
+
s.summary = 'Ruby FFI'
|
10
|
+
s.description = 'Ruby FFI library'
|
11
|
+
if s.respond_to?(:metadata)
|
12
|
+
s.metadata['bug_tracker_uri'] = 'https://github.com/ffi/ffi/issues'
|
13
|
+
s.metadata['changelog_uri'] = 'https://github.com/ffi/ffi/blob/master/CHANGELOG.md'
|
14
|
+
s.metadata['documentation_uri'] = 'https://github.com/ffi/ffi/wiki'
|
15
|
+
s.metadata['wiki_uri'] = 'https://github.com/ffi/ffi/wiki'
|
16
|
+
s.metadata['source_code_uri'] = 'https://github.com/ffi/ffi/'
|
17
|
+
s.metadata['mailing_list_uri'] = 'http://groups.google.com/group/ruby-ffi'
|
18
|
+
end
|
19
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f =~ /^(\.|bench|gen|libtest|nbproject|spec)/
|
21
|
+
end
|
22
|
+
|
23
|
+
# Add libffi git files
|
24
|
+
lfs = `git --git-dir ext/ffi_c/libffi/.git ls-files -z`.split("\x0")
|
25
|
+
# Add autoconf generated files of libffi
|
26
|
+
lfs += %w[ configure config.guess config.sub install-sh ltmain.sh missing fficonfig.h.in ]
|
27
|
+
# Add automake generated files of libffi
|
28
|
+
lfs += `git --git-dir ext/ffi_c/libffi/.git ls-files -z *.am */*.am`.gsub(".am\0", ".in\0").split("\x0")
|
29
|
+
s.files += lfs.map do |f|
|
30
|
+
File.join("ext/ffi_c/libffi", f)
|
31
|
+
end
|
32
|
+
|
33
|
+
s.extensions << 'ext/ffi_c/extconf.rb'
|
34
|
+
s.rdoc_options = %w[--exclude=ext/ffi_c/.*\.o$ --exclude=ffi_c\.(bundle|so)$]
|
35
|
+
s.license = 'BSD-3-Clause'
|
36
|
+
s.require_paths << 'ext/ffi_c'
|
37
|
+
s.required_ruby_version = '>= 2.3'
|
38
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
39
|
+
s.add_development_dependency 'rake-compiler', '~> 1.0'
|
40
|
+
s.add_development_dependency 'rake-compiler-dock', '~> 1.0'
|
41
|
+
s.add_development_dependency 'rspec', '~> 2.14.1'
|
42
|
+
s.add_development_dependency 'rubygems-tasks', "~> 0.2.4"
|
43
|
+
end
|
data/lib/ffi.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
|
2
|
+
Object.send(:remove_const, :FFI) if defined?(::FFI)
|
3
|
+
begin
|
4
|
+
require RUBY_VERSION.split('.')[0, 2].join('.') + '/ffi_c'
|
5
|
+
rescue Exception
|
6
|
+
require 'ffi_c'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'ffi/ffi'
|
10
|
+
|
11
|
+
elsif RUBY_ENGINE == 'jruby' && (RUBY_ENGINE_VERSION.split('.').map(&:to_i) <=> [9, 3]) >= 0
|
12
|
+
JRuby::Util.load_ext("org.jruby.ext.ffi.FFIService")
|
13
|
+
require 'ffi/ffi'
|
14
|
+
|
15
|
+
elsif RUBY_ENGINE == 'truffleruby' && (RUBY_ENGINE_VERSION.split('.').map(&:to_i) <=> [20, 1, 0]) >= 0
|
16
|
+
require 'truffleruby/ffi_backend'
|
17
|
+
require 'ffi/ffi'
|
18
|
+
|
19
|
+
else
|
20
|
+
# Remove the ffi gem dir from the load path, then reload the internal ffi implementation
|
21
|
+
$LOAD_PATH.delete(File.dirname(__FILE__))
|
22
|
+
$LOAD_PATH.delete(File.join(File.dirname(__FILE__), 'ffi'))
|
23
|
+
unless $LOADED_FEATURES.nil?
|
24
|
+
$LOADED_FEATURES.delete(__FILE__)
|
25
|
+
$LOADED_FEATURES.delete('ffi.rb')
|
26
|
+
end
|
27
|
+
require 'ffi.rb'
|
28
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2020 Lars Kanis
|
3
|
+
#
|
4
|
+
# This file is part of ruby-ffi.
|
5
|
+
#
|
6
|
+
# All rights reserved.
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions are met:
|
10
|
+
#
|
11
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
12
|
+
# list of conditions and the following disclaimer.
|
13
|
+
# * Redistributions in binary form must reproduce the above copyright notice
|
14
|
+
# this list of conditions and the following disclaimer in the documentation
|
15
|
+
# and/or other materials provided with the distribution.
|
16
|
+
# * Neither the name of the Ruby FFI project nor the names of its contributors
|
17
|
+
# may be used to endorse or promote products derived from this software
|
18
|
+
# without specific prior written permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
24
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
|
30
|
+
|
31
|
+
|
32
|
+
module FFI
|
33
|
+
class AbstractMemory
|
34
|
+
LONG_MAX = FFI::Pointer.new(1).size
|
35
|
+
private_constant :LONG_MAX
|
36
|
+
|
37
|
+
# Return +true+ if +self+ has a size limit.
|
38
|
+
#
|
39
|
+
# @return [Boolean]
|
40
|
+
def size_limit?
|
41
|
+
size != LONG_MAX
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2008-2010 Wayne Meissner
|
3
|
+
# Copyright (C) 2008 Mike Dalessio
|
4
|
+
#
|
5
|
+
# This file is part of ruby-ffi.
|
6
|
+
#
|
7
|
+
# All rights reserved.
|
8
|
+
#
|
9
|
+
# Redistribution and use in source and binary forms, with or without
|
10
|
+
# modification, are permitted provided that the following conditions are met:
|
11
|
+
#
|
12
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
13
|
+
# list of conditions and the following disclaimer.
|
14
|
+
# * Redistributions in binary form must reproduce the above copyright notice
|
15
|
+
# this list of conditions and the following disclaimer in the documentation
|
16
|
+
# and/or other materials provided with the distribution.
|
17
|
+
# * Neither the name of the Ruby FFI project nor the names of its contributors
|
18
|
+
# may be used to endorse or promote products derived from this software
|
19
|
+
# without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
22
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
25
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
29
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
|
32
|
+
module FFI
|
33
|
+
class AutoPointer < Pointer
|
34
|
+
extend DataConverter
|
35
|
+
|
36
|
+
# @overload initialize(pointer, method)
|
37
|
+
# @param pointer [Pointer]
|
38
|
+
# @param method [Method]
|
39
|
+
# @return [self]
|
40
|
+
# The passed Method will be invoked at GC time.
|
41
|
+
# @overload initialize(pointer, proc)
|
42
|
+
# @param pointer [Pointer]
|
43
|
+
# @return [self]
|
44
|
+
# The passed Proc will be invoked at GC time (SEE WARNING BELOW!)
|
45
|
+
# @note WARNING: passing a proc _may_ cause your pointer to never be
|
46
|
+
# GC'd, unless you're careful to avoid trapping a reference to the
|
47
|
+
# pointer in the proc. See the test specs for examples.
|
48
|
+
# @overload initialize(pointer) { |p| ... }
|
49
|
+
# @param pointer [Pointer]
|
50
|
+
# @yieldparam [Pointer] p +pointer+ passed to the block
|
51
|
+
# @return [self]
|
52
|
+
# The passed block will be invoked at GC time.
|
53
|
+
# @note
|
54
|
+
# WARNING: passing a block will cause your pointer to never be GC'd.
|
55
|
+
# This is bad.
|
56
|
+
# @overload initialize(pointer)
|
57
|
+
# @param pointer [Pointer]
|
58
|
+
# @return [self]
|
59
|
+
# The pointer's release() class method will be invoked at GC time.
|
60
|
+
#
|
61
|
+
# @note The safest, and therefore preferred, calling
|
62
|
+
# idiom is to pass a Method as the second parameter. Example usage:
|
63
|
+
#
|
64
|
+
# class PointerHelper
|
65
|
+
# def self.release(pointer)
|
66
|
+
# ...
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# p = AutoPointer.new(other_pointer, PointerHelper.method(:release))
|
71
|
+
#
|
72
|
+
# The above code will cause PointerHelper#release to be invoked at GC time.
|
73
|
+
#
|
74
|
+
# @note
|
75
|
+
# The last calling idiom (only one parameter) is generally only
|
76
|
+
# going to be useful if you subclass {AutoPointer}, and override
|
77
|
+
# #release, which by default does nothing.
|
78
|
+
def initialize(ptr, proc=nil, &block)
|
79
|
+
super(ptr.type_size, ptr)
|
80
|
+
raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) \
|
81
|
+
|| ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer)
|
82
|
+
|
83
|
+
@releaser = if proc
|
84
|
+
if not proc.respond_to?(:call)
|
85
|
+
raise RuntimeError.new("proc must be callable")
|
86
|
+
end
|
87
|
+
CallableReleaser.new(ptr, proc)
|
88
|
+
|
89
|
+
else
|
90
|
+
if not self.class.respond_to?(:release)
|
91
|
+
raise RuntimeError.new("no release method defined")
|
92
|
+
end
|
93
|
+
DefaultReleaser.new(ptr, self.class)
|
94
|
+
end
|
95
|
+
|
96
|
+
ObjectSpace.define_finalizer(self, @releaser)
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [nil]
|
101
|
+
# Free the pointer.
|
102
|
+
def free
|
103
|
+
@releaser.free
|
104
|
+
end
|
105
|
+
|
106
|
+
# @param [Boolean] autorelease
|
107
|
+
# @return [Boolean] +autorelease+
|
108
|
+
# Set +autorelease+ property. See {Pointer Autorelease section at Pointer}.
|
109
|
+
def autorelease=(autorelease)
|
110
|
+
@releaser.autorelease=(autorelease)
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [Boolean] +autorelease+
|
114
|
+
# Get +autorelease+ property. See {Pointer Autorelease section at Pointer}.
|
115
|
+
def autorelease?
|
116
|
+
@releaser.autorelease
|
117
|
+
end
|
118
|
+
|
119
|
+
# @abstract Base class for {AutoPointer}'s releasers.
|
120
|
+
#
|
121
|
+
# All subclasses of Releaser should define a +#release(ptr)+ method.
|
122
|
+
# A releaser is an object in charge of release an {AutoPointer}.
|
123
|
+
class Releaser
|
124
|
+
attr_accessor :autorelease
|
125
|
+
|
126
|
+
# @param [Pointer] ptr
|
127
|
+
# @param [#call] proc
|
128
|
+
# @return [nil]
|
129
|
+
# A new instance of Releaser.
|
130
|
+
def initialize(ptr, proc)
|
131
|
+
@ptr = ptr
|
132
|
+
@proc = proc
|
133
|
+
@autorelease = true
|
134
|
+
end
|
135
|
+
|
136
|
+
# @return [nil]
|
137
|
+
# Free pointer.
|
138
|
+
def free
|
139
|
+
if @ptr
|
140
|
+
release(@ptr)
|
141
|
+
@autorelease = false
|
142
|
+
@ptr = nil
|
143
|
+
@proc = nil
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# @param args
|
148
|
+
# Release pointer if +autorelease+ is set.
|
149
|
+
def call(*args)
|
150
|
+
release(@ptr) if @autorelease && @ptr
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# DefaultReleaser is a {Releaser} used when an {AutoPointer} is defined
|
155
|
+
# without Proc or Method. In this case, the pointer to release must be of
|
156
|
+
# a class derived from AutoPointer with a {release} class method.
|
157
|
+
class DefaultReleaser < Releaser
|
158
|
+
# @param [Pointer] ptr
|
159
|
+
# @return [nil]
|
160
|
+
# Release +ptr+ using the {release} class method of its class.
|
161
|
+
def release(ptr)
|
162
|
+
@proc.release(ptr)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# CallableReleaser is a {Releaser} used when an {AutoPointer} is defined with a
|
167
|
+
# Proc or a Method.
|
168
|
+
class CallableReleaser < Releaser
|
169
|
+
# Release +ptr+ by using Proc or Method defined at +ptr+
|
170
|
+
# {AutoPointer#initialize initialization}.
|
171
|
+
#
|
172
|
+
# @param [Pointer] ptr
|
173
|
+
# @return [nil]
|
174
|
+
def release(ptr)
|
175
|
+
@proc.call(ptr)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# Return native type of AutoPointer.
|
180
|
+
#
|
181
|
+
# Override {DataConverter#native_type}.
|
182
|
+
# @return [Type::POINTER]
|
183
|
+
# @raise {RuntimeError} if class does not implement a +#release+ method
|
184
|
+
def self.native_type
|
185
|
+
if not self.respond_to?(:release)
|
186
|
+
raise RuntimeError.new("no release method defined for #{self.inspect}")
|
187
|
+
end
|
188
|
+
Type::POINTER
|
189
|
+
end
|
190
|
+
|
191
|
+
# Create a new AutoPointer.
|
192
|
+
#
|
193
|
+
# Override {DataConverter#from_native}.
|
194
|
+
# @overload self.from_native(ptr, ctx)
|
195
|
+
# @param [Pointer] ptr
|
196
|
+
# @param ctx not used. Please set +nil+.
|
197
|
+
# @return [AutoPointer]
|
198
|
+
def self.from_native(val, ctx)
|
199
|
+
self.new(val)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|