ffi 1.9.21 → 1.9.22
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ffi might be problematic. Click here for more details.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +22 -0
- data/.gitmodules +3 -0
- data/.travis.yml +52 -0
- data/.yardopts +5 -0
- data/Gemfile +15 -0
- data/{spec/ffi/LICENSE.SPECS → LICENSE.SPECS} +1 -1
- data/README.md +1 -1
- data/Rakefile +28 -3
- data/appveyor.yml +22 -0
- data/ext/ffi_c/Call.c +1 -22
- data/ext/ffi_c/Call.h +0 -9
- data/ext/ffi_c/Closure.c +54 -0
- data/ext/ffi_c/{ClosurePool.h → Closure.h} +13 -23
- data/ext/ffi_c/Function.c +16 -25
- data/ext/ffi_c/Function.h +1 -2
- data/ext/ffi_c/FunctionInfo.c +0 -4
- data/ext/ffi_c/MethodHandle.c +33 -268
- data/ext/ffi_c/extconf.rb +3 -3
- data/ext/ffi_c/ffi.c +2 -2
- data/ext/ffi_c/libffi.bsd.mk +3 -3
- data/ext/ffi_c/libffi.darwin.mk +1 -1
- data/ext/ffi_c/libffi.gnu.mk +1 -1
- data/ext/ffi_c/libffi.mk +2 -2
- data/ext/ffi_c/libffi.vc.mk +1 -1
- data/ext/ffi_c/libffi.vc64.mk +1 -1
- data/ext/ffi_c/libffi/.appveyor.yml +48 -0
- data/ext/ffi_c/libffi/.gitignore +36 -0
- data/ext/ffi_c/libffi/.travis.yml +30 -0
- data/ext/ffi_c/libffi/.travis/install.sh +14 -0
- data/ext/ffi_c/libffi/Makefile.am +5 -3
- data/ext/ffi_c/libffi/acinclude.m4 +6 -0
- data/ext/ffi_c/libffi/autogen.sh +1 -1
- data/ext/ffi_c/libffi/config.guess +1466 -0
- data/ext/ffi_c/libffi/config.sub +1836 -0
- data/ext/ffi_c/libffi/configure.ac +2 -2
- data/ext/ffi_c/libffi/configure.host +15 -3
- data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +11 -15
- data/ext/ffi_c/libffi/include/ffi.h.in +6 -1
- data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +465 -59
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +33 -10
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +2 -2
- data/ext/ffi_c/libffi/src/arm/ffi.c +12 -1
- data/ext/ffi_c/libffi/src/arm/sysv.S +1 -1
- data/ext/ffi_c/libffi/src/closures.c +143 -97
- data/ext/ffi_c/libffi/src/ia64/unix.S +2 -0
- data/ext/ffi_c/libffi/src/mips/ffi.c +8 -0
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
- data/ext/ffi_c/libffi/src/mips/n32.S +2 -0
- data/ext/ffi_c/libffi/src/powerpc/aix.S +239 -1
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +250 -3
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +86 -5
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +3 -0
- data/ext/ffi_c/libffi/src/x86/ffi.c +3 -1
- data/ext/ffi_c/libffi/src/x86/ffi64.c +26 -5
- data/ext/ffi_c/libffi/src/x86/sysv.S +2 -2
- data/ext/ffi_c/libffi/src/x86/unix64.S +1 -1
- data/ext/ffi_c/libffi/src/x86/win64.S +1 -1
- data/ext/ffi_c/libffi/testsuite/Makefile.am +2 -1
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +2 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3float.c +95 -0
- data/ffi.gemspec +14 -1
- data/lib/ffi/library.rb +1 -1
- data/lib/ffi/version.rb +1 -1
- data/samples/getlogin.rb +8 -0
- data/samples/getpid.rb +8 -0
- data/samples/gettimeofday.rb +18 -0
- data/samples/hello.rb +7 -0
- data/samples/inotify.rb +60 -0
- data/samples/pty.rb +76 -0
- data/samples/qsort.rb +21 -0
- data/samples/sample_helper.rb +6 -0
- metadata +59 -81
- metadata.gz.sig +0 -0
- data/ext/ffi_c/ClosurePool.c +0 -283
- data/gen/Rakefile +0 -30
- data/libtest/Benchmark.c +0 -52
- data/libtest/BoolTest.c +0 -34
- data/libtest/BufferTest.c +0 -31
- data/libtest/ClosureTest.c +0 -205
- data/libtest/EnumTest.c +0 -51
- data/libtest/FunctionTest.c +0 -70
- data/libtest/GNUmakefile +0 -149
- data/libtest/GlobalVariable.c +0 -62
- data/libtest/LastErrorTest.c +0 -21
- data/libtest/NumberTest.c +0 -132
- data/libtest/PointerTest.c +0 -63
- data/libtest/ReferenceTest.c +0 -23
- data/libtest/StringTest.c +0 -34
- data/libtest/StructTest.c +0 -243
- data/libtest/UnionTest.c +0 -43
- data/libtest/VariadicTest.c +0 -99
- data/spec/ffi/async_callback_spec.rb +0 -35
- data/spec/ffi/bitmask_spec.rb +0 -575
- data/spec/ffi/bool_spec.rb +0 -32
- data/spec/ffi/buffer_spec.rb +0 -279
- data/spec/ffi/callback_spec.rb +0 -773
- data/spec/ffi/custom_param_type.rb +0 -37
- data/spec/ffi/custom_type_spec.rb +0 -74
- data/spec/ffi/dup_spec.rb +0 -52
- data/spec/ffi/enum_spec.rb +0 -423
- data/spec/ffi/errno_spec.rb +0 -20
- data/spec/ffi/ffi_spec.rb +0 -28
- data/spec/ffi/fixtures/Benchmark.c +0 -52
- data/spec/ffi/fixtures/BitmaskTest.c +0 -51
- data/spec/ffi/fixtures/BoolTest.c +0 -34
- data/spec/ffi/fixtures/BufferTest.c +0 -31
- data/spec/ffi/fixtures/ClosureTest.c +0 -205
- data/spec/ffi/fixtures/EnumTest.c +0 -51
- data/spec/ffi/fixtures/FunctionTest.c +0 -142
- data/spec/ffi/fixtures/GNUmakefile +0 -149
- data/spec/ffi/fixtures/GlobalVariable.c +0 -62
- data/spec/ffi/fixtures/LastErrorTest.c +0 -21
- data/spec/ffi/fixtures/NumberTest.c +0 -132
- data/spec/ffi/fixtures/PipeHelper.h +0 -21
- data/spec/ffi/fixtures/PipeHelperPosix.c +0 -41
- data/spec/ffi/fixtures/PipeHelperWindows.c +0 -72
- data/spec/ffi/fixtures/PointerTest.c +0 -63
- data/spec/ffi/fixtures/ReferenceTest.c +0 -23
- data/spec/ffi/fixtures/StringTest.c +0 -34
- data/spec/ffi/fixtures/StructTest.c +0 -243
- data/spec/ffi/fixtures/UnionTest.c +0 -43
- data/spec/ffi/fixtures/VariadicTest.c +0 -99
- data/spec/ffi/fixtures/classes.rb +0 -438
- data/spec/ffi/function_spec.rb +0 -97
- data/spec/ffi/io_spec.rb +0 -16
- data/spec/ffi/library_spec.rb +0 -286
- data/spec/ffi/long_double.rb +0 -30
- data/spec/ffi/managed_struct_spec.rb +0 -68
- data/spec/ffi/memorypointer_spec.rb +0 -78
- data/spec/ffi/number_spec.rb +0 -247
- data/spec/ffi/platform_spec.rb +0 -114
- data/spec/ffi/pointer_spec.rb +0 -285
- data/spec/ffi/rbx/attach_function_spec.rb +0 -34
- data/spec/ffi/rbx/memory_pointer_spec.rb +0 -198
- data/spec/ffi/rbx/spec_helper.rb +0 -6
- data/spec/ffi/rbx/struct_spec.rb +0 -18
- data/spec/ffi/spec_helper.rb +0 -93
- data/spec/ffi/string_spec.rb +0 -118
- data/spec/ffi/strptr_spec.rb +0 -50
- data/spec/ffi/struct_by_ref_spec.rb +0 -43
- data/spec/ffi/struct_callback_spec.rb +0 -69
- data/spec/ffi/struct_initialize_spec.rb +0 -35
- data/spec/ffi/struct_packed_spec.rb +0 -50
- data/spec/ffi/struct_spec.rb +0 -882
- data/spec/ffi/typedef_spec.rb +0 -91
- data/spec/ffi/union_spec.rb +0 -67
- data/spec/ffi/variadic_spec.rb +0 -132
- data/spec/spec.opts +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7595602437da38c9982383ba79f9b02a655cac808488f45a7091abb1c78e6055
|
4
|
+
data.tar.gz: 14b1b4a84c83923fc9105f1eb4ea5f6f30381a61ca2e9c0637700b774d8333a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98391b65bb0112f62c2915e5e85b15f5b0bb706333045d70c2c8a9d371f2adcd58aecfa71f3e2916837b6bf2eb4814d3e7eef04197f3bef97037de30245a6a30
|
7
|
+
data.tar.gz: 40e1f63a79a0bbb3aea7ea4b58ca4c4f3c088f5da00e64692bb4e64a1e2db06772465a26e3b7321d56c0698fca1bf943f3b99c67500843d6ed3ec7d114839a58
|
checksums.yaml.gz.sig
ADDED
data.tar.gz.sig
ADDED
Binary file
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
doc/
|
2
|
+
bin/
|
3
|
+
.yardoc
|
4
|
+
*.orig
|
5
|
+
nbproject/private
|
6
|
+
pkg
|
7
|
+
*.orig
|
8
|
+
*.rej
|
9
|
+
*.patch
|
10
|
+
*.diff
|
11
|
+
build
|
12
|
+
*.so
|
13
|
+
*.[oa]
|
14
|
+
core
|
15
|
+
lib/ffi/types.conf
|
16
|
+
lib/ffi_c.bundle
|
17
|
+
lib/ffi_c.so
|
18
|
+
vendor
|
19
|
+
.bundle
|
20
|
+
Gemfile.lock
|
21
|
+
types_log
|
22
|
+
*.gem
|
data/.gitmodules
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
dist: trusty
|
2
|
+
sudo: false
|
3
|
+
group: beta
|
4
|
+
language: ruby
|
5
|
+
before_install:
|
6
|
+
- gem install bundler
|
7
|
+
script:
|
8
|
+
- bundle exec rake compile || bundle exec rake compile
|
9
|
+
- bundle exec rake test
|
10
|
+
os:
|
11
|
+
- linux
|
12
|
+
- osx
|
13
|
+
rvm:
|
14
|
+
- 1.9.3
|
15
|
+
- 2.0.0
|
16
|
+
- 2.1
|
17
|
+
- 2.2.8
|
18
|
+
- 2.3.5
|
19
|
+
- 2.4.3
|
20
|
+
- 2.5.0
|
21
|
+
- ruby-head
|
22
|
+
- rbx
|
23
|
+
- system
|
24
|
+
env:
|
25
|
+
- CC=gcc
|
26
|
+
- CC=clang
|
27
|
+
matrix:
|
28
|
+
allow_failures:
|
29
|
+
- rvm: system
|
30
|
+
- os: osx
|
31
|
+
rvm: 2.0.0
|
32
|
+
- os: osx
|
33
|
+
rvm: ruby-head
|
34
|
+
- rvm: rbx
|
35
|
+
- rvm: rbx-head
|
36
|
+
- rvm: 1.9.3
|
37
|
+
exclude: # ruby 2.4.2 needs build with xcode9 or later on osx
|
38
|
+
- os: osx
|
39
|
+
rvm: 2.4.2
|
40
|
+
include:
|
41
|
+
- os: osx
|
42
|
+
osx_image: xcode9.1
|
43
|
+
rvm: 2.4.2
|
44
|
+
env:
|
45
|
+
- CC=gcc
|
46
|
+
- os: osx
|
47
|
+
osx_image: xcode9.1
|
48
|
+
rvm: 2.4.2
|
49
|
+
env:
|
50
|
+
- CC=clang
|
51
|
+
after_failure:
|
52
|
+
- "find build -name mkmf.log | xargs cat"
|
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem 'rake', '~> 10.1'
|
5
|
+
gem 'rake-compiler', '~> 1.0.3'
|
6
|
+
gem 'rake-compiler-dock', '~> 0.6.2'
|
7
|
+
gem 'rspec', '~> 3.0'
|
8
|
+
gem 'rubygems-tasks', '~> 0.2.4', :require => 'rubygems/tasks'
|
9
|
+
gem "rubysl", "~> 2.0", :platforms => 'rbx'
|
10
|
+
end
|
11
|
+
|
12
|
+
group :doc do
|
13
|
+
gem 'kramdown'
|
14
|
+
gem 'yard', '~> 0.9'
|
15
|
+
end
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# ruby-ffi https://wiki.github.com/ffi/ffi [![Build Status](https://travis-ci.org/ffi/ffi.png?branch=master)](https://travis-ci.org/ffi/ffi)
|
1
|
+
# ruby-ffi https://wiki.github.com/ffi/ffi [![Build Status](https://travis-ci.org/ffi/ffi.png?branch=master)](https://travis-ci.org/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
|
|
data/Rakefile
CHANGED
@@ -100,7 +100,7 @@ else
|
|
100
100
|
end
|
101
101
|
|
102
102
|
desc "Build all packages"
|
103
|
-
task :package =>
|
103
|
+
task :package => %w[ gem:java gem:windows ]
|
104
104
|
|
105
105
|
CLOBBER.include 'lib/ffi/types.conf'
|
106
106
|
CLOBBER.include 'pkg'
|
@@ -184,10 +184,11 @@ if USE_RAKE_COMPILER
|
|
184
184
|
ext.tmp_dir = BUILD_DIR # temporary folder used during compilation.
|
185
185
|
ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
|
186
186
|
ext.cross_platform = %w[i386-mingw32 x64-mingw32] # forces the Windows platform instead of the default one
|
187
|
+
ext.cross_compiling do |spec|
|
188
|
+
spec.files.reject! { |path| File.fnmatch?('ext/*', path) }
|
189
|
+
end
|
187
190
|
end
|
188
191
|
|
189
|
-
ENV['RUBY_CC_VERSION'] ||= '1.9.3:2.0.0:2.1.6:2.2.2:2.3.0'
|
190
|
-
|
191
192
|
# To reduce the gem file size strip mingw32 dlls before packaging
|
192
193
|
ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
|
193
194
|
task "build/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so" do |t|
|
@@ -206,6 +207,30 @@ if USE_RAKE_COMPILER
|
|
206
207
|
end
|
207
208
|
end
|
208
209
|
|
210
|
+
directory "ext/ffi_c/libffi"
|
211
|
+
file "ext/ffi_c/libffi/autogen.sh" => "ext/ffi_c/libffi" do
|
212
|
+
warn "Downloading libffi ..."
|
213
|
+
sh "git submodule update --init --recursive"
|
214
|
+
end
|
215
|
+
|
216
|
+
LIBFFI_GIT_FILES = `git --git-dir ext/ffi_c/libffi/.git ls-files -z`.split("\x0")
|
217
|
+
|
218
|
+
# Generate files in gemspec but not in libffi's git repo by running autogen.sh
|
219
|
+
gem_spec.files.select do |f|
|
220
|
+
f =~ /ext\/ffi_c\/libffi\/(.*)/ && !LIBFFI_GIT_FILES.include?($1)
|
221
|
+
end.each do |f|
|
222
|
+
file f => "ext/ffi_c/libffi/autogen.sh" do
|
223
|
+
chdir "ext/ffi_c/libffi" do
|
224
|
+
sh "sh ./autogen.sh"
|
225
|
+
end
|
226
|
+
touch f
|
227
|
+
if gem_spec.files != Gem::Specification.load('./ffi.gemspec').files
|
228
|
+
warn "gemspec files have changed -> Please restart rake!"
|
229
|
+
exit 1
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
209
234
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
|
210
235
|
require 'ffi/platform'
|
211
236
|
types_conf = File.expand_path(File.join(FFI::Platform::CONF_DIR, 'types.conf'))
|
data/appveyor.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
install:
|
2
|
+
- SET PATH=C:\Ruby%RUBYVER%\bin;%PATH%
|
3
|
+
- SET RAKEOPT=-rdevkit
|
4
|
+
- ps: |
|
5
|
+
if ($env:RUBYVER -like "*head*") {
|
6
|
+
$(new-object net.webclient).DownloadFile("https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-$env:RUBYVER.exe", "$pwd/ruby-setup.exe")
|
7
|
+
cmd /c ruby-setup.exe /verysilent /dir=C:/Ruby$env:RUBYVER
|
8
|
+
}
|
9
|
+
- ridk version
|
10
|
+
- gem --version
|
11
|
+
- gem install bundler --quiet --no-ri --no-rdoc
|
12
|
+
- bundle install
|
13
|
+
build: off
|
14
|
+
build_script:
|
15
|
+
- bundle exec rake compile || bundle exec rake compile
|
16
|
+
test_script:
|
17
|
+
- bundle exec rake test
|
18
|
+
environment:
|
19
|
+
matrix:
|
20
|
+
- RUBYVER: "head-x64"
|
21
|
+
- RUBYVER: 24
|
22
|
+
- RUBYVER: 25-x64
|
data/ext/ffi_c/Call.c
CHANGED
@@ -62,28 +62,7 @@
|
|
62
62
|
#include "Thread.h"
|
63
63
|
#include "LongDouble.h"
|
64
64
|
|
65
|
-
#
|
66
|
-
# ifndef __i386__
|
67
|
-
# error "RAW argument packing only supported on i386"
|
68
|
-
# endif
|
69
|
-
|
70
|
-
#define INT8_ADJ (4)
|
71
|
-
#define INT16_ADJ (4)
|
72
|
-
#define INT32_ADJ (4)
|
73
|
-
#define INT64_ADJ (8)
|
74
|
-
#define LONG_ADJ (sizeof(long))
|
75
|
-
#define FLOAT32_ADJ (4)
|
76
|
-
#define FLOAT64_ADJ (8)
|
77
|
-
#define ADDRESS_ADJ (sizeof(void *))
|
78
|
-
#define LONGDOUBLE_ADJ (ffi_type_longdouble.alignment)
|
79
|
-
|
80
|
-
#endif /* USE_RAW */
|
81
|
-
|
82
|
-
#ifdef USE_RAW
|
83
|
-
# define ADJ(p, a) ((p) = (FFIStorage*) (((char *) p) + a##_ADJ))
|
84
|
-
#else
|
85
|
-
# define ADJ(p, a) (++(p))
|
86
|
-
#endif
|
65
|
+
#define ADJ(p, a) (++(p))
|
87
66
|
|
88
67
|
static void* callback_param(VALUE proc, VALUE cbinfo);
|
89
68
|
static inline void* getPointer(VALUE value, int type);
|
data/ext/ffi_c/Call.h
CHANGED
@@ -39,16 +39,7 @@
|
|
39
39
|
extern "C" {
|
40
40
|
#endif
|
41
41
|
|
42
|
-
#if defined(__i386__) && \
|
43
|
-
(defined(HAVE_RAW_API) || defined(USE_INTERNAL_LIBFFI)) && \
|
44
|
-
!defined(_WIN32) && !defined(__WIN32__)
|
45
|
-
# define USE_RAW
|
46
|
-
#endif
|
47
42
|
|
48
|
-
#if (defined(__i386__) || defined(__x86_64__)) && !(defined(_WIN32) || defined(__WIN32__))
|
49
|
-
# define BYPASS_FFI 1
|
50
|
-
#endif
|
51
|
-
|
52
43
|
typedef union {
|
53
44
|
#ifdef USE_RAW
|
54
45
|
signed int s8, s16, s32;
|
data/ext/ffi_c/Closure.c
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2009, 2010 Wayne Meissner
|
3
|
+
* Copyright (c) 2008-2016, Ruby FFI project contributors
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are met:
|
8
|
+
* * Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
* * Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
* * Neither the name of the Ruby FFI project nor the
|
14
|
+
* names of its contributors may be used to endorse or promote products
|
15
|
+
* derived from this software without specific prior written permission.
|
16
|
+
*
|
17
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
18
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
21
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
*/
|
28
|
+
|
29
|
+
#include <ffi.h>
|
30
|
+
#include "Closure.h"
|
31
|
+
#include "rbffi.h"
|
32
|
+
|
33
|
+
Closure* rbffi_Closure_Alloc(void)
|
34
|
+
{
|
35
|
+
Closure *self;
|
36
|
+
|
37
|
+
self = xmalloc(sizeof(Closure));
|
38
|
+
self->libffi_closure = ffi_closure_alloc(sizeof(ffi_closure), &self->libffi_trampoline);
|
39
|
+
if (!self->libffi_closure) {
|
40
|
+
return NULL;
|
41
|
+
}
|
42
|
+
|
43
|
+
return self;
|
44
|
+
}
|
45
|
+
|
46
|
+
void rbffi_Closure_Free(Closure *self)
|
47
|
+
{
|
48
|
+
ffi_closure_free(self->libffi_closure);
|
49
|
+
free(self);
|
50
|
+
}
|
51
|
+
|
52
|
+
void rbffi_Closure_Init(VALUE moduleFFI)
|
53
|
+
{
|
54
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright (c) 2009, 2010 Wayne Meissner
|
3
|
-
* Copyright (c) 2008-
|
3
|
+
* Copyright (c) 2008-2016, Ruby FFI project contributors
|
4
4
|
* All rights reserved.
|
5
5
|
*
|
6
6
|
* Redistribution and use in source and binary forms, with or without
|
@@ -26,32 +26,22 @@
|
|
26
26
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
27
|
*/
|
28
28
|
|
29
|
-
#ifndef
|
30
|
-
#define
|
29
|
+
#ifndef RUBYFFI_CLOSURE_H
|
30
|
+
#define RUBYFFI_CLOSURE_H
|
31
31
|
|
32
|
-
|
33
|
-
typedef struct Closure_ Closure;
|
32
|
+
#include <ruby.h>
|
34
33
|
|
35
|
-
struct Closure_ {
|
36
|
-
void* info;
|
37
|
-
void* function;
|
38
|
-
void*
|
39
|
-
|
40
|
-
|
41
|
-
};
|
34
|
+
typedef struct Closure_ {
|
35
|
+
void* info; /* Data to pass when calling */
|
36
|
+
void* function; /* Function to call */
|
37
|
+
void* libffi_trampoline; /* Calls .function */
|
38
|
+
void *libffi_closure; /* Allocates .libffi_trampoline */
|
39
|
+
} Closure;
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
ClosurePool* rbffi_ClosurePool_New(int closureSize,
|
46
|
-
bool (*prep)(void* ctx, void *code, Closure* closure, char* errbuf, size_t errbufsize),
|
47
|
-
void* ctx);
|
48
|
-
|
49
|
-
void rbffi_ClosurePool_Free(ClosurePool *);
|
50
|
-
|
51
|
-
Closure* rbffi_Closure_Alloc(ClosurePool *);
|
41
|
+
Closure* rbffi_Closure_Alloc();
|
52
42
|
void rbffi_Closure_Free(Closure *);
|
53
43
|
|
54
|
-
void
|
44
|
+
void rbffi_Closure_Init(VALUE ffiModule);
|
55
45
|
|
56
|
-
#endif /*
|
46
|
+
#endif /* RUBYFFI_CLOSURE_H */
|
57
47
|
|
data/ext/ffi_c/Function.c
CHANGED
@@ -64,7 +64,7 @@
|
|
64
64
|
#include "Type.h"
|
65
65
|
#include "LastError.h"
|
66
66
|
#include "Call.h"
|
67
|
-
#include "
|
67
|
+
#include "Closure.h"
|
68
68
|
#include "MappedType.h"
|
69
69
|
#include "Thread.h"
|
70
70
|
#include "LongDouble.h"
|
@@ -297,6 +297,7 @@ static VALUE
|
|
297
297
|
function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
298
298
|
{
|
299
299
|
Function* fn = NULL;
|
300
|
+
ffi_status ffiStatus;
|
300
301
|
|
301
302
|
Data_Get_Struct(self, Function, fn);
|
302
303
|
|
@@ -311,13 +312,6 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
311
312
|
fn->base.rbParent = rbProc;
|
312
313
|
|
313
314
|
} else if (rb_obj_is_kind_of(rbProc, rb_cProc) || rb_respond_to(rbProc, id_call)) {
|
314
|
-
if (fn->info->closurePool == NULL) {
|
315
|
-
fn->info->closurePool = rbffi_ClosurePool_New(sizeof(ffi_closure), callback_prep, fn->info);
|
316
|
-
if (fn->info->closurePool == NULL) {
|
317
|
-
rb_raise(rb_eNoMemError, "failed to create closure pool");
|
318
|
-
}
|
319
|
-
}
|
320
|
-
|
321
315
|
#if defined(DEFER_ASYNC_CALLBACK)
|
322
316
|
if (async_cb_thread == Qnil) {
|
323
317
|
#if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) && defined(_WIN32)
|
@@ -332,10 +326,22 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
332
326
|
|
333
327
|
#endif
|
334
328
|
|
335
|
-
fn->closure = rbffi_Closure_Alloc(
|
329
|
+
fn->closure = rbffi_Closure_Alloc();
|
336
330
|
fn->closure->info = fn;
|
337
|
-
|
331
|
+
|
332
|
+
ffiStatus = ffi_prep_closure_loc(fn->closure->libffi_closure,
|
333
|
+
&fn->info->ffi_cif, /* callback signature */
|
334
|
+
callback_invoke,
|
335
|
+
fn->closure, /* user_data for callback_invoke */
|
336
|
+
fn->closure->libffi_trampoline);
|
337
|
+
if (ffiStatus != FFI_OK) {
|
338
|
+
rb_raise(rb_eRuntimeError, "ffi_prep_closure_loc in function_init failed. status=%#x",
|
339
|
+
ffiStatus);
|
340
|
+
}
|
341
|
+
|
342
|
+
fn->base.memory.address = fn->closure->libffi_trampoline;
|
338
343
|
fn->base.memory.size = sizeof(*fn->closure);
|
344
|
+
|
339
345
|
fn->autorelease = true;
|
340
346
|
|
341
347
|
} else {
|
@@ -939,21 +945,6 @@ save_callback_exception(void* data, VALUE exc)
|
|
939
945
|
return Qnil;
|
940
946
|
}
|
941
947
|
|
942
|
-
static bool
|
943
|
-
callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize)
|
944
|
-
{
|
945
|
-
FunctionType* fnInfo = (FunctionType *) ctx;
|
946
|
-
ffi_status ffiStatus;
|
947
|
-
|
948
|
-
ffiStatus = ffi_prep_closure(code, &fnInfo->ffi_cif, callback_invoke, closure);
|
949
|
-
if (ffiStatus != FFI_OK) {
|
950
|
-
snprintf(errmsg, errmsgsize, "ffi_prep_closure failed. status=%#x", ffiStatus);
|
951
|
-
return false;
|
952
|
-
}
|
953
|
-
|
954
|
-
return true;
|
955
|
-
}
|
956
|
-
|
957
948
|
void
|
958
949
|
rbffi_Function_Init(VALUE moduleFFI)
|
959
950
|
{
|