ffi 1.6.0-x86-mingw32 → 1.7.0-x86-mingw32

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.

data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rubygems/package_task'
3
+ require 'rubygems/tasks'
3
4
  require 'rbconfig'
4
5
 
5
6
  USE_RAKE_COMPILER = (RUBY_PLATFORM =~ /java/) ? false : true
@@ -64,8 +65,6 @@ OS = case RbConfig::CONFIG['host_os'].downcase
64
65
  RbConfig::CONFIG['host_os'].downcase
65
66
  end
66
67
 
67
- CC = ENV['CC'] || RbConfig::CONFIG['CC'] || "gcc"
68
-
69
68
  GMAKE = system('which gmake >/dev/null') && 'gmake' || 'make'
70
69
 
71
70
  LIBTEST = "build/libtest.#{LIBEXT}"
@@ -76,12 +75,6 @@ def gem_spec
76
75
  @gem_spec ||= Gem::Specification.load('ffi.gemspec')
77
76
  end
78
77
 
79
- Gem::PackageTask.new(gem_spec) do |pkg|
80
- pkg.need_zip = true
81
- pkg.need_tar = true
82
- pkg.package_dir = 'pkg'
83
- end
84
-
85
78
  TEST_DEPS = [ LIBTEST ]
86
79
  if RUBY_PLATFORM == "java"
87
80
  desc "Run all specs"
@@ -109,25 +102,15 @@ end
109
102
  desc "Build all packages"
110
103
  task :package => 'gem:package'
111
104
 
112
- desc "Install the gem locally"
113
- task :install => 'gem:install'
114
105
 
115
- namespace :gem do
116
- task :install => :gem do
117
- ruby %{ -S gem install pkg/ffi-#{gem_spec.version}.gem }
118
- end
119
- end
120
-
121
- desc "Clean all built files"
122
- task :distclean => :clobber do
123
- FileUtils.rm_rf('build')
124
- FileUtils.rm_rf(Dir["lib/**/ffi_c.#{RbConfig::CONFIG['DLEXT']}"])
125
- FileUtils.rm_rf(Dir["lib/**/ffi_c.so"])
126
- FileUtils.rm_rf('lib/ffi/types.conf')
127
- FileUtils.rm_rf('conftest.dSYM')
128
- FileUtils.rm_rf('pkg')
129
- end
106
+ CLOBBER.include 'build'
107
+ CLOBBER.include FileList['lib/**/ffi_c.so']
108
+ CLOBBER.include FileList["lib/**/ffi_c.#{RbConfig::CONFIG['DLEXT']}"]
109
+ CLOBBER.include 'lib/ffi/types.conf'
110
+ CLOBBER.include 'conftest.dSYM'
111
+ CLOBBER.include 'pkg'
130
112
 
113
+ task :distclean => :clobber
131
114
 
132
115
  desc "Build the native test lib"
133
116
  file "build/libtest.#{LIBEXT}" => FileList['libtest/**/*.[ch]'] do
@@ -200,18 +183,30 @@ if USE_RAKE_COMPILER
200
183
  # ext.lib_dir = BUILD_DIR # put binaries into this folder.
201
184
  ext.tmp_dir = BUILD_DIR # temporary folder used during compilation.
202
185
  ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
203
- ext.cross_platform = 'i386-mingw32' # forces the Windows platform instead of the default one
186
+ ext.cross_platform = %w[i386-mingw32 x64-mingw32] # forces the Windows platform instead of the default one
204
187
  end
205
188
 
206
- task 'copy:ffi_c:i386-mingw32:1.9.3' do |t|
207
- sh "i686-w64-mingw32-strip -S lib/1.9/ffi_c.so"
208
- end
209
-
210
- task 'copy:ffi_c:i386-mingw32:2.0.0' do |t|
211
- sh "i686-w64-mingw32-strip -S lib/2.0/ffi_c.so"
189
+ ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
190
+ task "copy:ffi_c:i386-mingw32:#{ruby_version}" do |t|
191
+ %w[lib #{BUILD_DIR}/i386-mingw32/stage/lib].each do |dir|
192
+ if File.exists?("#{dir}/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so")
193
+ sh "i686-w64-mingw32-strip -S #{dir}/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
194
+ end
195
+ end
196
+ end
197
+
198
+ task "copy:ffi_c:x64-mingw32:#{ruby_version}" do |t|
199
+ if File.exists?("#{BUILD_DIR}/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so")
200
+ sh "x86_64-w64-mingw32-strip -S #{dir}/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
201
+ end
202
+ end
212
203
  end
213
204
  end
214
205
 
206
+ Gem::Tasks.new do |t|
207
+ t.scm.tag.format = '%s'
208
+ end
209
+
215
210
  begin
216
211
  require 'yard'
217
212
 
@@ -77,7 +77,7 @@ typedef int bool;
77
77
  static bool prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize);
78
78
  static long trampoline_size(void);
79
79
 
80
- #if defined(__x86_64__) && defined(__GNUC__) && !defined(__sun)
80
+ #if defined(__x86_64__) && (defined(__linux__) || defined(__APPLE__))
81
81
  # define CUSTOM_TRAMPOLINE 1
82
82
  #endif
83
83
 
data/ext/ffi_c/Pointer.c CHANGED
@@ -396,6 +396,16 @@ ptr_free(VALUE self)
396
396
  return self;
397
397
  }
398
398
 
399
+ static VALUE
400
+ ptr_type_size(VALUE self)
401
+ {
402
+ Pointer* ptr;
403
+
404
+ Data_Get_Struct(self, Pointer, ptr);
405
+
406
+ return INT2NUM(ptr->memory.typeSize);
407
+ }
408
+
399
409
  /*
400
410
  * call-seq: ptr.autorelease = autorelease
401
411
  * @param [Boolean] autorelease
@@ -481,6 +491,7 @@ rbffi_Pointer_Init(VALUE moduleFFI)
481
491
  rb_define_method(rbffi_PointerClass, "autorelease=", ptr_autorelease, 1);
482
492
  rb_define_method(rbffi_PointerClass, "autorelease?", ptr_autorelease_p, 0);
483
493
  rb_define_method(rbffi_PointerClass, "free", ptr_free, 0);
494
+ rb_define_method(rbffi_PointerClass, "type_size", ptr_type_size, 0);
484
495
 
485
496
  rbffi_NullPointerSingleton = rb_class_new_instance(1, &rbNullAddress, rbffi_PointerClass);
486
497
  /*
File without changes
data/ffi.gemspec CHANGED
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ffi'
3
- s.version = '1.6.0'
3
+ s.version = '1.7.0'
4
4
  s.author = 'Wayne Meissner'
5
5
  s.email = 'wmeissner@gmail.com'
6
6
  s.homepage = 'http://wiki.github.com/ffi/ffi'
7
7
  s.summary = 'Ruby FFI'
8
8
  s.description = 'Ruby FFI library'
9
- s.files = %w(ffi.gemspec History.txt LICENSE COPYING COPYING.LESSER README.md Rakefile) + Dir.glob("{ext,gen,lib,spec,libtest}/**/*").reject { |f| f =~ /lib\/1\.[89]/}
9
+ s.files = %w(ffi.gemspec History.txt LICENSE COPYING COPYING.LESSER README.md Rakefile) + Dir.glob("{ext,gen,lib,spec,libtest}/**/*").reject { |f| f =~ /lib\/[12]\.[089]/}
10
10
  s.extensions << 'ext/ffi_c/extconf.rb'
11
11
  s.has_rdoc = false
12
12
  s.rdoc_options = %w[--exclude=ext/ffi_c/.*\.o$ --exclude=ffi_c\.(bundle|so)$]
@@ -16,4 +16,5 @@ Gem::Specification.new do |s|
16
16
  s.add_development_dependency 'rake'
17
17
  s.add_development_dependency 'rake-compiler', '>=0.6.0'
18
18
  s.add_development_dependency 'rspec'
19
+ s.add_development_dependency 'rubygems-tasks'
19
20
  end
data/lib/1.8/ffi_c.so CHANGED
Binary file
data/lib/1.9/ffi_c.so CHANGED
Binary file
data/lib/2.0/ffi_c.so CHANGED
Binary file
@@ -64,7 +64,7 @@ module FFI
64
64
  # going to be useful if you subclass {AutoPointer}, and override
65
65
  # #release, which by default does nothing.
66
66
  def initialize(ptr, proc=nil, &block)
67
- super(ptr)
67
+ super(ptr.type_size, ptr)
68
68
  raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) \
69
69
  || ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer)
70
70
 
data/lib/ffi/ffi.iml ADDED
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="jdk" jdkName="RVM: jruby-1.6.8" jdkType="JRUBY_SDK" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.0.0, RVM: jruby-1.6.8) [gem]" level="application" />
9
+ </component>
10
+ </module>
11
+
@@ -99,6 +99,36 @@ describe "Pointer" do
99
99
  end
100
100
  end
101
101
 
102
+ it "Pointer.size returns sizeof pointer on platform" do
103
+ FFI::Pointer.size.should == (FFI::Platform::ADDRESS_SIZE / 8)
104
+ end
105
+
106
+ describe "#slice" do
107
+ before(:each) do
108
+ @mptr = FFI::MemoryPointer.new(:char, 12)
109
+ @mptr.put_uint(0, 0x12345678)
110
+ @mptr.put_uint(4, 0xdeadbeef)
111
+ end
112
+
113
+ it "contents of sliced pointer matches original pointer at offset" do
114
+ @mptr.slice(4, 4).get_uint(0).should == 0xdeadbeef
115
+ end
116
+
117
+ it "modifying sliced pointer is reflected in original pointer" do
118
+ @mptr.slice(4, 4).put_uint(0, 0xfee1dead)
119
+ @mptr.get_uint(4).should == 0xfee1dead
120
+ end
121
+
122
+ it "access beyond bounds should raise IndexError" do
123
+ lambda { @mptr.slice(4, 4).get_int(4) }.should raise_error(IndexError)
124
+ end
125
+ end
126
+
127
+ describe "#type_size" do
128
+ it "should be same as FFI.type_size(type)" do
129
+ FFI::MemoryPointer.new(:int, 1).type_size.should == FFI.type_size(:int)
130
+ end
131
+ end
102
132
  end
103
133
 
104
134
  describe "AutoPointer" do
@@ -212,5 +242,24 @@ describe "AutoPointer" do
212
242
  end
213
243
  end
214
244
 
245
+ describe "#type_size" do
246
+ ptr_class = Class.new(FFI::AutoPointer) do
247
+ def self.release(ptr); end
248
+ end
249
+
250
+ it "type_size of AutoPointer should match wrapped Pointer" do
251
+ aptr = ptr_class.new(FFI::Pointer.new(:int, 0xdeadbeef))
252
+ aptr.type_size.should == FFI.type_size(:int)
253
+ end
254
+
255
+ it "[] offset should match wrapped Pointer" do
256
+ mptr = FFI::MemoryPointer.new(:int, 1024)
257
+ aptr = ptr_class.new(FFI::Pointer.new(:int, mptr))
258
+ aptr[0].write_uint(0xfee1dead)
259
+ aptr[1].write_uint(0xcafebabe)
260
+ mptr[0].read_uint.should == 0xfee1dead
261
+ mptr[1].read_uint.should == 0xcafebabe
262
+ end
263
+ end
215
264
  end
216
265
 
@@ -2,8 +2,8 @@
2
2
  <module type="RUBY_MODULE" version="4">
3
3
  <component name="NewModuleRootManager" inherit-compiler-output="true">
4
4
  <exclude-output />
5
- <content url="file://$MODULE_DIR$">
6
- <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
5
+ <content url="file://$MODULE_DIR$/..">
6
+ <sourceFolder url="file://$MODULE_DIR$/.." isTestSource="true" />
7
7
  </content>
8
8
  <orderEntry type="inheritedJdk" />
9
9
  <orderEntry type="sourceFolder" forTests="false" />
@@ -0,0 +1,43 @@
1
+ #
2
+ # This file is part of ruby-ffi.
3
+ # For licensing, see LICENSE.SPECS
4
+ #
5
+
6
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
+
8
+ describe FFI::Struct, ' by_ref' do
9
+ before :all do
10
+ @struct_class = struct_class = Class.new(FFI::Struct) do
11
+ layout :a, :pointer
12
+ end
13
+
14
+ @api = Module.new do
15
+ extend FFI::Library
16
+ ffi_lib TestLibrary::PATH
17
+ fn = FFI::Type::POINTER.size == FFI::Type::LONG.size ? :ret_ulong : ret_uint64_t
18
+ attach_function :struct_test, fn, [ struct_class.by_ref ], :pointer
19
+ end
20
+ end
21
+
22
+ it "should accept instances of exact struct class" do
23
+ s = @struct_class.new
24
+ @api.struct_test(s).should == s.pointer
25
+ end
26
+
27
+ it "should accept nil" do
28
+ @api.struct_test(nil).should == nil
29
+ end
30
+
31
+ it "should reject other types" do
32
+ lambda { @api.struct_test('test').should == nil }.should raise_error(TypeError)
33
+ end
34
+
35
+ it "should reject instances of other struct classes" do
36
+ other_class = Class.new(FFI::Struct) do
37
+ layout :a, :pointer
38
+ end
39
+
40
+ lambda { @api.struct_test(other_class.new) }.should raise_error(TypeError)
41
+ end
42
+ end
43
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 1.6.0
10
+ version: 1.7.0
11
11
  platform: x86-mingw32
12
12
  authors:
13
13
  - Wayne Meissner
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-03-25 00:00:00 Z
18
+ date: 2013-04-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  prerelease: false
@@ -61,6 +61,20 @@ dependencies:
61
61
  type: :development
62
62
  name: rspec
63
63
  version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :development
76
+ name: rubygems-tasks
77
+ version_requirements: *id004
64
78
  description: Ruby FFI library
65
79
  email: wmeissner@gmail.com
66
80
  executables: []
@@ -87,12 +101,12 @@ files:
87
101
  - ext/ffi_c/ClosurePool.c
88
102
  - ext/ffi_c/ClosurePool.h
89
103
  - ext/ffi_c/compat.h
104
+ - ext/ffi_c/cruby-ext.iml
90
105
  - ext/ffi_c/DataConverter.c
91
106
  - ext/ffi_c/DynamicLibrary.c
92
107
  - ext/ffi_c/DynamicLibrary.h
93
108
  - ext/ffi_c/extconf.rb
94
109
  - ext/ffi_c/ffi.c
95
- - ext/ffi_c/Ffi_c.iml
96
110
  - ext/ffi_c/Function.c
97
111
  - ext/ffi_c/Function.h
98
112
  - ext/ffi_c/FunctionInfo.c
@@ -411,6 +425,7 @@ files:
411
425
  - lib/ffi/callback.rb
412
426
  - lib/ffi/enum.rb
413
427
  - lib/ffi/errno.rb
428
+ - lib/ffi/ffi.iml
414
429
  - lib/ffi/ffi.rb
415
430
  - lib/ffi/io.rb
416
431
  - lib/ffi/library.rb
@@ -466,7 +481,6 @@ files:
466
481
  - spec/ffi/dup_spec.rb
467
482
  - spec/ffi/enum_spec.rb
468
483
  - spec/ffi/errno_spec.rb
469
- - spec/ffi/Ffi.iml
470
484
  - spec/ffi/ffi_spec.rb
471
485
  - spec/ffi/function_spec.rb
472
486
  - spec/ffi/library_spec.rb
@@ -478,9 +492,11 @@ files:
478
492
  - spec/ffi/rbx/memory_pointer_spec.rb
479
493
  - spec/ffi/rbx/spec_helper.rb
480
494
  - spec/ffi/rbx/struct_spec.rb
495
+ - spec/ffi/spec.iml
481
496
  - spec/ffi/spec_helper.rb
482
497
  - spec/ffi/string_spec.rb
483
498
  - spec/ffi/strptr_spec.rb
499
+ - spec/ffi/struct_by_ref_spec.rb
484
500
  - spec/ffi/struct_callback_spec.rb
485
501
  - spec/ffi/struct_initialize_spec.rb
486
502
  - spec/ffi/struct_packed_spec.rb