gir_ffi 0.4.1 → 0.4.2

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.4.2 / 2012-09-22
2
+
3
+ * Make objects and interfaces wrap poiners in the class that matches
4
+ their GType.
5
+
1
6
  == 0.4.1 / 2012-09-18
2
7
 
3
8
  * Remove workarounds for older versions of gobject-introspection
@@ -117,7 +117,7 @@ module GirFFI
117
117
  def self.wrap_object_pointer_by_gtype optr, gtype
118
118
  return nil if optr.null?
119
119
  klass = Builder.build_by_gtype gtype
120
- klass.wrap optr
120
+ klass.direct_wrap optr
121
121
  end
122
122
 
123
123
  def self.cast_from_pointer type, it
@@ -456,7 +456,7 @@ module GirFFI::Builder
456
456
  # Implements argument processing for object return values.
457
457
  class ObjectReturnValue < ReturnValue
458
458
  def post
459
- [ "#{retname} = GirFFI::ArgHelper.object_pointer_to_object(#{cvar})" ]
459
+ [ "#{retname} = #{argument_class_name}.wrap(#{cvar})" ]
460
460
  end
461
461
  end
462
462
 
@@ -13,6 +13,8 @@ module GirFFI
13
13
  # repository.
14
14
  module Builder
15
15
  module Type
16
+ CACHE = {}
17
+
16
18
  TYPE_MAP = {
17
19
  :callback => Callback,
18
20
  :constant => Constant,
@@ -7,8 +7,6 @@ module GirFFI
7
7
  # which no data is found in the GIR. Typically, these are created to
8
8
  # cast objects returned by a function that returns an interface.
9
9
  class Unintrospectable < Object
10
- CACHE = {}
11
-
12
10
  # FIXME: Breaks parent interface.
13
11
  def initialize gtype
14
12
  @gtype = gtype
@@ -36,6 +36,7 @@ module GirFFI
36
36
  @gtype = new_type
37
37
  @structklass = get_or_define_class @klass, :Struct, layout_superclass
38
38
  setup_class unless already_set_up
39
+ CACHE[@gtype] = @klass
39
40
  end
40
41
 
41
42
  def setup_class
@@ -61,7 +62,7 @@ module GirFFI
61
62
 
62
63
  def install_property pspec
63
64
  pinfo = GirFFI::UserDefined::IPropertyInfo.new
64
- pinfo.name = pspec.parent_instance.get_name
65
+ pinfo.name = pspec.get_name
65
66
  properties << pinfo
66
67
  end
67
68
 
@@ -75,7 +75,15 @@ module GirFFI
75
75
  alias_method :_real_new, :new
76
76
  undef new
77
77
 
78
+ # Wrap the passed pointer in an instance of the current class, or a
79
+ # descendant type if applicable.
78
80
  def wrap ptr
81
+ direct_wrap ptr
82
+ end
83
+
84
+ # Wrap the passed pointer in an instance of the current class. Will not
85
+ # do any casting to subtypes.
86
+ def direct_wrap ptr
79
87
  return nil if ptr.nil? or ptr.null?
80
88
  obj = _real_new
81
89
  obj.instance_variable_set :@struct, self::Struct.new(ptr.to_ptr)
@@ -17,6 +17,10 @@ module GirFFI
17
17
  def setup_instance_method name
18
18
  _builder.setup_instance_method name
19
19
  end
20
+
21
+ def wrap ptr
22
+ GirFFI::ArgHelper.object_pointer_to_object ptr
23
+ end
20
24
  end
21
25
  end
22
26
 
@@ -2,16 +2,25 @@ module GirFFI
2
2
  # Base class for all generated classes of type :object.
3
3
  class ObjectBase < ClassBase
4
4
  #
5
- # Wraps a pointer retrieved from a constructor method. Here,
6
- # it is simply defined as a wrapper around wrap, but, e.g., InitiallyUnowned
5
+ # Wraps a pointer retrieved from a constructor method. Here, it is simply
6
+ # defined as a wrapper around direct_wrap, but, e.g., InitiallyUnowned
7
7
  # overrides it to sink the floating object.
8
8
  #
9
+ # Unlike wrap, this method assumes the pointer will always be of the type
10
+ # corresponding to the current class, and never of a subtype.
11
+ #
9
12
  # @param ptr Pointer to the object's C structure
10
13
  #
11
14
  # @return An object of the current class wrapping the pointer
12
15
  #
13
16
  def self.constructor_wrap ptr
14
- wrap ptr
17
+ direct_wrap ptr
18
+ end
19
+
20
+ # Wrap the passed pointer in an instance of its type's corresponding class,
21
+ # generally assumed to be a descendant of the current type.
22
+ def self.wrap ptr
23
+ GirFFI::ArgHelper.object_pointer_to_object ptr
15
24
  end
16
25
 
17
26
  #
@@ -1,4 +1,4 @@
1
1
  module GirFFI
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
4
4
 
@@ -96,7 +96,7 @@ describe GirFFI::ArgHelper do
96
96
 
97
97
  object_class = Class.new
98
98
  mock(GirFFI::Builder).build_by_gtype(0xdeadbeef) { object_class }
99
- mock(object_class).wrap(objptr) { "good-result" }
99
+ mock(object_class).direct_wrap(objptr) { "good-result" }
100
100
 
101
101
  r = GirFFI::ArgHelper.object_pointer_to_object objptr
102
102
  assert_equal "good-result", r
@@ -0,0 +1,14 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GirFFI::InterfaceBase do
4
+ describe "#wrap" do
5
+ it "dynamically looks op the wrapped object's class" do
6
+ mod = Module.new { extend GirFFI::InterfaceBase }
7
+
8
+ mock(GirFFI::ArgHelper).object_pointer_to_object("some-pointer") { "good-result" }
9
+
10
+ mod.wrap("some-pointer").must_equal "good-result"
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,15 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GirFFI::ObjectBase do
4
+ describe "#wrap" do
5
+ it "dynamically looks op the wrapped object's class" do
6
+ mod = Class.new GirFFI::ObjectBase
7
+
8
+ mock(GirFFI::ArgHelper).object_pointer_to_object("some-pointer") { "good-result" }
9
+
10
+ mod.wrap("some-pointer").must_equal "good-result"
11
+ end
12
+ end
13
+ end
14
+
15
+
@@ -56,6 +56,11 @@ describe GirFFI do
56
56
  type = GObject.type_from_instance obj
57
57
  type.must_equal @gtype
58
58
  end
59
+
60
+ it "makes GirFFI find the new class by GType" do
61
+ klass = GirFFI::Builder.build_by_gtype @gtype
62
+ klass.must_equal @klass
63
+ end
59
64
  end
60
65
 
61
66
  describe "with a block with a call to #install_property" do
@@ -149,8 +149,7 @@ describe Regress, "The generated Regress module" do
149
149
  end
150
150
 
151
151
  it "has a refcount of 1" do
152
- # FIXME: Should be able to do @so.refcount
153
- assert_equal 1, @so.fundamental_object.refcount
152
+ assert_equal 1, @so.refcount
154
153
  end
155
154
  end
156
155
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-18 00:00:00.000000000 Z
12
+ date: 2012-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -220,6 +220,7 @@ files:
220
220
  - test/gir_ffi/builder/module_test.rb
221
221
  - test/gir_ffi/builder/function_test.rb
222
222
  - test/gir_ffi/builder/argument/base_test.rb
223
+ - test/gir_ffi/object_base_test.rb
223
224
  - test/gir_ffi/user_defined/i_registered_type_info_test.rb
224
225
  - test/gir_ffi/user_defined/i_object_info_test.rb
225
226
  - test/gir_ffi/user_defined/i_property_info_test.rb
@@ -232,6 +233,7 @@ files:
232
233
  - test/gir_ffi/class_base_test.rb
233
234
  - test/gir_ffi/info_ext/i_type_info_test.rb
234
235
  - test/gir_ffi/info_ext/i_field_info_test.rb
236
+ - test/gir_ffi/interface_base_test.rb
235
237
  - test/gir_ffi-base/glib/strv_test.rb
236
238
  - test/ffi-gobject/object_class_test.rb
237
239
  - test/ffi-gobject/object_test.rb
@@ -339,6 +341,8 @@ test_files:
339
341
  - test/gir_ffi/in_pointer_test.rb
340
342
  - test/gir_ffi/info_ext/i_field_info_test.rb
341
343
  - test/gir_ffi/info_ext/i_type_info_test.rb
344
+ - test/gir_ffi/interface_base_test.rb
345
+ - test/gir_ffi/object_base_test.rb
342
346
  - test/gir_ffi/user_defined/i_object_info_test.rb
343
347
  - test/gir_ffi/user_defined/i_property_info_test.rb
344
348
  - test/gir_ffi/user_defined/i_registered_type_info_test.rb