ffi 1.0.2 → 1.0.3

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.

@@ -3,7 +3,7 @@ require 'mkmf'
3
3
  require 'rbconfig'
4
4
  dir_config("ffi_c")
5
5
 
6
- unless Config::CONFIG['host_os'] =~ /mswin32|mingw32/
6
+ unless RbConfig::CONFIG['host_os'] =~ /mswin32|mingw32/
7
7
  if pkg_config("libffi") || find_header("ffi.h", "/usr/local/include")
8
8
 
9
9
  # We need at least ffi_call and ffi_prep_closure
@@ -25,16 +25,16 @@ $defs << "-DRUBY_1_9" if RUBY_VERSION >= "1.9.0"
25
25
 
26
26
  create_header
27
27
 
28
- $CFLAGS << " -mwin32 " if Config::CONFIG['host_os'] =~ /cygwin/
28
+ $CFLAGS << " -mwin32 " if RbConfig::CONFIG['host_os'] =~ /cygwin/
29
29
  #$CFLAGS << " -Werror -Wunused -Wformat -Wimplicit -Wreturn-type "
30
30
 
31
31
  create_makefile("ffi_c")
32
32
  unless libffi_ok
33
33
  File.open("Makefile", "a") do |mf|
34
- mf.puts "LIBFFI_HOST=--host=#{Config::CONFIG['host_alias']}" if Config::CONFIG.has_key?("host_alias")
35
- if Config::CONFIG['host_os'].downcase =~ /darwin/
34
+ mf.puts "LIBFFI_HOST=--host=#{RbConfig::CONFIG['host_alias']}" if RbConfig::CONFIG.has_key?("host_alias")
35
+ if RbConfig::CONFIG['host_os'].downcase =~ /darwin/
36
36
  mf.puts "include ${srcdir}/libffi.darwin.mk"
37
- elsif Config::CONFIG['host_os'].downcase =~ /bsd/
37
+ elsif RbConfig::CONFIG['host_os'].downcase =~ /bsd/
38
38
  mf.puts '.include "${srcdir}/libffi.bsd.mk"'
39
39
  else
40
40
  mf.puts "include ${srcdir}/libffi.mk"
@@ -10,7 +10,7 @@ describe "async callback" do
10
10
  attach_function :testAsyncCallback, [ AsyncIntCallback, :int ], :void, :blocking => true
11
11
  end
12
12
 
13
- unless RUBY_VERSION =~ /1.8/
13
+ # unless RUBY_VERSION =~ /1.8/
14
14
  it ":int (0x7fffffff) argument" do
15
15
  v = 0xdeadbeef
16
16
  called = false
@@ -19,5 +19,5 @@ describe "async callback" do
19
19
  called.should be_true
20
20
  v.should == 0x7fffffff
21
21
  end
22
- end
22
+ # end
23
23
  end
@@ -1,3 +1,19 @@
1
+ #
2
+ # This file is part of ruby-ffi.
3
+ #
4
+ # This code is free software: you can redistribute it and/or modify it under
5
+ # the terms of the GNU Lesser General Public License version 3 only, as
6
+ # published by the Free Software Foundation.
7
+ #
8
+ # This code is distributed in the hope that it will be useful, but WITHOUT
9
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ # version 3 for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+
1
17
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
18
 
3
19
  describe FFI::Function do
@@ -48,14 +64,12 @@ describe FFI::Function do
48
64
  foo.add(10, 10).should == 20
49
65
  end
50
66
  it 'can wrap a blocking function' do
51
- unless RUBY_VERSION =~ /1.8/
52
- fp = FFI::Function.new(:void, [ :int ], @libtest.find_function('testBlocking'), :blocking => true)
53
- time = Time.now
54
- threads = []
55
- threads << Thread.new { fp.call(2) }
56
- threads << Thread.new(time) { (Time.now - time).should < 1 }
57
- threads.each { |t| t.join }
58
- end
67
+ fp = FFI::Function.new(:void, [ :int ], @libtest.find_function('testBlocking'), :blocking => true)
68
+ time = Time.now
69
+ threads = []
70
+ threads << Thread.new { fp.call(2) }
71
+ threads << Thread.new(time) { (Time.now - time).should < 1 }
72
+ threads.each { |t| t.join }
59
73
  end
60
74
  it 'autorelease flag is set to true by default' do
61
75
  fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd'))
@@ -1,8 +1,25 @@
1
+ #
2
+ # This file is part of ruby-ffi.
3
+ #
4
+ # This code is free software: you can redistribute it and/or modify it under
5
+ # the terms of the GNU Lesser General Public License version 3 only, as
6
+ # published by the Free Software Foundation.
7
+ #
8
+ # This code is distributed in the hope that it will be useful, but WITHOUT
9
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ # version 3 for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
15
+ #
1
16
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
17
  require 'delegate'
3
18
  require 'java' if RUBY_PLATFORM =~ /java/
4
19
 
5
- module LibTest
20
+ module PointerTestLib
21
+ extend FFI::Library
22
+ ffi_lib TestLibrary::PATH
6
23
  attach_function :ptr_ret_int32_t, [ :pointer, :int ], :int
7
24
  attach_function :ptr_from_address, [ FFI::Platform::ADDRESS_SIZE == 32 ? :uint : :ulong_long ], :pointer
8
25
  attach_function :ptr_set_pointer, [ :pointer, :int, :pointer ], :void
@@ -23,7 +40,7 @@ describe "Pointer" do
23
40
  magic = 0x12345678
24
41
  memory.put_int32(0, magic)
25
42
  tp = ToPtrTest.new(memory)
26
- LibTest.ptr_ret_int32_t(tp, 0).should == magic
43
+ PointerTestLib.ptr_ret_int32_t(tp, 0).should == magic
27
44
  end
28
45
  class PointerDelegate < DelegateClass(FFI::Pointer)
29
46
  def initialize(ptr)
@@ -38,53 +55,40 @@ describe "Pointer" do
38
55
  magic = 0x12345678
39
56
  memory.put_int32(0, magic)
40
57
  ptr = PointerDelegate.new(memory)
41
- LibTest.ptr_ret_int32_t(ptr, 0).should == magic
58
+ PointerTestLib.ptr_ret_int32_t(ptr, 0).should == magic
42
59
  end
43
60
  it "Fixnum cannot be used as a Pointer argument" do
44
- lambda { LibTest.ptr_ret_int32(0, 0) }.should raise_error
61
+ lambda { PointerTestLib.ptr_ret_int32(0, 0) }.should raise_error
45
62
  end
46
63
  it "Bignum cannot be used as a Pointer argument" do
47
- lambda { LibTest.ptr_ret_int32(0xfee1deadbeefcafebabe, 0) }.should raise_error
64
+ lambda { PointerTestLib.ptr_ret_int32(0xfee1deadbeefcafebabe, 0) }.should raise_error
48
65
  end
49
66
 
50
67
  describe "pointer type methods" do
51
68
 
52
- describe "#read_pointer" do
69
+ it "#read_pointer" do
53
70
  memory = FFI::MemoryPointer.new :pointer
54
- LibTest.ptr_set_pointer(memory, 0, LibTest.ptr_from_address(0xdeadbeef))
71
+ PointerTestLib.ptr_set_pointer(memory, 0, PointerTestLib.ptr_from_address(0xdeadbeef))
55
72
  memory.read_pointer.address.should == 0xdeadbeef
56
73
  end
57
74
 
58
- describe "#write_pointer" do
75
+ it "#write_pointer" do
59
76
  memory = FFI::MemoryPointer.new :pointer
60
- memory.write_pointer(LibTest.ptr_from_address(0xdeadbeef))
61
- LibTest.ptr_ret_pointer(memory, 0).address.should == 0xdeadbeef
77
+ memory.write_pointer(PointerTestLib.ptr_from_address(0xdeadbeef))
78
+ PointerTestLib.ptr_ret_pointer(memory, 0).address.should == 0xdeadbeef
62
79
  end
63
80
 
64
- describe "#read_array_of_pointer" do
81
+ it "#read_array_of_pointer" do
65
82
  values = [0x12345678, 0xfeedf00d, 0xdeadbeef]
66
83
  memory = FFI::MemoryPointer.new :pointer, values.size
67
84
  values.each_with_index do |address, j|
68
- LibTest.ptr_set_pointer(memory, j * FFI.type_size(:pointer), LibTest.ptr_from_address(address))
85
+ PointerTestLib.ptr_set_pointer(memory, j * FFI.type_size(:pointer), PointerTestLib.ptr_from_address(address))
69
86
  end
70
87
  array = memory.read_array_of_pointer(values.size)
71
88
  values.each_with_index do |address, j|
72
89
  array[j].address.should == address
73
90
  end
74
91
  end
75
-
76
- describe "#write_array_of_pointer" do
77
- values = [0x12345678, 0xfeedf00d, 0xdeadbeef]
78
- memory = FFI::MemoryPointer.new :pointer, values.size
79
- memory.write_array_of_pointer(values.map { |address| LibTest.ptr_from_address(address) })
80
- array = []
81
- values.each_with_index do |address, j|
82
- array << LibTest.ptr_ret_pointer(memory, j * FFI.type_size(:pointer))
83
- end
84
- values.each_with_index do |address, j|
85
- array[j].address.should == address
86
- end
87
- end
88
92
 
89
93
  end
90
94
 
@@ -145,7 +149,7 @@ describe "AutoPointer" do
145
149
  # note that if we called
146
150
  # AutoPointerTestHelper.method(:release).to_proc inline, we'd
147
151
  # have a reference to the pointer and it would never get GC'd.
148
- ap = AutoPointerSubclass.new(LibTest.ptr_from_address(magic))
152
+ ap = AutoPointerSubclass.new(PointerTestLib.ptr_from_address(magic))
149
153
  end
150
154
  AutoPointerTestHelper.gc_everything loop_count
151
155
  end
@@ -162,7 +166,7 @@ describe "AutoPointer" do
162
166
  AutoPointerTestHelper.should_receive(:release).at_least(loop_count-wiggle_room).times
163
167
  AutoPointerTestHelper.reset
164
168
  loop_count.times do
165
- ap = FFI::AutoPointer.new(LibTest.ptr_from_address(magic),
169
+ ap = FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic),
166
170
  AutoPointerTestHelper.finalizer)
167
171
  end
168
172
  AutoPointerTestHelper.gc_everything loop_count
@@ -172,7 +176,7 @@ describe "AutoPointer" do
172
176
  AutoPointerTestHelper.should_receive(:release).at_least(loop_count-wiggle_room).times
173
177
  AutoPointerTestHelper.reset
174
178
  loop_count.times do
175
- ap = FFI::AutoPointer.new(LibTest.ptr_from_address(magic),
179
+ ap = FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic),
176
180
  AutoPointerTestHelper.method(:release))
177
181
  end
178
182
  AutoPointerTestHelper.gc_everything loop_count
@@ -200,7 +204,7 @@ describe "AutoPointer#new" do
200
204
  lambda { FFI::AutoPointer.new(FFI::MemoryPointer.new(:int))}.should raise_error(::TypeError)
201
205
  end
202
206
  it "AutoPointer argument raises TypeError" do
203
- lambda { AutoPointerSubclass.new(AutoPointerSubclass.new(LibTest.ptr_from_address(0))) }.should raise_error(::TypeError)
207
+ lambda { AutoPointerSubclass.new(AutoPointerSubclass.new(PointerTestLib.ptr_from_address(0))) }.should raise_error(::TypeError)
204
208
  end
205
209
  it "Buffer argument raises TypeError" do
206
210
  lambda { FFI::AutoPointer.new(FFI::Buffer.new(:int))}.should raise_error(::TypeError)
@@ -1,6 +1,20 @@
1
+ #
2
+ # This file is part of ruby-ffi.
3
+ #
4
+ # This code is free software: you can redistribute it and/or modify it under
5
+ # the terms of the GNU Lesser General Public License version 3 only, as
6
+ # published by the Free Software Foundation.
7
+ #
8
+ # This code is distributed in the hope that it will be useful, but WITHOUT
9
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ # version 3 for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
15
+ #
1
16
  require 'rubygems'
2
17
  require 'rbconfig'
3
- require 'spec'
4
18
 
5
19
  if RUBY_PLATFORM =~/java/
6
20
  libdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib"))
@@ -9,7 +23,7 @@ else
9
23
  $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib"),
10
24
  File.join(File.dirname(__FILE__), "..", "..", "build", "#{Config::CONFIG['host_cpu''arch']}", "ffi_c", RUBY_VERSION)
11
25
  end
12
- puts "loadpath=#{$:.join(':')}"
26
+ # puts "loadpath=#{$:.join(':')}"
13
27
  require "ffi"
14
28
 
15
29
  module TestLibrary
@@ -1,3 +1,19 @@
1
+ #
2
+ # This file is part of ruby-ffi.
3
+ #
4
+ # This code is free software: you can redistribute it and/or modify it under
5
+ # the terms of the GNU Lesser General Public License version 3 only, as
6
+ # published by the Free Software Foundation.
7
+ #
8
+ # This code is distributed in the hope that it will be useful, but WITHOUT
9
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ # version 3 for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+
1
17
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
18
  describe "String tests" do
3
19
  include FFI
@@ -10,14 +26,14 @@ describe "String tests" do
10
26
  attach_function :string_null, [ ], :string
11
27
  end
12
28
  it "MemoryPointer#get_string returns a tainted string" do
13
- mp = MemoryPointer.new 1024
29
+ mp = FFI::MemoryPointer.new 1024
14
30
  mp.put_string(0, "test\0")
15
31
  str = mp.get_string(0)
16
32
  str.tainted?.should == true
17
33
  end
18
34
  it "String returned by a method is tainted" do
19
- mp = MemoryPointer.new :pointer
20
- sp = MemoryPointer.new 1024
35
+ mp = FFI::MemoryPointer.new :pointer
36
+ sp = FFI::MemoryPointer.new 1024
21
37
  sp.put_string(0, "test")
22
38
  mp.put_pointer(0, sp)
23
39
  str = StrLibTest.ptr_ret_pointer(mp, 0)
@@ -45,9 +61,9 @@ describe "String tests" do
45
61
  end
46
62
  it "reads an array of strings until encountering a NULL pointer" do
47
63
  strings = ["foo", "bar", "baz", "testing", "ffi"]
48
- ptrary = MemoryPointer.new(:pointer, 6)
64
+ ptrary = FFI::MemoryPointer.new(:pointer, 6)
49
65
  ary = strings.inject([]) do |a, str|
50
- f = MemoryPointer.new(1024)
66
+ f = FFI::MemoryPointer.new(1024)
51
67
  f.put_string(0, str)
52
68
  a << f
53
69
  end
@@ -57,9 +73,9 @@ describe "String tests" do
57
73
  end
58
74
  it "reads an array of strings of the size specified, substituting nil when a pointer is NULL" do
59
75
  strings = ["foo", "bar", "baz", "testing", "ffi"]
60
- ptrary = MemoryPointer.new(:pointer, 6)
76
+ ptrary = FFI::MemoryPointer.new(:pointer, 6)
61
77
  ary = strings.inject([]) do |a, str|
62
- f = MemoryPointer.new(1024)
78
+ f = FFI::MemoryPointer.new(1024)
63
79
  f.put_string(0, str)
64
80
  a << f
65
81
  end
@@ -69,9 +85,9 @@ describe "String tests" do
69
85
  end
70
86
  it "reads an array of strings, taking a memory offset parameter" do
71
87
  strings = ["foo", "bar", "baz", "testing", "ffi"]
72
- ptrary = MemoryPointer.new(:pointer, 5)
88
+ ptrary = FFI::MemoryPointer.new(:pointer, 5)
73
89
  ary = strings.inject([]) do |a, str|
74
- f = MemoryPointer.new(1024)
90
+ f = FFI::MemoryPointer.new(1024)
75
91
  f.put_string(0, str)
76
92
  a << f
77
93
  end
@@ -80,9 +96,9 @@ describe "String tests" do
80
96
  end
81
97
  it "raises an IndexError when trying to read an array of strings out of bounds" do
82
98
  strings = ["foo", "bar", "baz", "testing", "ffi"]
83
- ptrary = MemoryPointer.new(:pointer, 5)
99
+ ptrary = FFI::MemoryPointer.new(:pointer, 5)
84
100
  ary = strings.inject([]) do |a, str|
85
- f = MemoryPointer.new(1024)
101
+ f = FFI::MemoryPointer.new(1024)
86
102
  f.put_string(0, str)
87
103
  a << f
88
104
  end
@@ -91,9 +107,9 @@ describe "String tests" do
91
107
  end
92
108
  it "raises an IndexError when trying to read an array of strings using a negative offset" do
93
109
  strings = ["foo", "bar", "baz", "testing", "ffi"]
94
- ptrary = MemoryPointer.new(:pointer, 5)
110
+ ptrary = FFI::MemoryPointer.new(:pointer, 5)
95
111
  ary = strings.inject([]) do |a, str|
96
- f = MemoryPointer.new(1024)
112
+ f = FFI::MemoryPointer.new(1024)
97
113
  f.put_string(0, str)
98
114
  a << f
99
115
  end
@@ -1,3 +1,18 @@
1
+ #
2
+ # This file is part of ruby-ffi.
3
+ #
4
+ # This code is free software: you can redistribute it and/or modify it under
5
+ # the terms of the GNU Lesser General Public License version 3 only, as
6
+ # published by the Free Software Foundation.
7
+ #
8
+ # This code is distributed in the hope that it will be useful, but WITHOUT
9
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ # version 3 for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
15
+ #
1
16
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
17
 
3
18
  describe FFI::Struct, ' with an initialize function' do
@@ -20,7 +35,7 @@ describe FFI::ManagedStruct, ' with an initialize function' do
20
35
  layout :string, :string
21
36
  attr_accessor :magic
22
37
  def initialize
23
- super MemoryPointer.new(:pointer).put_int(0, 0x1234).get_pointer(0)
38
+ super FFI::MemoryPointer.new(:pointer).put_int(0, 0x1234).get_pointer(0)
24
39
  self.magic = 42
25
40
  end
26
41
  def self.release;end
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 2
9
- version: 1.0.2
4
+ version: 1.0.3
10
5
  platform: ruby
11
6
  authors:
12
7
  - Wayne Meissner
@@ -14,39 +9,19 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-12-17 00:00:00 +10:00
12
+ date: 2010-12-28 00:00:00 +10:00
18
13
  default_executable:
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 8
31
- - 7
32
- version: 0.8.7
33
17
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: bones
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
40
20
  requirements:
41
21
  - - ">="
42
22
  - !ruby/object:Gem::Version
43
- segments:
44
- - 3
45
- - 4
46
- - 7
47
- version: 3.4.7
48
- type: :development
49
- version_requirements: *id002
23
+ version: 0.8.7
24
+ version:
50
25
  description: |-
51
26
  Ruby-FFI is a ruby extension for programmatically loading dynamic
52
27
  libraries, binding functions within them, and calling those functions
@@ -62,7 +37,6 @@ extensions:
62
37
  extra_rdoc_files:
63
38
  - History.txt
64
39
  - README.rdoc
65
- - lib/ffi_c.bundle
66
40
  files:
67
41
  - History.txt
68
42
  - LICENSE
@@ -102,6 +76,8 @@ files:
102
76
  - ext/ffi_c/StructByValue.c
103
77
  - ext/ffi_c/StructByValue.h
104
78
  - ext/ffi_c/StructLayout.c
79
+ - ext/ffi_c/Thread.c
80
+ - ext/ffi_c/Thread.h
105
81
  - ext/ffi_c/Type.c
106
82
  - ext/ffi_c/Type.h
107
83
  - ext/ffi_c/Types.c
@@ -391,7 +367,6 @@ files:
391
367
  - lib/ffi/types.rb
392
368
  - lib/ffi/union.rb
393
369
  - lib/ffi/variadic.rb
394
- - lib/ffi_c.bundle
395
370
  - spec/ffi/async_callback_spec.rb
396
371
  - spec/ffi/bool_spec.rb
397
372
  - spec/ffi/buffer_spec.rb
@@ -447,27 +422,21 @@ require_paths:
447
422
  - lib
448
423
  - ext
449
424
  required_ruby_version: !ruby/object:Gem::Requirement
450
- none: false
451
425
  requirements:
452
426
  - - ">="
453
427
  - !ruby/object:Gem::Version
454
- segments:
455
- - 1
456
- - 9
457
- - 2
458
- version: 1.9.2
428
+ version: "0"
429
+ version:
459
430
  required_rubygems_version: !ruby/object:Gem::Requirement
460
- none: false
461
431
  requirements:
462
432
  - - ">="
463
433
  - !ruby/object:Gem::Version
464
- segments:
465
- - 0
466
434
  version: "0"
435
+ version:
467
436
  requirements: []
468
437
 
469
438
  rubyforge_project: ffi
470
- rubygems_version: 1.3.7
439
+ rubygems_version: 1.3.5
471
440
  signing_key:
472
441
  specification_version: 3
473
442
  summary: Ruby-FFI is a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code