ffi 1.12.0 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) 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/ext/ffi_c/AbstractMemory.c +25 -26
  7. data/ext/ffi_c/Buffer.c +4 -9
  8. data/ext/ffi_c/Call.c +3 -14
  9. data/ext/ffi_c/ClosurePool.c +75 -25
  10. data/ext/ffi_c/ClosurePool.h +3 -1
  11. data/ext/ffi_c/DynamicLibrary.c +1 -6
  12. data/ext/ffi_c/Function.c +15 -35
  13. data/ext/ffi_c/FunctionInfo.c +3 -8
  14. data/ext/ffi_c/LastError.c +2 -6
  15. data/ext/ffi_c/LongDouble.c +5 -3
  16. data/ext/ffi_c/LongDouble.h +0 -4
  17. data/ext/ffi_c/MemoryPointer.c +3 -8
  18. data/ext/ffi_c/MethodHandle.c +21 -31
  19. data/ext/ffi_c/MethodHandle.h +3 -2
  20. data/ext/ffi_c/Platform.c +3 -7
  21. data/ext/ffi_c/Pointer.c +25 -26
  22. data/ext/ffi_c/Struct.c +49 -56
  23. data/ext/ffi_c/Struct.h +12 -6
  24. data/ext/ffi_c/StructByValue.c +2 -7
  25. data/ext/ffi_c/StructLayout.c +22 -19
  26. data/ext/ffi_c/Thread.c +0 -8
  27. data/ext/ffi_c/Thread.h +1 -9
  28. data/ext/ffi_c/Type.c +1 -1
  29. data/ext/ffi_c/Variadic.c +2 -7
  30. data/ext/ffi_c/compat.h +4 -0
  31. data/ext/ffi_c/extconf.rb +33 -24
  32. data/ext/ffi_c/libffi/.travis.yml +4 -0
  33. data/ext/ffi_c/libffi/.travis/bfin-sim.exp +1 -1
  34. data/ext/ffi_c/libffi/.travis/build.sh +4 -0
  35. data/ext/ffi_c/libffi/.travis/m32r-sim.exp +1 -1
  36. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +1 -1
  37. data/ext/ffi_c/libffi/.travis/or1k-sim.exp +1 -1
  38. data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +1 -1
  39. data/ext/ffi_c/libffi/.travis/wine-sim.exp +1 -1
  40. data/ext/ffi_c/libffi/Makefile.am +49 -58
  41. data/ext/ffi_c/libffi/README.md +11 -1
  42. data/ext/ffi_c/libffi/config.guess +552 -331
  43. data/ext/ffi_c/libffi/config.sub +1321 -1306
  44. data/ext/ffi_c/libffi/configure.ac +31 -10
  45. data/ext/ffi_c/libffi/configure.host +32 -20
  46. data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
  47. data/ext/ffi_c/libffi/doc/libffi.texi +997 -0
  48. data/ext/ffi_c/libffi/doc/version.texi +4 -0
  49. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +1 -1
  50. data/ext/ffi_c/libffi/include/ffi.h.in +8 -0
  51. data/ext/ffi_c/libffi/libffi.map.in +8 -12
  52. data/ext/ffi_c/libffi/libtool-version +1 -1
  53. data/ext/ffi_c/libffi/msvcc.sh +11 -11
  54. data/ext/ffi_c/libffi/src/aarch64/ffi.c +51 -35
  55. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +10 -5
  56. data/ext/ffi_c/libffi/src/aarch64/internal.h +1 -0
  57. data/ext/ffi_c/libffi/src/aarch64/sysv.S +14 -3
  58. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +1 -1
  59. data/ext/ffi_c/libffi/src/arm/ffi.c +22 -0
  60. data/ext/ffi_c/libffi/src/arm/sysv.S +4 -4
  61. data/ext/ffi_c/libffi/src/closures.c +33 -10
  62. data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
  63. data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
  64. data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
  65. data/ext/ffi_c/libffi/src/dlmalloc.c +1 -1
  66. data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
  67. data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
  68. data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
  69. data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
  70. data/ext/ffi_c/libffi/src/mips/ffi.c +5 -1
  71. data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
  72. data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
  73. data/ext/ffi_c/libffi/src/pa/ffitarget.h +1 -6
  74. data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
  75. data/ext/ffi_c/libffi/src/pa/linux.S +4 -2
  76. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +13 -1
  77. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +1 -1
  78. data/ext/ffi_c/libffi/src/powerpc/linux64.S +8 -0
  79. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +13 -1
  80. data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
  81. data/ext/ffi_c/libffi/src/prep_cif.c +1 -1
  82. data/ext/ffi_c/libffi/src/x86/ffi.c +15 -6
  83. data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
  84. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
  85. data/ext/ffi_c/libffi/src/x86/ffiw64.c +15 -8
  86. data/ext/ffi_c/libffi/src/x86/sysv.S +15 -6
  87. data/ext/ffi_c/libffi/src/x86/unix64.S +59 -4
  88. data/ext/ffi_c/libffi/src/x86/win64.S +7 -3
  89. data/ext/ffi_c/libffi/src/x86/win64_intel.S +3 -2
  90. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +22 -2
  91. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +4 -4
  92. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2 -2
  93. data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +2 -0
  94. data/ffi.gemspec +2 -2
  95. data/lib/ffi.rb +10 -2
  96. data/lib/ffi/abstract_memory.rb +44 -0
  97. data/lib/ffi/ffi.rb +1 -0
  98. data/lib/ffi/library.rb +6 -2
  99. data/lib/ffi/platform.rb +21 -8
  100. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  101. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  102. data/lib/ffi/platform/arm-linux/types.conf +32 -4
  103. data/lib/ffi/platform/i386-windows/types.conf +26 -79
  104. data/lib/ffi/platform/powerpc-linux/types.conf +32 -2
  105. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  106. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  107. data/lib/ffi/platform/x86_64-darwin/types.conf +4 -0
  108. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +4 -22
  109. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  110. data/lib/ffi/platform/x86_64-linux/types.conf +21 -0
  111. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  112. data/lib/ffi/platform/x86_64-windows/types.conf +10 -78
  113. data/lib/ffi/pointer.rb +40 -19
  114. data/lib/ffi/struct.rb +9 -4
  115. data/lib/ffi/tools/types_generator.rb +2 -0
  116. data/lib/ffi/version.rb +1 -1
  117. data/samples/getlogin.rb +1 -1
  118. data/samples/getpid.rb +1 -1
  119. data/samples/gettimeofday.rb +8 -8
  120. data/samples/hello.rb +2 -1
  121. data/samples/inotify.rb +1 -1
  122. data/samples/pty.rb +1 -2
  123. data/samples/qsort.rb +0 -1
  124. metadata +18 -12
  125. data/.appveyor.yml +0 -27
  126. data/.gitignore +0 -25
  127. data/.gitmodules +0 -4
  128. data/.travis.yml +0 -44
  129. data/.yardopts +0 -5
  130. data/ext/ffi_c/win32/stdbool.h +0 -8
  131. data/ext/ffi_c/win32/stdint.h +0 -201
  132. data/samples/sample_helper.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db7a0bfedbb2f28debcc2cbeb36e5dc12dffb11871a0d7007f5f54c28451be27
4
- data.tar.gz: b0b1eb568b60a18ccad29aee26855ba03ad3926b7b9d5aa4cc0711087f880bc8
3
+ metadata.gz: 2c0a1872f48b6db1c64ae5390e0e76455fa27ae7016e5a0426753e4973b53751
4
+ data.tar.gz: 2e9a65f7e151185182a42848eebbd0709fee683d3513e096c7552a669a5326a6
5
5
  SHA512:
6
- metadata.gz: 4db3e8840ad055fe18a40edc4bd957ab3039836785e7e23b6e996743c0fdde654aa4c660a955ce5b181082cda073fafefc4fa63a9356160ef9dcaf3bf82096f1
7
- data.tar.gz: 3ef93d16905de1ffc06986e0fb39261b2d305b8e3ad08a7fc247d338b3d57bff499314e4b2e77adadaefcc1ddc67c16a6e0576e86e189f3136a6407255ca4da9
6
+ metadata.gz: 9c78c1d0e46f1bcc9e0ff29dafadb660970ff86f54fb5326dc63e81eecee307e9e22e187c07dc2f9982ffff7c3a3c913caaeb2136683f5990466d452b87ec23c
7
+ data.tar.gz: a5c06fa33eb31dd59f26ee10796609bfee821d076107e5f6ac2ab131f39fbb4979d00f84d98e1e556268ee55f310f8bbda1c770d0af5b98d72b314c1fdd9b0a1
@@ -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'
@@ -32,12 +32,9 @@
32
32
  #include <sys/types.h>
33
33
  #ifndef _MSC_VER
34
34
  # include <sys/param.h>
35
- # include <stdint.h>
36
- # include <stdbool.h>
37
- #else
38
- # include "win32/stdbool.h"
39
- # include "win32/stdint.h"
40
35
  #endif
36
+ #include <stdint.h>
37
+ #include <stdbool.h>
41
38
 
42
39
  #include <limits.h>
43
40
  #include <ruby.h>
@@ -135,11 +132,13 @@ static VALUE memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary); \
135
132
  static VALUE \
136
133
  memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \
137
134
  { \
138
- long count = RARRAY_LEN(ary); \
135
+ long count; \
139
136
  long off = NUM2LONG(offset); \
140
137
  AbstractMemory* memory = MEMORY(self); \
141
138
  long i; \
142
- checkWrite(memory); \
139
+ Check_Type(ary, T_ARRAY); \
140
+ count = RARRAY_LEN(ary); \
141
+ if (likely(count > 0)) checkWrite(memory); \
143
142
  checkBounds(memory, off, count * sizeof(type)); \
144
143
  for (i = 0; i < count; i++) { \
145
144
  type tmp = (type) VAL(toNative(RARRAY_PTR(ary)[i]), swap); \
@@ -162,7 +161,7 @@ memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length) \
162
161
  AbstractMemory* memory = MEMORY(self); \
163
162
  VALUE retVal = rb_ary_new2(count); \
164
163
  long i; \
165
- checkRead(memory); \
164
+ if (likely(count > 0)) checkRead(memory); \
166
165
  checkBounds(memory, off, count * sizeof(type)); \
167
166
  for (i = 0; i < count; ++i) { \
168
167
  type tmp; \
@@ -209,13 +208,13 @@ SWAPU16(uint16_t x)
209
208
  ((x >> 40) & 0x000000000000ff00ULL) | \
210
209
  ((x >> 56) & 0x00000000000000ffULL))
211
210
 
212
- static inline int32_t
211
+ static inline int32_t
213
212
  SWAPS32(int32_t x)
214
213
  {
215
214
  return bswap32(x);
216
215
  }
217
216
 
218
- static inline uint32_t
217
+ static inline uint32_t
219
218
  SWAPU32(uint32_t x)
220
219
  {
221
220
  return bswap32(x);
@@ -450,7 +449,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
450
449
  int i;
451
450
 
452
451
  checkBounds(ptr, off, count * sizeof (char*));
453
-
452
+
454
453
  for (i = 0; i < count; ++i) {
455
454
  const char* strptr = *((const char**) (ptr->address + off) + i);
456
455
  rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_str_new2(strptr)));
@@ -477,7 +476,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
477
476
  * @param [Numeric] count number of strings to get. If nil, return all strings
478
477
  * @return [Array<String>]
479
478
  */
480
- static VALUE
479
+ static VALUE
481
480
  memory_read_array_of_string(int argc, VALUE* argv, VALUE self)
482
481
  {
483
482
  VALUE* rargv = ALLOCA_N(VALUE, argc + 1);
@@ -500,7 +499,7 @@ memory_read_array_of_string(int argc, VALUE* argv, VALUE self)
500
499
  * @raise {SecurityError} when writing unsafe string to memory
501
500
  * @raise {IndexError} if +offset+ is too great
502
501
  * @raise {NullPointerError} if memory not initialized
503
- * Put a string in memory.
502
+ * Put a string in memory. Writes a final \0 byte.
504
503
  */
505
504
  static VALUE
506
505
  memory_put_string(VALUE self, VALUE offset, VALUE str)
@@ -535,13 +534,13 @@ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
535
534
  {
536
535
  AbstractMemory* ptr = MEMORY(self);
537
536
  long off, len;
538
-
537
+
539
538
  off = NUM2LONG(offset);
540
539
  len = NUM2LONG(length);
541
540
 
542
541
  checkRead(ptr);
543
542
  checkBounds(ptr, off, len);
544
-
543
+
545
544
  return rb_str_new((char *) ptr->address + off, len);
546
545
  }
547
546
 
@@ -595,7 +594,7 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
595
594
  * equivalent to :
596
595
  * memory.get_bytes(0, length)
597
596
  */
598
- static VALUE
597
+ static VALUE
599
598
  memory_read_bytes(VALUE self, VALUE length)
600
599
  {
601
600
  return memory_get_bytes(self, INT2FIX(0), length);
@@ -610,7 +609,7 @@ memory_read_bytes(VALUE self, VALUE length)
610
609
  * equivalent to :
611
610
  * memory.put_bytes(0, str, index, length)
612
611
  */
613
- static VALUE
612
+ static VALUE
614
613
  memory_write_bytes(int argc, VALUE* argv, VALUE self)
615
614
  {
616
615
  VALUE* wargv = ALLOCA_N(VALUE, argc + 1);
@@ -643,7 +642,7 @@ memory_type_size(VALUE self)
643
642
  * Document-method: []
644
643
  * call-seq: memory[idx]
645
644
  * @param [Numeric] idx index to access in memory
646
- * @return
645
+ * @return
647
646
  * Memory read accessor.
648
647
  */
649
648
  static VALUE
@@ -748,9 +747,9 @@ MemoryOps rbffi_AbstractMemoryOps = {
748
747
  void
749
748
  rbffi_AbstractMemory_Init(VALUE moduleFFI)
750
749
  {
751
- /*
750
+ /*
752
751
  * Document-class: FFI::AbstractMemory
753
- *
752
+ *
754
753
  * {AbstractMemory} is the base class for many memory management classes such as {Buffer}.
755
754
  *
756
755
  * This class has a lot of methods to work with integers :
@@ -778,8 +777,8 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
778
777
  */
779
778
  VALUE classMemory = rb_define_class_under(moduleFFI, "AbstractMemory", rb_cObject);
780
779
  rbffi_AbstractMemoryClass = classMemory;
781
- /*
782
- * Document-variable: FFI::AbstractMemory
780
+ /*
781
+ * Document-variable: FFI::AbstractMemory
783
782
  */
784
783
  rb_global_variable(&rbffi_AbstractMemoryClass);
785
784
  rb_define_alloc_func(classMemory, memory_allocate);
@@ -807,13 +806,13 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
807
806
  rb_define_method(classMemory, "read_array_of_" #type, memory_read_array_of_##type, 1); \
808
807
  rb_define_method(classMemory, "write_array_of_u" #type, memory_write_array_of_u##type, 1); \
809
808
  rb_define_method(classMemory, "read_array_of_u" #type, memory_read_array_of_u##type, 1);
810
-
809
+
811
810
  INT(int8);
812
811
  INT(int16);
813
812
  INT(int32);
814
813
  INT(int64);
815
814
  INT(long);
816
-
815
+
817
816
  #define ALIAS(name, old) \
818
817
  rb_define_alias(classMemory, "put_" #name, "put_" #old); \
819
818
  rb_define_alias(classMemory, "get_" #name, "get_" #old); \
@@ -831,12 +830,12 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
831
830
  rb_define_alias(classMemory, "read_array_of_" #name, "read_array_of_" #old); \
832
831
  rb_define_alias(classMemory, "write_array_of_u" #name, "write_array_of_u" #old); \
833
832
  rb_define_alias(classMemory, "read_array_of_u" #name, "read_array_of_u" #old);
834
-
833
+
835
834
  ALIAS(char, int8);
836
835
  ALIAS(short, int16);
837
836
  ALIAS(int, int32);
838
837
  ALIAS(long_long, int64);
839
-
838
+
840
839
  /*
841
840
  * Document-method: put_float32
842
841
  * call-seq: memory.put_float32offset, value)