gir_ffi 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +80 -73
- data/Gemfile +2 -0
- data/README.md +2 -2
- data/lib/ffi-glib/array.rb +6 -6
- data/lib/ffi-glib/bytes.rb +5 -5
- data/lib/ffi-glib/container_class_methods.rb +6 -6
- data/lib/ffi-glib/error.rb +4 -4
- data/lib/ffi-glib/main_loop.rb +8 -8
- data/lib/ffi-glib/ptr_array.rb +2 -2
- data/lib/ffi-glib/strv.rb +5 -5
- data/lib/ffi-glib/variant.rb +3 -3
- data/lib/ffi-gobject.rb +1 -0
- data/lib/ffi-gobject/closure.rb +2 -2
- data/lib/ffi-gobject/object.rb +37 -15
- data/lib/ffi-gobject/value.rb +5 -5
- data/lib/ffi-gobject_introspection/i_registered_type_info.rb +1 -1
- data/lib/gir_ffi/builders/argument_builder.rb +1 -3
- data/lib/gir_ffi/builders/argument_builder_collection.rb +6 -6
- data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +1 -5
- data/lib/gir_ffi/builders/callback_argument_builder.rb +2 -6
- data/lib/gir_ffi/builders/module_builder.rb +1 -3
- data/lib/gir_ffi/builders/null_class_builder.rb +2 -2
- data/lib/gir_ffi/builders/user_defined_builder.rb +7 -17
- data/lib/gir_ffi/builders/with_layout.rb +1 -1
- data/lib/gir_ffi/class_base.rb +4 -8
- data/lib/gir_ffi/enum_like_base.rb +2 -4
- data/lib/gir_ffi/instance_method_setup.rb +14 -0
- data/lib/gir_ffi/interface_base.rb +4 -8
- data/lib/gir_ffi/method_setup.rb +14 -0
- data/lib/gir_ffi/module_base.rb +4 -4
- data/lib/gir_ffi/object_base.rb +2 -2
- data/lib/gir_ffi/sized_array.rb +4 -3
- data/lib/gir_ffi/version.rb +1 -1
- data/tasks/test.rake +60 -60
- data/test/gir_ffi/builder_test.rb +1 -1
- data/test/integration/generated_regress_test.rb +1 -1
- metadata +5 -3
data/lib/ffi-glib/bytes.rb
CHANGED
@@ -22,18 +22,18 @@ module GLib
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def from(typespec = :void,
|
26
|
-
case
|
25
|
+
def from(typespec = :void, obj)
|
26
|
+
case obj
|
27
27
|
when nil
|
28
28
|
nil
|
29
29
|
when FFI::Pointer
|
30
|
-
wrap typespec,
|
30
|
+
wrap typespec, obj
|
31
31
|
when self
|
32
|
-
|
32
|
+
obj.reset_typespec typespec
|
33
33
|
when GirFFI::BoxedBase
|
34
|
-
wrap typespec,
|
34
|
+
wrap typespec, obj.to_ptr
|
35
35
|
else
|
36
|
-
from_enumerable typespec,
|
36
|
+
from_enumerable typespec, obj
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/lib/ffi-glib/error.rb
CHANGED
@@ -7,12 +7,12 @@ module GLib
|
|
7
7
|
class Error
|
8
8
|
GIR_FFI_DOMAIN = GLib.quark_from_string('gir_ffi')
|
9
9
|
|
10
|
-
def self.from_exception(
|
11
|
-
new_literal GIR_FFI_DOMAIN, 0,
|
10
|
+
def self.from_exception(exception)
|
11
|
+
new_literal GIR_FFI_DOMAIN, 0, exception.message
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.from(
|
15
|
-
from_exception
|
14
|
+
def self.from(obj)
|
15
|
+
from_exception obj
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/ffi-glib/main_loop.rb
CHANGED
@@ -37,27 +37,27 @@ module GLib
|
|
37
37
|
EXCEPTIONS = []
|
38
38
|
RUNNING_LOOPS = []
|
39
39
|
|
40
|
-
setup_instance_method :run
|
40
|
+
setup_instance_method! :run
|
41
41
|
|
42
42
|
def run_with_thread_enabler
|
43
43
|
ThreadEnabler.instance.setup_idle_handler if RUBY_ENGINE == 'ruby'
|
44
44
|
RUNNING_LOOPS << self
|
45
45
|
result = run_without_thread_enabler
|
46
|
-
|
46
|
+
exception = EXCEPTIONS.shift
|
47
47
|
RUNNING_LOOPS.pop
|
48
|
-
raise
|
48
|
+
raise exception if exception
|
49
49
|
result
|
50
50
|
end
|
51
51
|
|
52
|
-
def self.handle_exception(
|
52
|
+
def self.handle_exception(exception)
|
53
53
|
current_loop = RUNNING_LOOPS.last
|
54
|
-
raise
|
55
|
-
EXCEPTIONS <<
|
54
|
+
raise exception unless current_loop
|
55
|
+
EXCEPTIONS << exception
|
56
56
|
current_loop.quit
|
57
57
|
end
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
alias run_without_thread_enabler run
|
60
|
+
alias run run_with_thread_enabler
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
data/lib/ffi-glib/ptr_array.rb
CHANGED
@@ -27,8 +27,8 @@ module GLib
|
|
27
27
|
store_pointer Lib.g_ptr_array_new
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.from_enumerable(type,
|
31
|
-
new(type).tap { |
|
30
|
+
def self.from_enumerable(type, arr)
|
31
|
+
new(type).tap { |it| it.add_array arr }
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.add(array, data)
|
data/lib/ffi-glib/strv.rb
CHANGED
@@ -10,16 +10,16 @@ module GLib
|
|
10
10
|
to_a == other.to_a
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.from(
|
14
|
-
case
|
13
|
+
def self.from(obj)
|
14
|
+
case obj
|
15
15
|
when nil
|
16
16
|
nil
|
17
17
|
when FFI::Pointer
|
18
|
-
wrap
|
18
|
+
wrap obj
|
19
19
|
when self
|
20
|
-
|
20
|
+
obj
|
21
21
|
else
|
22
|
-
from_enumerable
|
22
|
+
from_enumerable obj
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
data/lib/ffi-glib/variant.rb
CHANGED
@@ -5,14 +5,14 @@ GLib.load_class :Variant
|
|
5
5
|
module GLib
|
6
6
|
# Overrides for GVariant, GLib's variant data type.
|
7
7
|
class Variant
|
8
|
-
setup_instance_method 'get_string'
|
8
|
+
setup_instance_method! 'get_string'
|
9
9
|
|
10
10
|
def get_string_with_override
|
11
11
|
get_string_without_override.first
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
alias get_string_without_override get_string
|
15
|
+
alias get_string get_string_with_override
|
16
16
|
|
17
17
|
# Initializing method used in constructors. For Variant, this needs to sink
|
18
18
|
# the variant's floating reference.
|
data/lib/ffi-gobject.rb
CHANGED
@@ -87,6 +87,7 @@ module GObject
|
|
87
87
|
attach_function :g_object_ref_sink, [:pointer], :pointer
|
88
88
|
attach_function :g_object_ref, [:pointer], :pointer
|
89
89
|
attach_function :g_object_unref, [:pointer], :pointer
|
90
|
+
attach_function :g_object_new, [:size_t, :pointer], :pointer
|
90
91
|
|
91
92
|
attach_function :g_value_copy, [:pointer, :pointer], :void
|
92
93
|
attach_function :g_value_init, [:pointer, :size_t], :pointer
|
data/lib/ffi-gobject/closure.rb
CHANGED
data/lib/ffi-gobject/object.rb
CHANGED
@@ -7,11 +7,20 @@ GObject.load_class :Object
|
|
7
7
|
module GObject
|
8
8
|
# Overrides for GObject, GObject's generic base class.
|
9
9
|
class Object
|
10
|
-
setup_method 'new'
|
11
10
|
if !GLib.check_version(2, 54, 0)
|
12
|
-
|
11
|
+
GObject::Lib.attach_function(:g_object_new_with_properties,
|
12
|
+
[:size_t, :uint32, :pointer, :pointer],
|
13
|
+
:pointer)
|
14
|
+
|
15
|
+
def self.new(*args, &block)
|
16
|
+
obj = allocate
|
17
|
+
obj.__send__ :initialize, *args, &block
|
18
|
+
obj
|
19
|
+
end
|
13
20
|
|
14
|
-
|
21
|
+
# Starting with GLib 2.54.0, use g_object_new_with_properties, which
|
22
|
+
# takes an array of names and an array of values.
|
23
|
+
def initialize(properties = {})
|
15
24
|
names = []
|
16
25
|
values = []
|
17
26
|
properties.each do |name, value|
|
@@ -22,9 +31,21 @@ module GObject
|
|
22
31
|
names << name
|
23
32
|
values << gvalue
|
24
33
|
end
|
25
|
-
|
34
|
+
|
35
|
+
n_properties = names.length
|
36
|
+
names_arr = GirFFI::SizedArray.from(:utf8, -1, names)
|
37
|
+
values_arr = GirFFI::SizedArray.from(GObject::Value, -1, values)
|
38
|
+
|
39
|
+
ptr = GObject::Lib.g_object_new_with_properties(self.class.gtype,
|
40
|
+
n_properties,
|
41
|
+
names_arr,
|
42
|
+
values_arr)
|
43
|
+
store_pointer ptr
|
26
44
|
end
|
27
45
|
else
|
46
|
+
setup_method! 'new'
|
47
|
+
|
48
|
+
# Before GLib 2.54.0, use g_object_newv, which takes an array of GParameter.
|
28
49
|
def initialize_with_automatic_gtype(properties = {})
|
29
50
|
gparameters = properties.map do |name, value|
|
30
51
|
name = name.to_s
|
@@ -36,11 +57,12 @@ module GObject
|
|
36
57
|
end
|
37
58
|
initialize_without_automatic_gtype(self.class.gtype, gparameters)
|
38
59
|
end
|
60
|
+
|
61
|
+
alias initialize_without_automatic_gtype initialize
|
62
|
+
alias initialize initialize_with_automatic_gtype
|
39
63
|
end
|
40
64
|
|
41
|
-
|
42
|
-
alias_method :initialize, :initialize_with_automatic_gtype
|
43
|
-
alias_method :base_initialize, :initialize
|
65
|
+
alias base_initialize initialize
|
44
66
|
|
45
67
|
private :base_initialize
|
46
68
|
|
@@ -90,8 +112,8 @@ module GObject
|
|
90
112
|
GObject.signal_connect_after(self, event, data, &block)
|
91
113
|
end
|
92
114
|
|
93
|
-
setup_instance_method 'get_property'
|
94
|
-
setup_instance_method 'set_property'
|
115
|
+
setup_instance_method! 'get_property'
|
116
|
+
setup_instance_method! 'set_property'
|
95
117
|
|
96
118
|
def get_property_extended(property_name)
|
97
119
|
value = get_property(property_name)
|
@@ -117,14 +139,14 @@ module GObject
|
|
117
139
|
set_property_without_override property_name, gvalue
|
118
140
|
end
|
119
141
|
|
120
|
-
|
121
|
-
|
142
|
+
alias get_property_without_override get_property
|
143
|
+
alias get_property get_property_with_override
|
122
144
|
|
123
|
-
|
124
|
-
|
145
|
+
alias set_property_without_override set_property
|
146
|
+
alias set_property set_property_with_override
|
125
147
|
|
126
|
-
setup_instance_method 'is_floating'
|
127
|
-
|
148
|
+
setup_instance_method! 'is_floating'
|
149
|
+
alias floating? is_floating
|
128
150
|
|
129
151
|
private
|
130
152
|
|
data/lib/ffi-gobject/value.rb
CHANGED
@@ -58,7 +58,7 @@ module GObject
|
|
58
58
|
send set_method, val
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
alias value= set_value
|
62
62
|
|
63
63
|
def current_gtype
|
64
64
|
@struct[:g_type]
|
@@ -146,7 +146,7 @@ module GObject
|
|
146
146
|
raise "Can't handle #{val.class}"
|
147
147
|
end
|
148
148
|
|
149
|
-
def set_none(
|
149
|
+
def set_none(_val); end
|
150
150
|
|
151
151
|
def get_none; end
|
152
152
|
|
@@ -169,9 +169,9 @@ module GObject
|
|
169
169
|
end
|
170
170
|
|
171
171
|
def check_type_compatibility(val)
|
172
|
-
|
173
|
-
|
174
|
-
|
172
|
+
return if GObject::Value.type_compatible(GObject.type_from_instance(val), current_gtype)
|
173
|
+
|
174
|
+
raise ArgumentError, "#{val.class} is incompatible with #{current_gtype_name}"
|
175
175
|
end
|
176
176
|
|
177
177
|
def wrap_boxed(boxed)
|
@@ -76,13 +76,13 @@ module GirFFI
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
all_builders.each do |bldr|
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
idx = bldr.array_length_idx
|
80
|
+
next unless idx >= 0
|
81
|
+
other = @base_argument_builders[idx]
|
82
|
+
next unless other
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
end
|
84
|
+
bldr.length_arg = other
|
85
|
+
other.array_arg = bldr
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -37,15 +37,11 @@ module GirFFI
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def call_argument_name
|
40
|
-
if [:in, :inout].include?
|
41
|
-
pre_converted_name unless array_arg
|
42
|
-
end
|
40
|
+
pre_converted_name if [:in, :inout].include?(direction) && !array_arg
|
43
41
|
end
|
44
42
|
|
45
43
|
def capture_variable_name
|
46
|
-
|
47
|
-
result_name if [:out, :inout].include? direction
|
48
|
-
end
|
44
|
+
result_name if [:out, :inout].include?(direction) && !array_arg
|
49
45
|
end
|
50
46
|
|
51
47
|
def pre_conversion
|
@@ -90,9 +90,7 @@ module GirFFI
|
|
90
90
|
lib.extend FFI::Library
|
91
91
|
lib.extend FFI::BitMasks
|
92
92
|
lib.ffi_lib_flags :global, :lazy
|
93
|
-
if shared_library_specification
|
94
|
-
lib.ffi_lib(*shared_library_specification.split(/,/))
|
95
|
-
end
|
93
|
+
lib.ffi_lib(*shared_library_specification.split(/,/)) if shared_library_specification
|
96
94
|
end
|
97
95
|
|
98
96
|
def shared_library_specification
|
@@ -127,7 +127,7 @@ module GirFFI
|
|
127
127
|
superclass.gir_ffi_builder.object_class_struct::Struct.new(object_class_ptr)
|
128
128
|
|
129
129
|
info.vfunc_implementations.each do |impl|
|
130
|
-
setup_vfunc super_class_struct, impl
|
130
|
+
setup_vfunc parent_info, super_class_struct, impl
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -138,26 +138,16 @@ module GirFFI
|
|
138
138
|
interface_info = interface_builder.info
|
139
139
|
|
140
140
|
info.vfunc_implementations.each do |impl|
|
141
|
-
|
141
|
+
setup_vfunc interface_info, interface_struct, impl
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
-
def setup_vfunc(
|
145
|
+
def setup_vfunc(ancestor_info, ancestor_struct, impl)
|
146
146
|
vfunc_name = impl.name
|
147
|
-
vfunc_info =
|
147
|
+
vfunc_info = ancestor_info.find_vfunc vfunc_name.to_s
|
148
|
+
return unless vfunc_info
|
148
149
|
|
149
|
-
|
150
|
-
install_vfunc super_class_struct, vfunc_name, vfunc_info, impl.implementation
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def setup_interface_vfunc(interface_info, interface_struct, impl)
|
155
|
-
vfunc_name = impl.name
|
156
|
-
vfunc_info = interface_info.find_vfunc vfunc_name.to_s
|
157
|
-
|
158
|
-
if vfunc_info
|
159
|
-
install_vfunc interface_struct, vfunc_name, vfunc_info, impl.implementation
|
160
|
-
end
|
150
|
+
install_vfunc ancestor_struct, vfunc_name, vfunc_info, impl.implementation
|
161
151
|
end
|
162
152
|
|
163
153
|
def install_vfunc(container_struct, vfunc_name, vfunc_info, implementation)
|
@@ -265,7 +255,7 @@ module GirFFI
|
|
265
255
|
def setup_constructor
|
266
256
|
code = <<-CODE
|
267
257
|
def initialize
|
268
|
-
ptr = GObject::Lib.
|
258
|
+
ptr = GObject::Lib.g_object_new #{@gtype}, nil
|
269
259
|
store_pointer(ptr)
|
270
260
|
end
|
271
261
|
CODE
|