gir_ffi 0.6.3 → 0.6.4
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.
- data/History.txt +11 -0
- data/README.md +24 -6
- data/lib/ffi-glib/ptr_array.rb +17 -1
- data/lib/ffi-glib/variant.rb +15 -0
- data/lib/ffi-glib.rb +1 -0
- data/lib/ffi-gobject/object.rb +1 -1
- data/lib/ffi-gobject/ruby_closure.rb +1 -1
- data/lib/ffi-gobject/value.rb +13 -3
- data/lib/ffi-gobject.rb +1 -2
- data/lib/ffi-gobject_introspection/i_enum_info.rb +14 -0
- data/lib/ffi-gobject_introspection/lib.rb +2 -0
- data/lib/gir_ffi/arg_helper.rb +2 -0
- data/lib/gir_ffi/argument_builder.rb +22 -21
- data/lib/gir_ffi/base_argument_builder.rb +2 -1
- data/lib/gir_ffi/builder/module.rb +2 -3
- data/lib/gir_ffi/builder/type/enum.rb +18 -1
- data/lib/gir_ffi/builder/type/object.rb +20 -18
- data/lib/gir_ffi/class_base.rb +0 -1
- data/lib/gir_ffi/enum_base.rb +25 -0
- data/lib/gir_ffi/ffi_ext.rb +1 -0
- data/lib/gir_ffi/function_builder.rb +50 -33
- data/lib/gir_ffi/in_out_pointer.rb +0 -5
- data/lib/gir_ffi/in_pointer.rb +7 -5
- data/lib/gir_ffi/info_ext/i_callable_info.rb +4 -0
- data/lib/gir_ffi/info_ext/i_enum_info.rb +13 -0
- data/lib/gir_ffi/info_ext/i_field_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_object_info.rb +11 -0
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +11 -0
- data/lib/gir_ffi/info_ext/i_struct_info.rb +11 -0
- data/lib/gir_ffi/info_ext/i_type_info.rb +10 -19
- data/lib/gir_ffi/info_ext/i_union_info.rb +12 -0
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +0 -2
- data/lib/gir_ffi/info_ext.rb +4 -0
- data/lib/gir_ffi/interface_base.rb +0 -1
- data/lib/gir_ffi/return_value_builder.rb +3 -2
- data/lib/gir_ffi/type_map.rb +3 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi/zero_terminated.rb +36 -3
- data/lib/gir_ffi-base/gir_ffi/library.rb +17 -0
- data/lib/gir_ffi-base/gobject/lib.rb +2 -2
- data/lib/gir_ffi.rb +1 -0
- data/tasks/test.rake +1 -0
- data/test/base_test_helper.rb +22 -2
- data/test/ffi-glib/ruby_closure_test.rb +1 -1
- data/test/ffi-glib/variant_test.rb +10 -0
- data/test/ffi-gobject/value_test.rb +24 -8
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +17 -0
- data/test/gir_ffi/argument_builder_test.rb +66 -24
- data/test/gir_ffi/builder_test.rb +1 -1
- data/test/gir_ffi/function_builder_test.rb +1 -3
- data/test/gir_ffi/in_out_pointer_test.rb +5 -3
- data/test/gir_ffi/in_pointer_test.rb +32 -2
- data/test/gir_ffi/info_ext/i_arg_info_test.rb +2 -2
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +2 -2
- data/test/gir_ffi/info_ext/i_field_info_test.rb +14 -20
- data/test/gir_ffi/info_ext/i_function_info_test.rb +2 -2
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +2 -2
- data/test/gir_ffi/info_ext/i_type_info_test.rb +8 -8
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +2 -2
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +2 -2
- data/test/gir_ffi/return_value_builder_test.rb +18 -1
- data/test/gir_ffi/zero_terminated_test.rb +10 -0
- data/test/gir_ffi_test_helper.rb +0 -19
- data/test/integration/generated_gimarshallingtests_test.rb +291 -99
- data/test/integration/generated_regress_test.rb +138 -14
- data/test/lib/autogen.sh +6 -2
- metadata +14 -2
@@ -40,9 +40,6 @@ module GirFFI
|
|
40
40
|
case @value_type
|
41
41
|
when :gboolean
|
42
42
|
(value ? 1 : 0)
|
43
|
-
# TODO: Remove all references to :utf8 from this class
|
44
|
-
when :utf8
|
45
|
-
InPointer.from :utf8, value
|
46
43
|
else
|
47
44
|
value || nil_value
|
48
45
|
end
|
@@ -60,7 +57,5 @@ module GirFFI
|
|
60
57
|
value
|
61
58
|
end
|
62
59
|
end
|
63
|
-
|
64
60
|
end
|
65
61
|
end
|
66
|
-
|
data/lib/gir_ffi/in_pointer.rb
CHANGED
@@ -10,8 +10,10 @@ module GirFFI
|
|
10
10
|
from_utf8_array ary
|
11
11
|
when Symbol
|
12
12
|
from_basic_type_array type, ary
|
13
|
-
when
|
14
|
-
from_enum_array type, ary
|
13
|
+
when Module
|
14
|
+
from_enum_array type::Enum, ary
|
15
|
+
when Array
|
16
|
+
from_interface_pointer_array ary
|
15
17
|
else
|
16
18
|
raise NotImplementedError, type
|
17
19
|
end
|
@@ -22,14 +24,14 @@ module GirFFI
|
|
22
24
|
case type
|
23
25
|
when :utf8, :filename
|
24
26
|
from_utf8 val
|
25
|
-
when :gint32, :gint8
|
27
|
+
when :gint32, :guint32, :gint8
|
26
28
|
self.new val
|
27
|
-
when
|
29
|
+
when Module
|
28
30
|
self.new type[val]
|
29
31
|
when :void
|
30
32
|
ArgHelper.object_to_inptr val
|
31
33
|
else
|
32
|
-
raise NotImplementedError
|
34
|
+
raise NotImplementedError, type
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
@@ -1,11 +1,22 @@
|
|
1
1
|
require 'gir_ffi/builder_helper'
|
2
|
+
require 'gir_ffi/info_ext/safe_constant_name'
|
2
3
|
|
3
4
|
module GirFFI
|
4
5
|
module InfoExt
|
5
6
|
module IRegisteredTypeInfo
|
7
|
+
include SafeConstantName
|
8
|
+
|
6
9
|
def full_type_name
|
7
10
|
"::#{safe_namespace}::#{name}"
|
8
11
|
end
|
12
|
+
|
13
|
+
def to_ffitype
|
14
|
+
to_type
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_type
|
18
|
+
Builder.build_class self
|
19
|
+
end
|
9
20
|
end
|
10
21
|
end
|
11
22
|
end
|
@@ -20,23 +20,6 @@ module GirFFI
|
|
20
20
|
GObject::Value.for_g_type g_type
|
21
21
|
end
|
22
22
|
|
23
|
-
def layout_specification_type
|
24
|
-
ffitype = self.to_ffitype
|
25
|
-
case ffitype
|
26
|
-
when Class
|
27
|
-
ffitype.const_get :Struct
|
28
|
-
when :array
|
29
|
-
subtype = param_type(0).layout_specification_type
|
30
|
-
# XXX Don't use pointer directly to appease JRuby.
|
31
|
-
if subtype == :pointer
|
32
|
-
subtype = :"uint#{FFI.type_size(:pointer)*8}"
|
33
|
-
end
|
34
|
-
[subtype, array_fixed_size]
|
35
|
-
else
|
36
|
-
ffitype
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
23
|
def element_type
|
41
24
|
case tag
|
42
25
|
when :glist, :gslist, :array
|
@@ -117,8 +100,16 @@ module GirFFI
|
|
117
100
|
return :pointer if pointer?
|
118
101
|
|
119
102
|
type_tag = tag
|
120
|
-
|
121
|
-
|
103
|
+
case type_tag
|
104
|
+
when :interface
|
105
|
+
interface.to_ffitype
|
106
|
+
when :array
|
107
|
+
subtype = param_type(0).to_ffitype
|
108
|
+
# NOTE: Don't use pointer directly to appease JRuby.
|
109
|
+
if subtype == :pointer
|
110
|
+
subtype = :"uint#{FFI.type_size(:pointer)*8}"
|
111
|
+
end
|
112
|
+
[subtype, array_fixed_size]
|
122
113
|
else
|
123
114
|
TypeMap.map_basic_type type_tag
|
124
115
|
end
|
@@ -16,7 +16,5 @@ module GirFFI
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
GObjectIntrospection::IRegisteredTypeInfo.send :include, GirFFI::InfoExt::SafeConstantName
|
20
19
|
GObjectIntrospection::ICallbackInfo.send :include, GirFFI::InfoExt::SafeConstantName
|
21
20
|
GObjectIntrospection::IConstantInfo.send :include, GirFFI::InfoExt::SafeConstantName
|
22
|
-
|
data/lib/gir_ffi/info_ext.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'gir_ffi/info_ext/i_arg_info'
|
2
2
|
require 'gir_ffi/info_ext/i_callable_info'
|
3
|
+
require 'gir_ffi/info_ext/i_enum_info'
|
3
4
|
require 'gir_ffi/info_ext/i_field_info'
|
4
5
|
require 'gir_ffi/info_ext/i_function_info'
|
6
|
+
require 'gir_ffi/info_ext/i_object_info'
|
5
7
|
require 'gir_ffi/info_ext/i_property_info'
|
6
8
|
require 'gir_ffi/info_ext/i_registered_type_info'
|
7
9
|
require 'gir_ffi/info_ext/i_signal_info'
|
10
|
+
require 'gir_ffi/info_ext/i_struct_info'
|
8
11
|
require 'gir_ffi/info_ext/i_type_info'
|
12
|
+
require 'gir_ffi/info_ext/i_union_info'
|
9
13
|
require 'gir_ffi/info_ext/safe_constant_name'
|
10
14
|
require 'gir_ffi/info_ext/safe_function_name'
|
@@ -63,9 +63,10 @@ module GirFFI
|
|
63
63
|
needs_wrapping? || [ :utf8, :c ].include?(specialized_type_tag)
|
64
64
|
end
|
65
65
|
|
66
|
+
# TODO: Merge with ArgumentBuilder#needs_outgoing_parameter_conversion?
|
66
67
|
def needs_wrapping?
|
67
|
-
[ :
|
68
|
-
:
|
68
|
+
[ :array, :byte_array, :error, :ghash, :glist, :gslist, :interface,
|
69
|
+
:object, :ptr_array, :struct, :strv, :union, :zero_terminated
|
69
70
|
].include?(specialized_type_tag)
|
70
71
|
end
|
71
72
|
|
data/lib/gir_ffi/type_map.rb
CHANGED
data/lib/gir_ffi/version.rb
CHANGED
@@ -26,7 +26,10 @@ module GirFFI
|
|
26
26
|
return if @ptr.null?
|
27
27
|
offset = 0
|
28
28
|
while val = read_value(offset)
|
29
|
-
offset += FFI.type_size(
|
29
|
+
offset += FFI.type_size(ffi_type)
|
30
|
+
if complex_element_type?
|
31
|
+
val = element_class.wrap val
|
32
|
+
end
|
30
33
|
yield val
|
31
34
|
end
|
32
35
|
end
|
@@ -34,8 +37,38 @@ module GirFFI
|
|
34
37
|
private
|
35
38
|
|
36
39
|
def read_value offset
|
37
|
-
val = @ptr.
|
38
|
-
return val unless val
|
40
|
+
val = @ptr.send("get_#{ffi_type}", offset)
|
41
|
+
return val unless is_null_value(val)
|
42
|
+
end
|
43
|
+
|
44
|
+
def ffi_type
|
45
|
+
@ffi_type ||= TypeMap.map_basic_type_or_string basic_element_type
|
46
|
+
end
|
47
|
+
|
48
|
+
def complex_element_type?
|
49
|
+
Array === element_type
|
50
|
+
end
|
51
|
+
|
52
|
+
def basic_element_type
|
53
|
+
if complex_element_type?
|
54
|
+
element_type.first
|
55
|
+
else
|
56
|
+
element_type
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def is_null_value value
|
61
|
+
if basic_element_type == :pointer
|
62
|
+
value.null?
|
63
|
+
else
|
64
|
+
value == 0
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def element_class
|
69
|
+
if complex_element_type?
|
70
|
+
element_type.last
|
71
|
+
end
|
39
72
|
end
|
40
73
|
end
|
41
74
|
end
|
data/lib/gir_ffi.rb
CHANGED
data/tasks/test.rake
CHANGED
data/test/base_test_helper.rb
CHANGED
@@ -10,6 +10,28 @@ end
|
|
10
10
|
require 'minitest/autorun'
|
11
11
|
require 'rr'
|
12
12
|
|
13
|
+
require 'gir_ffi-base'
|
14
|
+
require 'ffi-gobject_introspection'
|
15
|
+
|
16
|
+
GObjectIntrospection::IRepository.prepend_search_path File.join(File.dirname(__FILE__), 'lib')
|
17
|
+
module GObjectIntrospection
|
18
|
+
class IRepository
|
19
|
+
def shared_library_with_regress namespace
|
20
|
+
case namespace
|
21
|
+
when "Regress"
|
22
|
+
return File.join(File.dirname(__FILE__), 'lib', 'libregress.so')
|
23
|
+
when "GIMarshallingTests"
|
24
|
+
return File.join(File.dirname(__FILE__), 'lib', 'libgimarshallingtests.so')
|
25
|
+
else
|
26
|
+
return shared_library_without_regress namespace
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
alias shared_library_without_regress shared_library
|
31
|
+
alias shared_library shared_library_with_regress
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
13
35
|
Thread.abort_on_exception = true
|
14
36
|
|
15
37
|
class Minitest::Test
|
@@ -71,5 +93,3 @@ class Minitest::Spec
|
|
71
93
|
alias :context :describe
|
72
94
|
end
|
73
95
|
end
|
74
|
-
|
75
|
-
require 'gir_ffi-base'
|
@@ -42,25 +42,41 @@ describe GObject::Value do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
describe "#
|
45
|
+
describe "#set_value" do
|
46
|
+
it "handles :int64" do
|
47
|
+
value = 0x1234_5678_9012_3456
|
48
|
+
gv = GObject::Value.for_g_type GObject::TYPE_INT64
|
49
|
+
gv.set_value value
|
50
|
+
gv.get_int64.must_equal value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#get_value" do
|
46
55
|
it "unwraps a boolean false" do
|
47
56
|
gv = GObject::Value.wrap_ruby_value false
|
48
|
-
result = gv.
|
57
|
+
result = gv.get_value
|
49
58
|
assert_equal false, result
|
50
59
|
end
|
51
60
|
|
52
61
|
it "unwraps a boolean true" do
|
53
62
|
gv = GObject::Value.wrap_ruby_value true
|
54
|
-
result = gv.
|
63
|
+
result = gv.get_value
|
55
64
|
assert_equal true, result
|
56
65
|
end
|
57
66
|
|
67
|
+
it "unwraps an int64" do
|
68
|
+
value = 0x1234_5678_9012_3456
|
69
|
+
gv = GObject::Value.for_g_type GObject::TYPE_INT64
|
70
|
+
gv.set_int64 value
|
71
|
+
gv.get_value.must_equal value
|
72
|
+
end
|
73
|
+
|
58
74
|
it "works with a ByteArray" do
|
59
75
|
ba = GLib::ByteArray.new.append("some bytes")
|
60
|
-
v = GObject::Value.
|
76
|
+
v = GObject::Value.for_g_type GObject.type_from_name("GByteArray")
|
61
77
|
v.set_boxed ba
|
62
78
|
|
63
|
-
result = v.
|
79
|
+
result = v.get_value
|
64
80
|
|
65
81
|
result.to_string.must_equal "some bytes"
|
66
82
|
result.must_be_kind_of GLib::ByteArray
|
@@ -71,14 +87,14 @@ describe GObject::Value do
|
|
71
87
|
it "creates a gint GValue from a Ruby Integer" do
|
72
88
|
gv = GObject::Value.from 21
|
73
89
|
gv.current_gtype_name.must_equal "gint"
|
74
|
-
gv.
|
90
|
+
gv.get_value.must_equal 21
|
75
91
|
end
|
76
92
|
|
77
93
|
it "returns its argument if given a GValue" do
|
78
94
|
gv = GObject::Value.from 21
|
79
95
|
gv2 = GObject::Value.from gv
|
80
96
|
gv2.current_gtype_name.must_equal "gint"
|
81
|
-
gv2.
|
97
|
+
gv2.get_value.must_equal 21
|
82
98
|
end
|
83
99
|
end
|
84
100
|
|
@@ -97,7 +113,7 @@ describe GObject::Value do
|
|
97
113
|
ba = GLib::ByteArray.new.append("some bytes")
|
98
114
|
v = GObject::Value.new.init(GObject.type_from_name("GByteArray"))
|
99
115
|
v.set_value ba
|
100
|
-
v.
|
116
|
+
v.get_value.to_string.must_equal "some bytes"
|
101
117
|
end
|
102
118
|
end
|
103
119
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'introspection_test_helper'
|
2
|
+
|
3
|
+
describe GObjectIntrospection::IEnumInfo do
|
4
|
+
describe "#find_method" do
|
5
|
+
setup do
|
6
|
+
gir = GObjectIntrospection::IRepository.default
|
7
|
+
gir.require 'Regress', nil
|
8
|
+
@info = gir.find_by_name 'Regress', 'TestEnum'
|
9
|
+
end
|
10
|
+
|
11
|
+
should "find a method by name" do
|
12
|
+
result = @info.find_method("param")
|
13
|
+
result.name.must_equal "param"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|