ffi 1.12.0-x64-mingw32 → 1.14.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +79 -0
  3. data/Gemfile +4 -2
  4. data/README.md +10 -2
  5. data/Rakefile +24 -43
  6. data/ffi.gemspec +2 -2
  7. data/lib/2.3/ffi_c.so +0 -0
  8. data/lib/2.4/ffi_c.so +0 -0
  9. data/lib/2.5/ffi_c.so +0 -0
  10. data/lib/2.6/ffi_c.so +0 -0
  11. data/lib/2.7/ffi_c.so +0 -0
  12. data/lib/ffi.rb +10 -2
  13. data/lib/ffi/abstract_memory.rb +44 -0
  14. data/lib/ffi/ffi.rb +1 -0
  15. data/lib/ffi/library.rb +6 -2
  16. data/lib/ffi/platform.rb +21 -8
  17. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  18. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  19. data/lib/ffi/platform/arm-linux/types.conf +32 -4
  20. data/lib/ffi/platform/i386-windows/types.conf +26 -79
  21. data/lib/ffi/platform/powerpc-linux/types.conf +32 -2
  22. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  23. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  24. data/lib/ffi/platform/x86_64-darwin/types.conf +4 -0
  25. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +4 -22
  26. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  27. data/lib/ffi/platform/x86_64-linux/types.conf +21 -0
  28. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  29. data/lib/ffi/platform/x86_64-windows/types.conf +10 -78
  30. data/lib/ffi/pointer.rb +40 -19
  31. data/lib/ffi/struct.rb +9 -4
  32. data/lib/ffi/tools/types_generator.rb +2 -0
  33. data/lib/ffi/version.rb +1 -1
  34. data/samples/getlogin.rb +1 -1
  35. data/samples/getpid.rb +1 -1
  36. data/samples/gettimeofday.rb +8 -8
  37. data/samples/hello.rb +2 -1
  38. data/samples/inotify.rb +1 -1
  39. data/samples/pty.rb +1 -2
  40. data/samples/qsort.rb +0 -1
  41. metadata +11 -10
  42. data/.appveyor.yml +0 -27
  43. data/.gitignore +0 -25
  44. data/.gitmodules +0 -4
  45. data/.travis.yml +0 -44
  46. data/.yardopts +0 -5
  47. data/samples/sample_helper.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d2ce245fbdd4d02defcd88efaa887d20aeb8e3564d15ca2c3ba4a81ace27390
4
- data.tar.gz: 9f2f9ccc884e43a150e9ef033d58a3f80b28229596bd96ce8b333aeffa40378d
3
+ metadata.gz: 614f2331a77eb45762c942a282697e247a86a4b2f97582226893e93cb496bee5
4
+ data.tar.gz: 1c39548adec97f5c9b7f19518edcf1581583b3a55b11535edfdc7b67031f2a54
5
5
  SHA512:
6
- metadata.gz: 3b737cd72a35eebe49afff4aa99e40845002ee61050ef42524cbfe8c7806e332559608ca715e2ed6cd4c2dcf2b02de4d3f16db2260f25b4162eb7370801eb85a
7
- data.tar.gz: 0a2cc5ad7a8a967b2bd109e2a75846d1a8158ee365a067f379ec35fd287873cf3d32f82de692b67a87eb4f9057c1e4f904d4f9e3c0a7a91a3952b8195afa0914
6
+ metadata.gz: 62f122b39e7f8b78fb5e01e6acdbb67f9d0ae009145944b22af0cd1c474cdf0d4afe63c409d644418d66d3135269a979e435c78c3e4df4ec641160e72d6685aa
7
+ data.tar.gz: 15f60935d1e76db78ef96d6e06de2dfcb2f3151b005083abe1b6fd180fbad3945544d1d344b582529d07401c14d22b7a15d0ad1a03f73592356fc7e6a4a8684b
@@ -1,3 +1,82 @@
1
+ 1.14.0 / 2020-12-18
2
+ -------------------
3
+
4
+ Added:
5
+ * Add types.conf for x86_64-msys, x86_64-haiku, aarch64-openbsd and aarch64-darwin (alias arm64-darwin)
6
+ * Add method AbstractMemory#size_limit? . #829
7
+ * Add new extconf option --enable-libffi-alloc which is enabled per default on Apple M1 (arm64-darwin).
8
+
9
+ Changed:
10
+ * Do NULL pointer check only when array length > 0 . #305
11
+ * Raise an error on an unknown order argument. #830
12
+ * Change FFI::Pointer#write_string to terminate with a NUL byte like other string methods. #805
13
+ * Update bundled libffi to latest master.
14
+
15
+ Removed:
16
+ * Remove win32/stdint.h and stdbool.h because of copyright issue. #693
17
+
18
+ Fixed:
19
+ * Fix possible UTF-8 load error in loader script interpretation. #792
20
+ * Fix segfault on non-array argument to #write_array_of_*
21
+ * Fix memory leak in MethodHandle . #815
22
+ * Fix possible segfault in combination with fiddle or other libffi using gems . #835
23
+ * Fix possibility to use ffi ruby gem with JRuby-9.3 . #763
24
+
25
+
26
+ 1.13.1 / 2020-06-09
27
+ -------------------
28
+
29
+ Changed:
30
+ * Revert use of `ucrtbase.dll` as default C library on Windows-MINGW.
31
+ `ucrtbase.dll` is still used on MSWIN target. #790
32
+ * Test for `ffi_prep_closure_loc()` to make sure we can use this function.
33
+ This fixes incorrect use of system libffi on MacOS Mojave (10.14). #787
34
+ * Update types.conf on x86_64-dragonflybsd
35
+
36
+
37
+ 1.13.0 / 2020-06-01
38
+ -------------------
39
+
40
+ Added:
41
+ * Add TruffleRuby support. Almost all specs are running on TruffleRuby and succeed. #768
42
+ * 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
43
+ * Add FFI::Platform::LONG_DOUBLE_SIZE
44
+ * Add bounds checks for writing to an inline char[] . #756
45
+ * Add long double as callback return value. #771
46
+ * 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
47
+ * Add new type definitions for powerpc-openbsd and sparcv9-openbsd. #775, #778
48
+
49
+ Changed:
50
+ * Raise required ruby version to >= 2.3.
51
+ * Lots of cleanups and improvements in library, specs and benchmarks.
52
+ * Fix a lot of compiler warnings at the C-extension
53
+ * Fix several install issues on MacOS:
54
+ * Look for libffi in SDK paths, since recent versions of macOS removed it from `/usr/include` . #757
55
+ * Fix error `ld: library not found for -lgcc_s.10.4`
56
+ * Don't built for i386 architecture as it is deprecated
57
+ * Several fixes for MSVC build on Windows. #779
58
+ * Use `ucrtbase.dll` as default C library on Windows instead of old `msvcrt.dll`. #779
59
+ * Update builtin libffi to fix a Powerpc issue with parameters of type long
60
+ * Allow unmodified sourcing of (the ruby code of) this gem in JRuby and TruffleRuby as a default gem. #747
61
+ * Improve check to detect if a module has a #find_type method suitable for FFI. This fixes compatibility with stdlib `mkmf` . #776
62
+
63
+ Removed:
64
+ * Reject callback with `:string` return type at definition, because it didn't work so far and is not save to use. #751, #782
65
+
66
+
67
+ 1.12.2 / 2020-02-01
68
+ -------------------
69
+
70
+ * Fix possible segfault at FFI::Struct#[] and []= after GC.compact . #742
71
+
72
+
73
+ 1.12.1 / 2020-01-14
74
+ -------------------
75
+
76
+ Added:
77
+ * Add binary gem support for ruby-2.7 on Windows
78
+
79
+
1
80
  1.12.0 / 2020-01-14
2
81
  -------------------
3
82
 
data/Gemfile CHANGED
@@ -5,8 +5,10 @@ group :development do
5
5
  gem 'rake-compiler', '~> 1.0.3'
6
6
  gem 'rake-compiler-dock', '~> 1.0'
7
7
  gem 'rspec', '~> 3.0'
8
- gem 'rubygems-tasks', '~> 0.2.4', :require => 'rubygems/tasks'
9
- gem "rubysl", "~> 2.0", :platforms => 'rbx'
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'
10
12
  end
11
13
 
12
14
  group :doc do
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ruby-FFI https://github.com/ffi/ffi/wiki [![Build Status](https://travis-ci.org/ffi/ffi.svg?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)
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
- require File.expand_path("./lib/ffi/version")
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
- TEST_DEPS = []
24
- if RUBY_PLATFORM == "java"
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"
@@ -58,37 +45,29 @@ task :test => [ :spec ]
58
45
 
59
46
  namespace :bench do
60
47
  ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000
61
- bench_libs = "-Ilib" unless RUBY_PLATFORM == "java"
62
- bench_files = Dir["bench/bench_*.rb"].reject { |f| f == "bench/bench_helper.rb" }
48
+ bench_files = Dir["bench/bench_*.rb"].sort.reject { |f| f == "bench/bench_helper.rb" }
63
49
  bench_files.each do |bench|
64
- task File.basename(bench, ".rb")[6..-1] => TEST_DEPS do
65
- sh %{#{Gem.ruby} #{bench_libs} #{bench} #{ITER}}
50
+ task File.basename(bench, ".rb")[6..-1] => :compile do
51
+ sh %{#{Gem.ruby} #{bench} #{ITER}}
66
52
  end
67
53
  end
68
- task :all => TEST_DEPS do
54
+ task :all => :compile do
69
55
  bench_files.each do |bench|
70
- sh %{#{Gem.ruby} #{bench_libs} #{bench}}
56
+ sh %{#{Gem.ruby} #{bench}}
71
57
  end
72
58
  end
73
59
  end
74
60
 
75
- task 'spec:run' => TEST_DEPS
76
- task 'spec:specdoc' => TEST_DEPS
61
+ task 'spec:run' => :compile
62
+ task 'spec:specdoc' => :compile
77
63
 
78
64
  task :default => :spec
79
65
 
80
66
  namespace 'java' do
81
67
 
82
- java_gem_spec = Gem::Specification.new do |s|
83
- s.name = gem_spec.name
84
- s.version = gem_spec.version
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
68
+ java_gem_spec = gem_spec.dup.tap do |s|
69
+ s.files.reject! { |f| File.fnmatch?("ext/*", f) }
70
+ s.extensions = []
92
71
  s.platform = 'java'
93
72
  end
94
73
 
@@ -101,7 +80,7 @@ end
101
80
 
102
81
  task 'gem:java' => 'java:gem'
103
82
 
104
- unless java?
83
+ if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
105
84
  require 'rake/extensiontask'
106
85
  Rake::ExtensionTask.new('ffi_c', gem_spec) do |ext|
107
86
  ext.name = 'ffi_c' # indicate the name of the extension.
@@ -124,13 +103,17 @@ unless java?
124
103
  sh "x86_64-w64-mingw32-strip -S build/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
125
104
  end
126
105
  end
106
+ else
107
+ task :compile do
108
+ STDERR.puts "Nothing to compile on #{RUBY_ENGINE}"
109
+ end
127
110
  end
128
111
 
129
112
  desc "build a windows gem without all the ceremony"
130
113
  task "gem:windows" do
131
114
  require "rake_compiler_dock"
132
115
  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`'"
116
+ 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
117
  end
135
118
 
136
119
  directory "ext/ffi_c/libffi"
@@ -158,16 +141,15 @@ end.each do |f|
158
141
  end
159
142
  end
160
143
 
161
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
162
- require 'ffi/platform'
144
+ require_relative "lib/ffi/platform"
163
145
  types_conf = File.expand_path(File.join(FFI::Platform::CONF_DIR, 'types.conf'))
164
146
  logfile = File.join(File.dirname(__FILE__), 'types_log')
165
147
 
166
- file types_conf => File.join("lib", "ffi", "version.rb") do |task|
148
+ task types_conf do |task|
167
149
  require 'fileutils'
168
- require 'ffi/tools/types_generator'
150
+ require_relative "lib/ffi/tools/types_generator"
169
151
  options = {}
170
- FileUtils.mkdir_p(File.dirname(task.name), { :mode => 0755 })
152
+ FileUtils.mkdir_p(File.dirname(task.name), mode: 0755 )
171
153
  File.open(task.name, File::CREAT|File::TRUNC|File::RDWR, 0644) do |f|
172
154
  f.puts FFI::TypesGenerator.generate(options)
173
155
  end
@@ -177,8 +159,7 @@ file types_conf => File.join("lib", "ffi", "version.rb") do |task|
177
159
  end
178
160
 
179
161
  desc "Create or update type information for platform #{FFI::Platform::NAME}"
180
- task :types_conf => types_conf do
181
- end
162
+ task :types_conf => types_conf
182
163
 
183
164
  Gem::Tasks.new do |t|
184
165
  t.scm.tag.format = '%s'
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.metadata['mailing_list_uri'] = 'http://groups.google.com/group/ruby-ffi'
18
18
  end
19
19
  s.files = `git ls-files -z`.split("\x0").reject do |f|
20
- f =~ /^(bench|gen|libtest|nbproject|spec)/
20
+ f =~ /^(\.|bench|gen|libtest|nbproject|spec)/
21
21
  end
22
22
 
23
23
  # Add libffi git files
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.rdoc_options = %w[--exclude=ext/ffi_c/.*\.o$ --exclude=ffi_c\.(bundle|so)$]
35
35
  s.license = 'BSD-3-Clause'
36
36
  s.require_paths << 'ext/ffi_c'
37
- s.required_ruby_version = '>= 2.0'
37
+ s.required_ruby_version = '>= 2.3'
38
38
  s.add_development_dependency 'rake', '~> 13.0'
39
39
  s.add_development_dependency 'rake-compiler', '~> 1.0'
40
40
  s.add_development_dependency 'rake-compiler-dock', '~> 1.0'
Binary file
Binary file
Binary file
Binary file
Binary file
data/lib/ffi.rb CHANGED
@@ -1,4 +1,4 @@
1
- if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
1
+ if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
2
2
  Object.send(:remove_const, :FFI) if defined?(::FFI)
3
3
  begin
4
4
  require RUBY_VERSION.split('.')[0, 2].join('.') + '/ffi_c'
@@ -8,7 +8,15 @@ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
8
8
 
9
9
  require 'ffi/ffi'
10
10
 
11
- elsif defined?(RUBY_ENGINE)
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
12
20
  # Remove the ffi gem dir from the load path, then reload the internal ffi implementation
13
21
  $LOAD_PATH.delete(File.dirname(__FILE__))
14
22
  $LOAD_PATH.delete(File.join(File.dirname(__FILE__), 'ffi'))
@@ -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
@@ -33,6 +33,7 @@ require 'ffi/data_converter'
33
33
  require 'ffi/types'
34
34
  require 'ffi/library'
35
35
  require 'ffi/errno'
36
+ require 'ffi/abstract_memory'
36
37
  require 'ffi/pointer'
37
38
  require 'ffi/memorypointer'
38
39
  require 'ffi/struct'
@@ -115,7 +115,7 @@ module FFI
115
115
  rescue Exception => ex
116
116
  ldscript = false
117
117
  if ex.message =~ /(([^ \t()])+\.so([^ \t:()])*):([ \t])*(invalid ELF header|file too short|invalid file format)/
118
- if File.read($1) =~ /(?:GROUP|INPUT) *\( *([^ \)]+)/
118
+ if File.binread($1) =~ /(?:GROUP|INPUT) *\( *([^ \)]+)/
119
119
  libname = $1
120
120
  ldscript = true
121
121
  end
@@ -394,7 +394,11 @@ module FFI
394
394
  options = Hash.new
395
395
  options[:convention] = ffi_convention
396
396
  options[:enums] = @ffi_enums if defined?(@ffi_enums)
397
- cb = FFI::CallbackInfo.new(find_type(ret), native_params, options)
397
+ ret_type = find_type(ret)
398
+ if ret_type == Type::STRING
399
+ raise TypeError, ":string is not allowed as return type of callbacks"
400
+ end
401
+ cb = FFI::CallbackInfo.new(ret_type, native_params, options)
398
402
 
399
403
  # Add to the symbol -> type map (unless there was no name)
400
404
  unless name.nil?
@@ -61,9 +61,9 @@ module FFI
61
61
  CPU = RbConfig::CONFIG['host_cpu']
62
62
 
63
63
  ARCH = case CPU.downcase
64
- when /amd64|x86_64/
64
+ when /amd64|x86_64|x64/
65
65
  "x86_64"
66
- when /i?86|x86|i86pc/
66
+ when /i\d86|x86|i86pc/
67
67
  "i386"
68
68
  when /ppc64|powerpc64/
69
69
  "powerpc64"
@@ -71,13 +71,16 @@ module FFI
71
71
  "powerpc"
72
72
  when /sparcv9|sparc64/
73
73
  "sparcv9"
74
- else
75
- case RbConfig::CONFIG['host_cpu']
76
- when /^arm/
77
- "arm"
74
+ when /arm64|aarch64/ # MacOS calls it "arm64", other operating systems "aarch64"
75
+ "aarch64"
76
+ when /^arm/
77
+ if OS == "darwin" # Ruby before 3.0 reports "arm" instead of "arm64" as host_cpu on darwin
78
+ "aarch64"
78
79
  else
79
- RbConfig::CONFIG['host_cpu']
80
+ "arm"
80
81
  end
82
+ else
83
+ RbConfig::CONFIG['host_cpu']
81
84
  end
82
85
 
83
86
  private
@@ -129,7 +132,11 @@ module FFI
129
132
  end
130
133
 
131
134
  LIBC = if IS_WINDOWS
132
- RbConfig::CONFIG['RUBY_SO_NAME'].split('-')[-2] + '.dll'
135
+ if RbConfig::CONFIG['host_os'] =~ /mingw/i
136
+ RbConfig::CONFIG['RUBY_SO_NAME'].split('-')[-2] + '.dll'
137
+ else
138
+ "ucrtbase.dll"
139
+ end
133
140
  elsif IS_GNU
134
141
  GNU_LIBC
135
142
  elsif OS == 'cygwin'
@@ -141,6 +148,12 @@ module FFI
141
148
  "#{LIBPREFIX}c.#{LIBSUFFIX}"
142
149
  end
143
150
 
151
+ LITTLE_ENDIAN = 1234 unless defined?(LITTLE_ENDIAN)
152
+ BIG_ENDIAN = 4321 unless defined?(BIG_ENDIAN)
153
+ unless defined?(BYTE_ORDER)
154
+ BYTE_ORDER = [0x12345678].pack("I") == [0x12345678].pack("N") ? BIG_ENDIAN : LITTLE_ENDIAN
155
+ end
156
+
144
157
  # Test if current OS is a *BSD (include MAC)
145
158
  # @return [Boolean]
146
159
  def self.bsd?