gir_ffi 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,8 @@
1
+ == 0.0.12 / 2011-09-04
2
+
3
+ * No longer use _id2ref to locate objects past as user data pointers.
4
+ * Fix failing tests on JRuby.
5
+
1
6
  == 0.0.11 / 2011-08-22
2
7
 
3
8
  * Change interface to the underlying builder in generated modules and
@@ -0,0 +1,59 @@
1
+ require 'gir_ffi'
2
+
3
+ # File activesupport/lib/active_support/inflector/methods.rb, line 48
4
+ def underscore(camel_cased_word)
5
+ word = camel_cased_word.to_s.dup
6
+ word.gsub!(/::/, '/')
7
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
8
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
9
+ word.tr!("-", "_")
10
+ word.downcase!
11
+ word
12
+ end
13
+
14
+ namespace = 'Tracker'
15
+ GirFFI.setup namespace
16
+
17
+ gir = GirFFI::IRepository.default
18
+ gir.require namespace, nil
19
+ infos = gir.infos namespace
20
+
21
+ main_file = File.open(File.join('.', "#{underscore(namespace)}.rb"), 'w')
22
+
23
+ main_file.write "module #{namespace}\n"
24
+
25
+ infos.each do |info|
26
+ case info.info_type
27
+ when :function
28
+ fbuilder = GirFFI::Builder::Function.new info, Tracker::Lib
29
+ main_file.write "\n"
30
+ main_file.write fbuilder.generate
31
+ main_file.write "\n"
32
+ when :object
33
+ main_file.write "class #{info.name} < #{info.parent.name}\n"
34
+ info.get_methods.each do |minfo|
35
+ main_file.write "\n"
36
+ unless minfo.method?
37
+ main_file.write "class << self\n"
38
+ end
39
+ if minfo.constructor?
40
+ main_file.write "# This method is a constructor\n"
41
+ end
42
+ main_file.write "# @return [#{minfo.return_type.tag}]\n"
43
+
44
+ fbuilder = GirFFI::Builder::Function.new minfo, Tracker::Lib
45
+ main_file.write fbuilder.generate
46
+ unless minfo.method?
47
+ main_file.write "end\n"
48
+ end
49
+ main_file.write "\n"
50
+ end
51
+ main_file.write "end\n"
52
+ else
53
+ puts "#{info.info_type}: #{info.name}\n"
54
+ end
55
+ end
56
+
57
+ main_file.write "end\n"
58
+ main_file.close
59
+
@@ -4,6 +4,8 @@ require 'gir_ffi/builder'
4
4
 
5
5
  module GirFFI
6
6
  module ArgHelper
7
+ OBJECT_STORE = {}
8
+
7
9
  POINTER_SIZE = FFI.type_size(:pointer)
8
10
 
9
11
  SIMPLE_G_TYPES = [
@@ -16,6 +18,8 @@ module GirFFI
16
18
  return obj.to_ptr if obj.respond_to? :to_ptr
17
19
  return nil if obj.nil?
18
20
  return obj if obj.is_a? FFI::Pointer
21
+
22
+ OBJECT_STORE[obj.object_id] = obj
19
23
  FFI::Pointer.new(obj.object_id)
20
24
  end
21
25
 
@@ -45,12 +45,7 @@ module GirFFI
45
45
  if arg.null?
46
46
  nil
47
47
  else
48
- begin
49
- # TODO: Use custom object store.
50
- ObjectSpace._id2ref arg.address
51
- rescue RangeError
52
- arg
53
- end
48
+ GirFFI::ArgHelper::OBJECT_STORE[arg.address]
54
49
  end
55
50
  end
56
51
  end
@@ -29,7 +29,7 @@ module GirFFI
29
29
  def self.for type
30
30
  ffi_type = type_to_ffi_type type
31
31
  ptr = AllocationHelper.safe_malloc(FFI.type_size ffi_type)
32
- ptr.send "put_#{ffi_type}", 0, 0
32
+ ptr.send "put_#{ffi_type}", 0, nil_value_for(type)
33
33
  self.new ptr, type, ffi_type
34
34
  end
35
35
 
@@ -70,6 +70,15 @@ module GirFFI
70
70
  value
71
71
  end
72
72
  end
73
+
74
+ def nil_value_for type
75
+ case type
76
+ when :utf8, :pointer
77
+ nil
78
+ else
79
+ 0
80
+ end
81
+ end
73
82
  end
74
83
  end
75
84
  end
@@ -218,15 +218,7 @@ module GirFFI
218
218
 
219
219
  # User Data
220
220
  arg = args.shift
221
- arg = if FFI::Pointer === arg
222
- begin
223
- ObjectSpace._id2ref arg.address
224
- rescue RangeError
225
- arg
226
- end
227
- else
228
- arg
229
- end
221
+ arg = GirFFI::ArgHelper::OBJECT_STORE[arg.address]
230
222
  result << arg
231
223
 
232
224
  return result
@@ -1,4 +1,4 @@
1
1
  module GirFFI
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
4
4
 
@@ -1,6 +1,9 @@
1
- require "rdoc/task"
1
+ begin
2
+ require "rdoc/task"
2
3
 
3
- RDoc::Task.new(:rdoc => "rdoc", :clobber_rdoc => "rdoc:clean", :rerdoc => "rdoc:force") do |rdoc|
4
- rdoc.main = "README.rdoc"
5
- rdoc.rdoc_files.include "README.rdoc", "DESIGN.rdoc", "TODO.rdoc", "lib/**/*.rb"
4
+ RDoc::Task.new(:rdoc => "rdoc", :clobber_rdoc => "rdoc:clean", :rerdoc => "rdoc:force") do |rdoc|
5
+ rdoc.main = "README.rdoc"
6
+ rdoc.rdoc_files.include "README.rdoc", "DESIGN.rdoc", "TODO.rdoc", "lib/**/*.rb"
7
+ end
8
+ rescue LoadError
6
9
  end
@@ -1,6 +1,9 @@
1
- require 'yard'
1
+ begin
2
+ require 'yard'
2
3
 
3
- YARD::Rake::YardocTask.new do |t|
4
- t.files = ['lib/**/*.rb']
5
- t.options = ['--private', '--protected', '--readme', 'README.rdoc', "--files", "DESIGN.rdoc,TODO.rdoc"]
4
+ YARD::Rake::YardocTask.new do |t|
5
+ t.files = ['lib/**/*.rb']
6
+ t.options = ['--private', '--protected', '--readme', 'README.rdoc', "--files", "DESIGN.rdoc,TODO.rdoc"]
7
+ end
8
+ rescue LoadError
6
9
  end
@@ -112,7 +112,7 @@ class BuilderTest < MiniTest::Spec
112
112
  end
113
113
 
114
114
  should "have correct introspection data" do
115
- @gir.require "Gtk", nil
115
+ @gir.require "Gtk", "2.0"
116
116
  go2 = @gir.find_by_name "Gtk", "main"
117
117
  assert_equal go2, @go
118
118
  end
@@ -213,6 +213,7 @@ class BuilderTest < MiniTest::Spec
213
213
  end
214
214
 
215
215
  should "set up struct members with the correct types" do
216
+ skip "JRuby creates new type wrappers every time, so this test fails" if RUBY_PLATFORM == 'java'
216
217
  tags = [:int, :int8, :double, Regress::TestEnum]
217
218
  assert_equal tags.map {|t| FFI.find_type t},
218
219
  Regress::TestStructA::Struct.layout.fields.map {|f| f.type}
@@ -34,6 +34,10 @@ module GirFFI
34
34
  end
35
35
  end
36
36
 
37
+ # Preload data for Gtk+ version 2.0.
38
+ gir = GirFFI::IRepository.default
39
+ gir.require "Gtk", "2.0"
40
+
37
41
  # Need a dummy module for some tests.
38
42
  module Lib
39
43
  end
@@ -0,0 +1,57 @@
1
+ require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
2
+
3
+ describe GirFFI::IRepository do
4
+ describe "an instance" do
5
+ should "not be created by calling new()" do
6
+ assert_raises NoMethodError do
7
+ GirFFI::IRepository.new
8
+ end
9
+ end
10
+
11
+ should "be created by calling default()" do
12
+ gir = GirFFI::IRepository.default
13
+ assert_kind_of GirFFI::IRepository, gir
14
+ end
15
+
16
+ should "be a singleton" do
17
+ gir = GirFFI::IRepository.default
18
+ gir2 = GirFFI::IRepository.default
19
+ assert_equal gir, gir2
20
+ end
21
+ end
22
+
23
+ describe "#namespace" do
24
+ should "raise an error if the namespace doesn't exist" do
25
+ assert_raises RuntimeError do
26
+ GirFFI::IRepository.default.require 'VeryUnlikelyGObjectNamespaceName', nil
27
+ end
28
+ end
29
+
30
+ should "allow version to be nil" do
31
+ assert_nothing_raised do
32
+ GirFFI::IRepository.default.require 'GObject', nil
33
+ end
34
+ end
35
+
36
+ should "allow version to be left out" do
37
+ assert_nothing_raised do
38
+ GirFFI::IRepository.default.require 'GObject'
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "enumerating the infos for Gtk" do
44
+ setup do
45
+ @gir = GirFFI::IRepository.default
46
+ @gir.require 'Gtk', "2.0"
47
+ end
48
+
49
+ should "yield more than one object" do
50
+ assert_operator @gir.n_infos('Gtk'), :>, 0
51
+ end
52
+
53
+ should "yield IBaseInfo objects" do
54
+ assert_kind_of GirFFI::IBaseInfo, @gir.info('Gtk', 0)
55
+ end
56
+ end
57
+ end
@@ -9,7 +9,7 @@ describe GirFFI::InOutPointer do
9
9
  end
10
10
 
11
11
  it "holds a pointer to the given value" do
12
- assert_equal 23, @result.read_int32
12
+ assert_equal 23, @result.get_int32(0)
13
13
  end
14
14
 
15
15
  it "is an instance of GirFFI::InOutPointer" do
@@ -72,7 +72,7 @@ describe GirFFI::InOutPointer do
72
72
  end
73
73
 
74
74
  it "holds a pointer to a null value" do
75
- assert_equal 0, @result.read_int32
75
+ assert_equal 0, @result.get_int32(0)
76
76
  end
77
77
 
78
78
  it "is an instance of GirFFI::InOutPointer" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matijs van Zuijlen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-22 00:00:00 Z
18
+ date: 2011-09-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: ffi
@@ -141,7 +141,6 @@ files:
141
141
  - lib/gir_ffi/i_interface_info.rb
142
142
  - lib/gir_ffi/i_arg_info.rb
143
143
  - lib/gir_ffi/i_type_info.rb
144
- - test/i_repository_test.rb
145
144
  - test/unintrospectable_type_builder_test.rb
146
145
  - test/function_definition_builder_test.rb
147
146
  - test/g_object_test.rb
@@ -157,6 +156,7 @@ files:
157
156
  - test/module_builder_test.rb
158
157
  - test/i_object_info_test.rb
159
158
  - test/g_object_overrides_test.rb
159
+ - test/unit/i_repository_test.rb
160
160
  - test/unit/constant_builder_test.rb
161
161
  - test/unit/in_out_pointer_test.rb
162
162
  - test/unit/callback_helper_test.rb
@@ -178,6 +178,7 @@ files:
178
178
  - tasks/test.rake
179
179
  - tasks/setup.rb
180
180
  - tasks/notes.rake
181
+ - examples/print_class.rb
181
182
  - examples/05_notification.rb
182
183
  - examples/demo_ffi_safe_inherited_layout.rb
183
184
  - examples/04_webkit.rb
@@ -237,7 +238,6 @@ test_files:
237
238
  - test/glib_overrides_test.rb
238
239
  - test/gtk_overrides_test.rb
239
240
  - test/i_object_info_test.rb
240
- - test/i_repository_test.rb
241
241
  - test/integration/generated_gimarshallingtests_test.rb
242
242
  - test/integration/generated_gio_test.rb
243
243
  - test/integration/generated_gobject_test.rb
@@ -256,6 +256,7 @@ test_files:
256
256
  - test/unit/callback_helper_test.rb
257
257
  - test/unit/constant_builder_test.rb
258
258
  - test/unit/i_constant_info_test.rb
259
+ - test/unit/i_repository_test.rb
259
260
  - test/unit/in_out_pointer_test.rb
260
261
  - test/unit/in_pointer_test.rb
261
262
  - test/unit/object_type_builder_test.rb
@@ -1,59 +0,0 @@
1
- require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
-
3
- module GirFFI
4
- class IRepositoryTest < MiniTest::Spec
5
- context "An IRepository object" do
6
- should "not be created by calling new()" do
7
- assert_raises NoMethodError do
8
- IRepository.new
9
- end
10
- end
11
-
12
- should "be created by calling default()" do
13
- gir = IRepository.default
14
- assert_kind_of IRepository, gir
15
- end
16
-
17
- should "be a singleton" do
18
- gir = IRepository.default
19
- gir2 = IRepository.default
20
- assert_equal gir, gir2
21
- end
22
- end
23
-
24
- context "The namespace method" do
25
- should "raise an error if the namespace doesn't exist" do
26
- assert_raises RuntimeError do
27
- IRepository.default.require 'VeryUnlikelyGObjectNamespaceName', nil
28
- end
29
- end
30
-
31
- should "allow version to be nil" do
32
- assert_nothing_raised do
33
- IRepository.default.require 'GObject', nil
34
- end
35
- end
36
-
37
- should "allow version to be left out" do
38
- assert_nothing_raised do
39
- IRepository.default.require 'GObject'
40
- end
41
- end
42
- end
43
-
44
- context "Enumerating the infos for Gtk" do
45
- setup do
46
- @gir = IRepository.default
47
- @gir.require 'Gtk'
48
- end
49
-
50
- should "yield more than one object" do
51
- assert_operator @gir.n_infos('Gtk'), :>, 0
52
- end
53
-
54
- should "yield IBaseInfo objects" do
55
- assert_kind_of IBaseInfo, @gir.info('Gtk', 0)
56
- end
57
- end
58
- end
59
- end