gir_ffi 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/gir_ffi/arg_helper.rb +1 -1
- data/lib/gir_ffi/builder/argument.rb +1 -1
- data/lib/gir_ffi/builder/type.rb +2 -0
- data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -2
- data/lib/gir_ffi/builder/type/user_defined.rb +2 -1
- data/lib/gir_ffi/class_base.rb +8 -0
- data/lib/gir_ffi/interface_base.rb +4 -0
- data/lib/gir_ffi/object_base.rb +12 -3
- data/lib/gir_ffi/version.rb +1 -1
- data/test/gir_ffi/arg_helper_test.rb +1 -1
- data/test/gir_ffi/interface_base_test.rb +14 -0
- data/test/gir_ffi/object_base_test.rb +15 -0
- data/test/gir_ffi_test.rb +5 -0
- data/test/integration/generated_regress_test.rb +1 -2
- metadata +6 -2
data/History.txt
CHANGED
data/lib/gir_ffi/arg_helper.rb
CHANGED
@@ -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} =
|
459
|
+
[ "#{retname} = #{argument_class_name}.wrap(#{cvar})" ]
|
460
460
|
end
|
461
461
|
end
|
462
462
|
|
data/lib/gir_ffi/builder/type.rb
CHANGED
@@ -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.
|
65
|
+
pinfo.name = pspec.get_name
|
65
66
|
properties << pinfo
|
66
67
|
end
|
67
68
|
|
data/lib/gir_ffi/class_base.rb
CHANGED
@@ -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)
|
data/lib/gir_ffi/object_base.rb
CHANGED
@@ -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
|
-
#
|
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
|
-
|
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
|
#
|
data/lib/gir_ffi/version.rb
CHANGED
@@ -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).
|
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
|
+
|
data/test/gir_ffi_test.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|