ffi 1.17.0.rc1-x86-linux-musl
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +442 -0
- data/COPYING +49 -0
- data/Gemfile +21 -0
- data/LICENSE +24 -0
- data/LICENSE.SPECS +22 -0
- data/README.md +137 -0
- data/Rakefile +206 -0
- data/ffi.gemspec +42 -0
- data/lib/2.5/ffi_c.so +0 -0
- data/lib/2.6/ffi_c.so +0 -0
- data/lib/2.7/ffi_c.so +0 -0
- data/lib/3.0/ffi_c.so +0 -0
- data/lib/3.1/ffi_c.so +0 -0
- data/lib/3.2/ffi_c.so +0 -0
- data/lib/3.3/ffi_c.so +0 -0
- data/lib/ffi/abstract_memory.rb +44 -0
- data/lib/ffi/autopointer.rb +188 -0
- data/lib/ffi/buffer.rb +4 -0
- data/lib/ffi/callback.rb +4 -0
- data/lib/ffi/compat.rb +43 -0
- data/lib/ffi/data_converter.rb +67 -0
- data/lib/ffi/dynamic_library.rb +118 -0
- data/lib/ffi/enum.rb +302 -0
- data/lib/ffi/errno.rb +43 -0
- data/lib/ffi/ffi.rb +50 -0
- data/lib/ffi/function.rb +71 -0
- data/lib/ffi/io.rb +62 -0
- data/lib/ffi/library.rb +576 -0
- data/lib/ffi/library_path.rb +109 -0
- data/lib/ffi/managedstruct.rb +84 -0
- data/lib/ffi/memorypointer.rb +1 -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 +181 -0
- data/lib/ffi/platform/aarch64-linux/types.conf +175 -0
- 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 +132 -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/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/loongarch64-linux/types.conf +141 -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/powerpc64le-linux/types.conf +100 -0
- data/lib/ffi/platform/riscv64-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/sparcv9-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/sw_64-linux/types.conf +141 -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/platform.rb +187 -0
- data/lib/ffi/pointer.rb +167 -0
- data/lib/ffi/struct.rb +317 -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 +232 -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 +195 -0
- data/lib/ffi/tools/types_generator.rb +137 -0
- data/lib/ffi/types.rb +222 -0
- data/lib/ffi/union.rb +43 -0
- data/lib/ffi/variadic.rb +80 -0
- data/lib/ffi/version.rb +3 -0
- data/lib/ffi.rb +27 -0
- data/rakelib/ffi_gem_helper.rb +65 -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/hello_ractor.rb +11 -0
- data/samples/inotify.rb +60 -0
- data/samples/pty.rb +75 -0
- data/samples/qsort.rb +20 -0
- data/samples/qsort_ractor.rb +28 -0
- data/sig/ffi/abstract_memory.rbs +164 -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
- metadata +244 -0
data/README.md
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# Ruby-FFI https://github.com/ffi/ffi/wiki
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Ruby-FFI is a gem for programmatically loading dynamically-linked native
|
6
|
+
libraries, binding functions within them, and calling those functions
|
7
|
+
from Ruby code. Moreover, a Ruby-FFI extension works without changes
|
8
|
+
on CRuby (MRI), JRuby, Rubinius and TruffleRuby. [Discover why you should write your next extension
|
9
|
+
using Ruby-FFI](https://github.com/ffi/ffi/wiki/why-use-ffi).
|
10
|
+
|
11
|
+
## Features
|
12
|
+
|
13
|
+
* Intuitive DSL
|
14
|
+
* Supports all C native types
|
15
|
+
* C structs (also nested), enums and global variables
|
16
|
+
* Callbacks from C to Ruby
|
17
|
+
* Automatic garbage collection of native memory
|
18
|
+
* Usable in Ractor: [How-to-use-FFI-in-Ruby-Ractors](https://github.com/ffi/ffi/wiki/Ractors)
|
19
|
+
|
20
|
+
## Synopsis
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'ffi'
|
24
|
+
|
25
|
+
module MyLib
|
26
|
+
extend FFI::Library
|
27
|
+
ffi_lib 'c'
|
28
|
+
attach_function :puts, [ :string ], :int
|
29
|
+
end
|
30
|
+
|
31
|
+
MyLib.puts 'Hello, World using libc!'
|
32
|
+
```
|
33
|
+
|
34
|
+
For less minimalistic and more examples you may look at:
|
35
|
+
|
36
|
+
* the `samples/` folder
|
37
|
+
* the examples on the [wiki](https://github.com/ffi/ffi/wiki)
|
38
|
+
* the projects using FFI listed on the wiki: https://github.com/ffi/ffi/wiki/projects-using-ffi
|
39
|
+
|
40
|
+
## Requirements
|
41
|
+
|
42
|
+
When installing the gem on CRuby (MRI), you will need:
|
43
|
+
* A C compiler (e.g., Xcode on macOS, `gcc` or `clang` on everything else)
|
44
|
+
Optionally (speeds up installation):
|
45
|
+
* The `libffi` library and development headers - this is commonly in the `libffi-dev` or `libffi-devel` packages
|
46
|
+
|
47
|
+
The ffi gem comes with a builtin libffi version, which is used, when the system libffi library is not available or too old.
|
48
|
+
Use of the system libffi can be enforced by:
|
49
|
+
```
|
50
|
+
gem install ffi -- --enable-system-libffi # to install the gem manually
|
51
|
+
bundle config build.ffi --enable-system-libffi # for bundle install
|
52
|
+
```
|
53
|
+
or prevented by `--disable-system-libffi`.
|
54
|
+
|
55
|
+
On Linux systems running with [PaX](https://en.wikipedia.org/wiki/PaX) (Gentoo, Alpine, etc.), FFI may trigger `mprotect` errors. You may need to disable [mprotect](https://en.wikibooks.org/wiki/Grsecurity/Appendix/Grsecurity_and_PaX_Configuration_Options#Restrict_mprotect.28.29) for ruby (`paxctl -m [/path/to/ruby]`) for the time being until a solution is found.
|
56
|
+
|
57
|
+
On FreeBSD systems pkgconf must be installed for the gem to be able to compile using clang. Install either via packages `pkg install pkgconf` or from ports via `devel/pkgconf`.
|
58
|
+
|
59
|
+
On JRuby and TruffleRuby, there are no requirements to install the FFI gem, and `require 'ffi'` works even without installing the gem (i.e., the gem is preinstalled on these implementations).
|
60
|
+
|
61
|
+
## Installation
|
62
|
+
|
63
|
+
From rubygems:
|
64
|
+
|
65
|
+
[sudo] gem install ffi
|
66
|
+
|
67
|
+
From a Gemfile using git or GitHub
|
68
|
+
|
69
|
+
gem 'ffi', github: 'ffi/ffi', submodules: true
|
70
|
+
|
71
|
+
or from the git repository on github:
|
72
|
+
|
73
|
+
git clone git://github.com/ffi/ffi.git
|
74
|
+
cd ffi
|
75
|
+
git submodule update --init --recursive
|
76
|
+
bundle install
|
77
|
+
rake install
|
78
|
+
|
79
|
+
### Install options:
|
80
|
+
|
81
|
+
* `--enable-system-libffi` : Force usage of system libffi
|
82
|
+
* `--disable-system-libffi` : Force usage of builtin libffi
|
83
|
+
* `--enable-libffi-alloc` : Force closure allocation by libffi
|
84
|
+
* `--disable-libffi-alloc` : Force closure allocation by builtin method
|
85
|
+
|
86
|
+
## License
|
87
|
+
|
88
|
+
The ffi library is covered by the BSD license, also see the LICENSE file.
|
89
|
+
The specs are covered by the same license as [ruby/spec](https://github.com/ruby/spec), the MIT license.
|
90
|
+
|
91
|
+
## Credits
|
92
|
+
|
93
|
+
The following people have submitted code, bug reports, or otherwise contributed to the success of this project:
|
94
|
+
|
95
|
+
* Alban Peignier <alban.peignier@free.fr>
|
96
|
+
* Aman Gupta <aman@tmm1.net>
|
97
|
+
* Andrea Fazzi <andrea.fazzi@alcacoop.it>
|
98
|
+
* Andreas Niederl <rico32@gmx.net>
|
99
|
+
* Andrew Cholakian <andrew@andrewvc.com>
|
100
|
+
* Antonio Terceiro <terceiro@softwarelivre.org>
|
101
|
+
* Benoit Daloze <eregontp@gmail.com>
|
102
|
+
* Brian Candler <B.Candler@pobox.com>
|
103
|
+
* Brian D. Burns <burns180@gmail.com>
|
104
|
+
* Bryan Kearney <bkearney@redhat.com>
|
105
|
+
* Charlie Savage <cfis@zerista.com>
|
106
|
+
* Chikanaga Tomoyuki <nagachika00@gmail.com>
|
107
|
+
* Hongli Lai <hongli@phusion.nl>
|
108
|
+
* Ian MacLeod <ian@nevir.net>
|
109
|
+
* Jake Douglas <jake@shiftedlabs.com>
|
110
|
+
* Jean-Dominique Morani <jdmorani@mac.com>
|
111
|
+
* Jeremy Hinegardner <jeremy@hinegardner.org>
|
112
|
+
* Jesús García Sáez <blaxter@gmail.com>
|
113
|
+
* Joe Khoobyar <joe@ankhcraft.com>
|
114
|
+
* Jurij Smakov <jurij@wooyd.org>
|
115
|
+
* KISHIMOTO, Makoto <ksmakoto@dd.iij4u.or.jp>
|
116
|
+
* Kim Burgestrand <kim@burgestrand.se>
|
117
|
+
* Lars Kanis <lars@greiz-reinsdorf.de>
|
118
|
+
* Luc Heinrich <luc@honk-honk.com>
|
119
|
+
* Luis Lavena <luislavena@gmail.com>
|
120
|
+
* Matijs van Zuijlen <matijs@matijs.net>
|
121
|
+
* Matthew King <automatthew@gmail.com>
|
122
|
+
* Mike Dalessio <mike.dalessio@gmail.com>
|
123
|
+
* NARUSE, Yui <naruse@airemix.jp>
|
124
|
+
* Park Heesob <phasis@gmail.com>
|
125
|
+
* Shin Yee <shinyee@speedgocomputing.com>
|
126
|
+
* Stephen Bannasch <stephen.bannasch@gmail.com>
|
127
|
+
* Suraj N. Kurapati <sunaku@gmail.com>
|
128
|
+
* Sylvain Daubert <sylvain.daubert@laposte.net>
|
129
|
+
* Victor Costan
|
130
|
+
* beoran@gmail.com
|
131
|
+
* ctide <christide@christide.com>
|
132
|
+
* emboss <Martin.Bosslet@googlemail.com>
|
133
|
+
* hobophobe <unusualtears@gmail.com>
|
134
|
+
* meh <meh@paranoici.org>
|
135
|
+
* postmodern <postmodern.mod3@gmail.com>
|
136
|
+
* wycats@gmail.com <wycats@gmail.com>
|
137
|
+
* Wayne Meissner <wmeissner@gmail.com>
|
data/Rakefile
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'date'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'yaml'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'rubygems/package_task'
|
7
|
+
require 'rake/extensiontask'
|
8
|
+
require_relative "lib/ffi/version"
|
9
|
+
require_relative "rakelib/ffi_gem_helper"
|
10
|
+
|
11
|
+
BUILD_DIR = "build"
|
12
|
+
BUILD_EXT_DIR = File.join(BUILD_DIR, "#{RbConfig::CONFIG['arch']}", 'ffi_c', RUBY_VERSION)
|
13
|
+
|
14
|
+
gem_spec = Bundler.load_gemspec('ffi.gemspec')
|
15
|
+
|
16
|
+
RSpec::Core::RakeTask.new(:spec) do |config|
|
17
|
+
config.rspec_opts = YAML.load_file 'spec/spec.opts'
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Build all packages"
|
21
|
+
task :package => %w[ gem:java gem:native ]
|
22
|
+
|
23
|
+
CLOBBER.include 'lib/ffi/types.conf'
|
24
|
+
CLOBBER.include 'pkg'
|
25
|
+
CLOBBER.include 'log'
|
26
|
+
|
27
|
+
CLEAN.include 'build'
|
28
|
+
CLEAN.include 'conftest.dSYM'
|
29
|
+
CLEAN.include 'spec/ffi/fixtures/libtest.{dylib,so,dll}'
|
30
|
+
CLEAN.include 'spec/ffi/fixtures/*.o'
|
31
|
+
CLEAN.include 'spec/ffi/embed-test/ext/*.{o,def}'
|
32
|
+
CLEAN.include 'spec/ffi/embed-test/ext/Makefile'
|
33
|
+
CLEAN.include "pkg/ffi-*-*/"
|
34
|
+
CLEAN.include 'lib/{2,3}.*'
|
35
|
+
|
36
|
+
# clean all shipped files, that are not in git
|
37
|
+
CLEAN.include(
|
38
|
+
gem_spec.files -
|
39
|
+
`git --git-dir ext/ffi_c/libffi/.git ls-files -z`.split("\x0").map { |f| File.join("ext/ffi_c/libffi", f) } -
|
40
|
+
`git ls-files -z`.split("\x0")
|
41
|
+
)
|
42
|
+
|
43
|
+
task :distclean => :clobber
|
44
|
+
|
45
|
+
desc "Test the extension"
|
46
|
+
task :test => [ :spec ]
|
47
|
+
|
48
|
+
|
49
|
+
namespace :bench do
|
50
|
+
ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000
|
51
|
+
bench_files = Dir["bench/bench_*.rb"].sort.reject { |f| f == "bench/bench_helper.rb" }
|
52
|
+
bench_files.each do |bench|
|
53
|
+
task File.basename(bench, ".rb")[6..-1] => :compile do
|
54
|
+
sh %{#{Gem.ruby} #{bench} #{ITER}}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
task :all => :compile do
|
58
|
+
bench_files.each do |bench|
|
59
|
+
sh %{#{Gem.ruby} #{bench}}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
task 'spec:run' => :compile
|
65
|
+
task 'spec:specdoc' => :compile
|
66
|
+
|
67
|
+
task :default => :spec
|
68
|
+
|
69
|
+
namespace 'java' do
|
70
|
+
|
71
|
+
java_gem_spec = gem_spec.dup.tap do |s|
|
72
|
+
s.files.reject! { |f| File.fnmatch?("ext/*", f) }
|
73
|
+
s.extensions = []
|
74
|
+
s.platform = 'java'
|
75
|
+
end
|
76
|
+
|
77
|
+
Gem::PackageTask.new(java_gem_spec) do |pkg|
|
78
|
+
pkg.need_zip = true
|
79
|
+
pkg.need_tar = true
|
80
|
+
pkg.package_dir = 'pkg'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
task 'gem:java' => 'java:gem'
|
85
|
+
|
86
|
+
FfiGemHelper.install_tasks
|
87
|
+
# Register binary gems to be pushed to rubygems.org
|
88
|
+
Bundler::GemHelper.instance.cross_platforms = %w[
|
89
|
+
x86-mingw32
|
90
|
+
x64-mingw-ucrt
|
91
|
+
x64-mingw32
|
92
|
+
x86-linux-gnu
|
93
|
+
x86-linux-musl
|
94
|
+
x86_64-linux-gnu
|
95
|
+
x86_64-linux-musl
|
96
|
+
arm-linux-gnu
|
97
|
+
arm-linux-musl
|
98
|
+
aarch64-linux-gnu
|
99
|
+
aarch64-linux-musl
|
100
|
+
x86_64-darwin
|
101
|
+
arm64-darwin
|
102
|
+
]
|
103
|
+
|
104
|
+
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
|
105
|
+
require 'rake/extensiontask'
|
106
|
+
Rake::ExtensionTask.new('ffi_c', gem_spec) do |ext|
|
107
|
+
ext.name = 'ffi_c' # indicate the name of the extension.
|
108
|
+
# ext.lib_dir = BUILD_DIR # put binaries into this folder.
|
109
|
+
ext.tmp_dir = BUILD_DIR # temporary folder used during compilation.
|
110
|
+
ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
|
111
|
+
ext.cross_platform = Bundler::GemHelper.instance.cross_platforms
|
112
|
+
ext.cross_compiling do |spec|
|
113
|
+
spec.files.reject! { |path| File.fnmatch?('ext/*', path) }
|
114
|
+
end
|
115
|
+
# Enable debug info for 'rake compile' but not for 'gem install'
|
116
|
+
ext.config_options << "--enable-debug"
|
117
|
+
|
118
|
+
end
|
119
|
+
else
|
120
|
+
task :compile do
|
121
|
+
STDERR.puts "Nothing to compile on #{RUBY_ENGINE}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
namespace "gem" do
|
127
|
+
task 'prepare' do
|
128
|
+
require 'rake_compiler_dock'
|
129
|
+
sh "bundle package --all"
|
130
|
+
end
|
131
|
+
|
132
|
+
Bundler::GemHelper.instance.cross_platforms.each do |plat|
|
133
|
+
desc "Build all native binary gems in parallel"
|
134
|
+
multitask 'native' => plat
|
135
|
+
|
136
|
+
desc "Build the native gem for #{plat}"
|
137
|
+
task plat => ['prepare', 'build'] do
|
138
|
+
RakeCompilerDock.sh <<-EOT, platform: plat
|
139
|
+
#{ "sudo apt-get update && sudo apt-get install -y libltdl-dev &&" if plat !~ /linux/ }
|
140
|
+
bundle --local &&
|
141
|
+
rake native:#{plat} pkg/#{gem_spec.full_name}-#{plat}.gem MAKE='nice make -j`nproc`' RUBY_CC_VERSION=${RUBY_CC_VERSION/:2.4.0/}
|
142
|
+
EOT
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
directory "ext/ffi_c/libffi"
|
148
|
+
file "ext/ffi_c/libffi/autogen.sh" => "ext/ffi_c/libffi" do
|
149
|
+
warn "Downloading libffi ..."
|
150
|
+
sh "git submodule update --init --recursive"
|
151
|
+
end
|
152
|
+
task :libffi => "ext/ffi_c/libffi/autogen.sh"
|
153
|
+
|
154
|
+
LIBFFI_GIT_FILES = `git --git-dir ext/ffi_c/libffi/.git ls-files -z`.split("\x0")
|
155
|
+
|
156
|
+
# Generate files which are in the gemspec but not in libffi's git repo by running autogen.sh
|
157
|
+
gem_spec.files.select do |f|
|
158
|
+
f =~ /ext\/ffi_c\/libffi\/(.*)/ && !LIBFFI_GIT_FILES.include?($1)
|
159
|
+
end.each do |f|
|
160
|
+
file f => "ext/ffi_c/libffi/autogen.sh" do
|
161
|
+
chdir "ext/ffi_c/libffi" do
|
162
|
+
sh "sh ./autogen.sh"
|
163
|
+
end
|
164
|
+
touch f
|
165
|
+
if gem_spec.files != Gem::Specification.load('./ffi.gemspec').files
|
166
|
+
warn "gemspec files have changed -> Please restart rake!"
|
167
|
+
exit 1
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# Make sure we have all gemspec files before packaging
|
173
|
+
task :build => gem_spec.files
|
174
|
+
task :gem => :build
|
175
|
+
|
176
|
+
|
177
|
+
require_relative "lib/ffi/platform"
|
178
|
+
types_conf = File.expand_path(File.join(FFI::Platform::CONF_DIR, 'types.conf'))
|
179
|
+
logfile = File.join(File.dirname(__FILE__), 'types_log')
|
180
|
+
|
181
|
+
task types_conf do |task|
|
182
|
+
require 'fileutils'
|
183
|
+
require_relative "lib/ffi/tools/types_generator"
|
184
|
+
options = {}
|
185
|
+
FileUtils.mkdir_p(File.dirname(task.name), mode: 0755 )
|
186
|
+
File.open(task.name, File::CREAT|File::TRUNC|File::RDWR, 0644) do |f|
|
187
|
+
f.puts FFI::TypesGenerator.generate(options)
|
188
|
+
end
|
189
|
+
File.open(logfile, 'w') do |log|
|
190
|
+
log.puts(types_conf)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
desc "Create or update type information for platform #{FFI::Platform::NAME}"
|
195
|
+
task :types_conf => types_conf
|
196
|
+
|
197
|
+
begin
|
198
|
+
require 'yard'
|
199
|
+
|
200
|
+
namespace :doc do
|
201
|
+
YARD::Rake::YardocTask.new do |yard|
|
202
|
+
end
|
203
|
+
end
|
204
|
+
rescue LoadError
|
205
|
+
warn "[warn] YARD unavailable"
|
206
|
+
end
|
data/ffi.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
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[ compile 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.5'
|
38
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
39
|
+
s.add_development_dependency 'rake-compiler', '~> 1.1'
|
40
|
+
s.add_development_dependency 'rake-compiler-dock', '~> 1.0'
|
41
|
+
s.add_development_dependency 'rspec', '~> 2.14.1'
|
42
|
+
end
|
data/lib/2.5/ffi_c.so
ADDED
Binary file
|
data/lib/2.6/ffi_c.so
ADDED
Binary file
|
data/lib/2.7/ffi_c.so
ADDED
Binary file
|
data/lib/3.0/ffi_c.so
ADDED
Binary file
|
data/lib/3.1/ffi_c.so
ADDED
Binary file
|
data/lib/3.2/ffi_c.so
ADDED
Binary file
|
data/lib/3.3/ffi_c.so
ADDED
Binary file
|
@@ -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,188 @@
|
|
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
|
+
raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) ||
|
80
|
+
ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer)
|
81
|
+
super(ptr.type_size, ptr)
|
82
|
+
|
83
|
+
@releaser = if proc
|
84
|
+
if not proc.respond_to?(:call)
|
85
|
+
raise RuntimeError.new("proc must be callable")
|
86
|
+
end
|
87
|
+
Releaser.new(ptr, proc)
|
88
|
+
|
89
|
+
else
|
90
|
+
if not self.class.respond_to?(:release, true)
|
91
|
+
raise RuntimeError.new("no release method defined")
|
92
|
+
end
|
93
|
+
Releaser.new(ptr, self.class.method(:release))
|
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
|
+
raise FrozenError.new("can't modify frozen #{self.class}") if frozen?
|
111
|
+
@releaser.autorelease=(autorelease)
|
112
|
+
end
|
113
|
+
|
114
|
+
# @return [Boolean] +autorelease+
|
115
|
+
# Get +autorelease+ property. See {Pointer Autorelease section at Pointer}.
|
116
|
+
def autorelease?
|
117
|
+
@releaser.autorelease
|
118
|
+
end
|
119
|
+
|
120
|
+
# @abstract Base class for {AutoPointer}'s releasers.
|
121
|
+
#
|
122
|
+
# All subclasses of Releaser should define a +#release(ptr)+ method.
|
123
|
+
# A releaser is an object in charge of release an {AutoPointer}.
|
124
|
+
class Releaser
|
125
|
+
attr_accessor :autorelease
|
126
|
+
|
127
|
+
# @param [Pointer] ptr
|
128
|
+
# @param [#call] proc
|
129
|
+
# @return [nil]
|
130
|
+
# A new instance of Releaser.
|
131
|
+
def initialize(ptr, proc)
|
132
|
+
@ptr = ptr
|
133
|
+
@proc = proc
|
134
|
+
@autorelease = true
|
135
|
+
end
|
136
|
+
|
137
|
+
# @return [nil]
|
138
|
+
# Free pointer.
|
139
|
+
def free
|
140
|
+
if @ptr
|
141
|
+
release(@ptr)
|
142
|
+
@autorelease = false
|
143
|
+
@ptr = nil
|
144
|
+
@proc = nil
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# @param args
|
149
|
+
# Release pointer if +autorelease+ is set.
|
150
|
+
def call(*args)
|
151
|
+
release(@ptr) if @autorelease && @ptr
|
152
|
+
end
|
153
|
+
|
154
|
+
# Release +ptr+ by using Proc or Method defined at +ptr+
|
155
|
+
# {AutoPointer#initialize initialization}.
|
156
|
+
#
|
157
|
+
# @param [Pointer] ptr
|
158
|
+
# @return [nil]
|
159
|
+
def release(ptr)
|
160
|
+
@proc.call(ptr)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# Return native type of AutoPointer.
|
165
|
+
#
|
166
|
+
# Override {DataConverter#native_type}.
|
167
|
+
# @return [Type::POINTER]
|
168
|
+
# @raise {RuntimeError} if class does not implement a +#release+ method
|
169
|
+
def self.native_type
|
170
|
+
if not self.respond_to?(:release, true)
|
171
|
+
raise RuntimeError.new("no release method defined for #{self.inspect}")
|
172
|
+
end
|
173
|
+
Type::POINTER
|
174
|
+
end
|
175
|
+
|
176
|
+
# Create a new AutoPointer.
|
177
|
+
#
|
178
|
+
# Override {DataConverter#from_native}.
|
179
|
+
# @overload self.from_native(ptr, ctx)
|
180
|
+
# @param [Pointer] ptr
|
181
|
+
# @param ctx not used. Please set +nil+.
|
182
|
+
# @return [AutoPointer]
|
183
|
+
def self.from_native(val, ctx)
|
184
|
+
self.new(val)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
data/lib/ffi/buffer.rb
ADDED
data/lib/ffi/callback.rb
ADDED
data/lib/ffi/compat.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2023-2023 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
|
+
if defined?(Ractor.make_shareable)
|
34
|
+
# This is for FFI internal use only.
|
35
|
+
def self.make_shareable(obj)
|
36
|
+
Ractor.make_shareable(obj)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
def self.make_shareable(obj)
|
40
|
+
obj.freeze
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|