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.

Files changed (151) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +3 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +22 -0
  5. data/.gitmodules +3 -0
  6. data/.travis.yml +52 -0
  7. data/.yardopts +5 -0
  8. data/Gemfile +15 -0
  9. data/{spec/ffi/LICENSE.SPECS → LICENSE.SPECS} +1 -1
  10. data/README.md +1 -1
  11. data/Rakefile +28 -3
  12. data/appveyor.yml +22 -0
  13. data/ext/ffi_c/Call.c +1 -22
  14. data/ext/ffi_c/Call.h +0 -9
  15. data/ext/ffi_c/Closure.c +54 -0
  16. data/ext/ffi_c/{ClosurePool.h → Closure.h} +13 -23
  17. data/ext/ffi_c/Function.c +16 -25
  18. data/ext/ffi_c/Function.h +1 -2
  19. data/ext/ffi_c/FunctionInfo.c +0 -4
  20. data/ext/ffi_c/MethodHandle.c +33 -268
  21. data/ext/ffi_c/extconf.rb +3 -3
  22. data/ext/ffi_c/ffi.c +2 -2
  23. data/ext/ffi_c/libffi.bsd.mk +3 -3
  24. data/ext/ffi_c/libffi.darwin.mk +1 -1
  25. data/ext/ffi_c/libffi.gnu.mk +1 -1
  26. data/ext/ffi_c/libffi.mk +2 -2
  27. data/ext/ffi_c/libffi.vc.mk +1 -1
  28. data/ext/ffi_c/libffi.vc64.mk +1 -1
  29. data/ext/ffi_c/libffi/.appveyor.yml +48 -0
  30. data/ext/ffi_c/libffi/.gitignore +36 -0
  31. data/ext/ffi_c/libffi/.travis.yml +30 -0
  32. data/ext/ffi_c/libffi/.travis/install.sh +14 -0
  33. data/ext/ffi_c/libffi/Makefile.am +5 -3
  34. data/ext/ffi_c/libffi/acinclude.m4 +6 -0
  35. data/ext/ffi_c/libffi/autogen.sh +1 -1
  36. data/ext/ffi_c/libffi/config.guess +1466 -0
  37. data/ext/ffi_c/libffi/config.sub +1836 -0
  38. data/ext/ffi_c/libffi/configure.ac +2 -2
  39. data/ext/ffi_c/libffi/configure.host +15 -3
  40. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +11 -15
  41. data/ext/ffi_c/libffi/include/ffi.h.in +6 -1
  42. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +465 -59
  43. data/ext/ffi_c/libffi/src/aarch64/ffi.c +33 -10
  44. data/ext/ffi_c/libffi/src/aarch64/sysv.S +2 -2
  45. data/ext/ffi_c/libffi/src/arm/ffi.c +12 -1
  46. data/ext/ffi_c/libffi/src/arm/sysv.S +1 -1
  47. data/ext/ffi_c/libffi/src/closures.c +143 -97
  48. data/ext/ffi_c/libffi/src/ia64/unix.S +2 -0
  49. data/ext/ffi_c/libffi/src/mips/ffi.c +8 -0
  50. data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
  51. data/ext/ffi_c/libffi/src/mips/n32.S +2 -0
  52. data/ext/ffi_c/libffi/src/powerpc/aix.S +239 -1
  53. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +250 -3
  54. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +86 -5
  55. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +3 -0
  56. data/ext/ffi_c/libffi/src/x86/ffi.c +3 -1
  57. data/ext/ffi_c/libffi/src/x86/ffi64.c +26 -5
  58. data/ext/ffi_c/libffi/src/x86/sysv.S +2 -2
  59. data/ext/ffi_c/libffi/src/x86/unix64.S +1 -1
  60. data/ext/ffi_c/libffi/src/x86/win64.S +1 -1
  61. data/ext/ffi_c/libffi/testsuite/Makefile.am +2 -1
  62. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +2 -1
  63. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3float.c +95 -0
  64. data/ffi.gemspec +14 -1
  65. data/lib/ffi/library.rb +1 -1
  66. data/lib/ffi/version.rb +1 -1
  67. data/samples/getlogin.rb +8 -0
  68. data/samples/getpid.rb +8 -0
  69. data/samples/gettimeofday.rb +18 -0
  70. data/samples/hello.rb +7 -0
  71. data/samples/inotify.rb +60 -0
  72. data/samples/pty.rb +76 -0
  73. data/samples/qsort.rb +21 -0
  74. data/samples/sample_helper.rb +6 -0
  75. metadata +59 -81
  76. metadata.gz.sig +0 -0
  77. data/ext/ffi_c/ClosurePool.c +0 -283
  78. data/gen/Rakefile +0 -30
  79. data/libtest/Benchmark.c +0 -52
  80. data/libtest/BoolTest.c +0 -34
  81. data/libtest/BufferTest.c +0 -31
  82. data/libtest/ClosureTest.c +0 -205
  83. data/libtest/EnumTest.c +0 -51
  84. data/libtest/FunctionTest.c +0 -70
  85. data/libtest/GNUmakefile +0 -149
  86. data/libtest/GlobalVariable.c +0 -62
  87. data/libtest/LastErrorTest.c +0 -21
  88. data/libtest/NumberTest.c +0 -132
  89. data/libtest/PointerTest.c +0 -63
  90. data/libtest/ReferenceTest.c +0 -23
  91. data/libtest/StringTest.c +0 -34
  92. data/libtest/StructTest.c +0 -243
  93. data/libtest/UnionTest.c +0 -43
  94. data/libtest/VariadicTest.c +0 -99
  95. data/spec/ffi/async_callback_spec.rb +0 -35
  96. data/spec/ffi/bitmask_spec.rb +0 -575
  97. data/spec/ffi/bool_spec.rb +0 -32
  98. data/spec/ffi/buffer_spec.rb +0 -279
  99. data/spec/ffi/callback_spec.rb +0 -773
  100. data/spec/ffi/custom_param_type.rb +0 -37
  101. data/spec/ffi/custom_type_spec.rb +0 -74
  102. data/spec/ffi/dup_spec.rb +0 -52
  103. data/spec/ffi/enum_spec.rb +0 -423
  104. data/spec/ffi/errno_spec.rb +0 -20
  105. data/spec/ffi/ffi_spec.rb +0 -28
  106. data/spec/ffi/fixtures/Benchmark.c +0 -52
  107. data/spec/ffi/fixtures/BitmaskTest.c +0 -51
  108. data/spec/ffi/fixtures/BoolTest.c +0 -34
  109. data/spec/ffi/fixtures/BufferTest.c +0 -31
  110. data/spec/ffi/fixtures/ClosureTest.c +0 -205
  111. data/spec/ffi/fixtures/EnumTest.c +0 -51
  112. data/spec/ffi/fixtures/FunctionTest.c +0 -142
  113. data/spec/ffi/fixtures/GNUmakefile +0 -149
  114. data/spec/ffi/fixtures/GlobalVariable.c +0 -62
  115. data/spec/ffi/fixtures/LastErrorTest.c +0 -21
  116. data/spec/ffi/fixtures/NumberTest.c +0 -132
  117. data/spec/ffi/fixtures/PipeHelper.h +0 -21
  118. data/spec/ffi/fixtures/PipeHelperPosix.c +0 -41
  119. data/spec/ffi/fixtures/PipeHelperWindows.c +0 -72
  120. data/spec/ffi/fixtures/PointerTest.c +0 -63
  121. data/spec/ffi/fixtures/ReferenceTest.c +0 -23
  122. data/spec/ffi/fixtures/StringTest.c +0 -34
  123. data/spec/ffi/fixtures/StructTest.c +0 -243
  124. data/spec/ffi/fixtures/UnionTest.c +0 -43
  125. data/spec/ffi/fixtures/VariadicTest.c +0 -99
  126. data/spec/ffi/fixtures/classes.rb +0 -438
  127. data/spec/ffi/function_spec.rb +0 -97
  128. data/spec/ffi/io_spec.rb +0 -16
  129. data/spec/ffi/library_spec.rb +0 -286
  130. data/spec/ffi/long_double.rb +0 -30
  131. data/spec/ffi/managed_struct_spec.rb +0 -68
  132. data/spec/ffi/memorypointer_spec.rb +0 -78
  133. data/spec/ffi/number_spec.rb +0 -247
  134. data/spec/ffi/platform_spec.rb +0 -114
  135. data/spec/ffi/pointer_spec.rb +0 -285
  136. data/spec/ffi/rbx/attach_function_spec.rb +0 -34
  137. data/spec/ffi/rbx/memory_pointer_spec.rb +0 -198
  138. data/spec/ffi/rbx/spec_helper.rb +0 -6
  139. data/spec/ffi/rbx/struct_spec.rb +0 -18
  140. data/spec/ffi/spec_helper.rb +0 -93
  141. data/spec/ffi/string_spec.rb +0 -118
  142. data/spec/ffi/strptr_spec.rb +0 -50
  143. data/spec/ffi/struct_by_ref_spec.rb +0 -43
  144. data/spec/ffi/struct_callback_spec.rb +0 -69
  145. data/spec/ffi/struct_initialize_spec.rb +0 -35
  146. data/spec/ffi/struct_packed_spec.rb +0 -50
  147. data/spec/ffi/struct_spec.rb +0 -882
  148. data/spec/ffi/typedef_spec.rb +0 -91
  149. data/spec/ffi/union_spec.rb +0 -67
  150. data/spec/ffi/variadic_spec.rb +0 -132
  151. data/spec/spec.opts +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0bd345be101aa3db6f97505141dadfc33a331ef2
4
- data.tar.gz: 25cda6342b821cbbff4ac0906b3dbc3db41e71e0
2
+ SHA256:
3
+ metadata.gz: 7595602437da38c9982383ba79f9b02a655cac808488f45a7091abb1c78e6055
4
+ data.tar.gz: 14b1b4a84c83923fc9105f1eb4ea5f6f30381a61ca2e9c0637700b774d8333a7
5
5
  SHA512:
6
- metadata.gz: a7f8d8dc376a97daa3f3e4a449fcf258fb97979720e047fac070f09d6d79517d2393f8fb34917c0f8b818214f5753e76d6c8924fc2c2f0408394104dad36fbe9
7
- data.tar.gz: d213a690f6d5d0a30c9bdcce80bee546eae435573937107859411e3bfa0d76831b0de07ecfe13212d4e32a06b8416d7c8f11efdbd3aeeace2b072c13040625e6
6
+ metadata.gz: 98391b65bb0112f62c2915e5e85b15f5b0bb706333045d70c2c8a9d371f2adcd58aecfa71f3e2916837b6bf2eb4814d3e7eef04197f3bef97037de30245a6a30
7
+ data.tar.gz: 40e1f63a79a0bbb3aea7ea4b58ca4c4f3c088f5da00e64692bb4e64a1e2db06772465a26e3b7321d56c0698fca1bf943f3b99c67500843d6ed3ec7d114839a58
@@ -0,0 +1,3 @@
1
+ N�A瑧��5��E�8�{|rv��t1��"R����
2
+ �=��A�P} ZmQ�FȠ�8����I�v$�S}j��d\pW��֓�]I�`A��_oca� �I�M?���X�:�_�/� p ���~r�P���=�\ �C/t˜zL���T���}O�/]/��F~m�֕W<h��|g`5��y}���\�Ɨ!�9y�Z\~�L������(���'5s=�I�
3
+ Pp�r�+FA��]�1�9&78�JOB��Zb~���@]|�.�'�����
Binary file
@@ -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
@@ -0,0 +1,3 @@
1
+ [submodule "ext/ffi_c/libffi"]
2
+ path = ext/ffi_c/libffi
3
+ url = https://github.com/libffi/libffi.git
@@ -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"
@@ -0,0 +1,5 @@
1
+ --title "Ruby FFI"
2
+ --charset UTF-8
3
+ --private
4
+ lib/**/*.rb
5
+ ext/**/*.c
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2014 Ruby-FFI contributors
1
+ Copyright (c) 2008-2012 Ruby-FFI contributors
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
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 => 'gem: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'))
@@ -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
@@ -62,28 +62,7 @@
62
62
  #include "Thread.h"
63
63
  #include "LongDouble.h"
64
64
 
65
- #ifdef USE_RAW
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);
@@ -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;
@@ -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-2013, Ruby FFI project contributors
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 RUBYFFI_CLOSUREPOOL_H
30
- #define RUBYFFI_CLOSUREPOOL_H
29
+ #ifndef RUBYFFI_CLOSURE_H
30
+ #define RUBYFFI_CLOSURE_H
31
31
 
32
- typedef struct ClosurePool_ ClosurePool;
33
- typedef struct Closure_ Closure;
32
+ #include <ruby.h>
34
33
 
35
- struct Closure_ {
36
- void* info; /* opaque handle for storing closure-instance specific data */
37
- void* function; /* closure-instance specific function, called by custom trampoline */
38
- void* code; /* The native trampoline code location */
39
- struct ClosurePool_* pool;
40
- Closure* next;
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
- void rbffi_ClosurePool_Init(VALUE module);
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* rbffi_Closure_GetCodeAddress(Closure *);
44
+ void rbffi_Closure_Init(VALUE ffiModule);
55
45
 
56
- #endif /* RUBYFFI_CLOSUREPOOL_H */
46
+ #endif /* RUBYFFI_CLOSURE_H */
57
47
 
@@ -64,7 +64,7 @@
64
64
  #include "Type.h"
65
65
  #include "LastError.h"
66
66
  #include "Call.h"
67
- #include "ClosurePool.h"
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(fn->info->closurePool);
329
+ fn->closure = rbffi_Closure_Alloc();
336
330
  fn->closure->info = fn;
337
- fn->base.memory.address = fn->closure->code;
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
  {