gir_ffi 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/Rakefile +0 -18
- data/TODO.rdoc +1 -1
- data/lib/gir_ffi/arg_helper.rb +165 -35
- data/lib/gir_ffi/builder.rb +4 -3
- data/lib/gir_ffi/class_base.rb +11 -3
- data/lib/gir_ffi/class_builder.rb +49 -35
- data/lib/gir_ffi/function_definition_builder.rb +194 -64
- data/lib/gir_ffi/i_arg_info.rb +3 -0
- data/lib/gir_ffi/i_callback_info.rb +1 -1
- data/lib/gir_ffi/i_interface_info.rb +67 -2
- data/lib/gir_ffi/i_repository.rb +5 -0
- data/lib/gir_ffi/lib.rb +22 -1
- data/lib/gir_ffi/module_builder.rb +1 -0
- data/lib/gir_ffi/overrides/gobject.rb +16 -13
- data/lib/gir_ffi/overrides/gtk.rb +1 -1
- data/tasks/notes.rake +12 -25
- data/tasks/setup.rb +0 -132
- data/tasks/test.rake +4 -12
- data/test/arg_helper_test.rb +25 -7
- data/test/builder_test.rb +36 -21
- data/test/class_base_test.rb +0 -7
- data/test/class_builder_test.rb +6 -0
- data/test/everything_test.rb +427 -1
- data/test/function_definition_builder_test.rb +69 -12
- data/test/gobject_overrides_test.rb +12 -3
- data/test/test_helper.rb +5 -0
- metadata +8 -10
- data/tasks/bones.rake +0 -87
- data/tasks/post_load.rake +0 -25
@@ -2,6 +2,23 @@ module GirFFI
|
|
2
2
|
# Implements the creation of a Ruby function definition out of a GIR
|
3
3
|
# IFunctionInfo.
|
4
4
|
class FunctionDefinitionBuilder
|
5
|
+
ArgData = Struct.new(:arginfo, :inarg, :callarg, :retval, :pre, :post, :postpost,
|
6
|
+
:name, :retname)
|
7
|
+
class ArgData
|
8
|
+
def initialize arginfo=nil
|
9
|
+
super
|
10
|
+
self.arginfo = arginfo
|
11
|
+
self.inarg = nil
|
12
|
+
self.callarg = nil
|
13
|
+
self.retval = nil
|
14
|
+
self.retname = nil
|
15
|
+
self.name = nil
|
16
|
+
self.pre = []
|
17
|
+
self.post = []
|
18
|
+
self.postpost = []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
5
22
|
KEYWORDS = [
|
6
23
|
"alias", "and", "begin", "break", "case", "class", "def", "do",
|
7
24
|
"else", "elsif", "end", "ensure", "false", "for", "if", "in",
|
@@ -17,8 +34,10 @@ module GirFFI
|
|
17
34
|
|
18
35
|
def generate
|
19
36
|
setup_accumulators
|
37
|
+
@data = @info.args.map {|a| ArgData.new a}
|
38
|
+
@data.each {|data| prepare_arg data }
|
39
|
+
@data.each {|data| process_arg data }
|
20
40
|
process_return_value
|
21
|
-
@info.args.each {|a| process_arg a}
|
22
41
|
adjust_accumulators
|
23
42
|
return filled_out_template
|
24
43
|
end
|
@@ -33,126 +52,236 @@ module GirFFI
|
|
33
52
|
@pre = []
|
34
53
|
@post = []
|
35
54
|
|
55
|
+
@data = []
|
56
|
+
|
36
57
|
@capture = ""
|
37
58
|
|
38
59
|
@varno = 0
|
39
60
|
end
|
40
61
|
|
41
|
-
def
|
62
|
+
def prepare_arg data
|
63
|
+
arg = data.arginfo
|
64
|
+
data.name = safe arg.name
|
65
|
+
data.callarg = new_var
|
66
|
+
|
67
|
+
case arg.direction
|
68
|
+
when :inout
|
69
|
+
data.inarg = data.name
|
70
|
+
data.retname = data.retval = new_var
|
71
|
+
when :in
|
72
|
+
data.inarg = data.name
|
73
|
+
when :out
|
74
|
+
data.retname = data.retval = new_var
|
75
|
+
else
|
76
|
+
raise ArgumentError
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def process_arg data
|
81
|
+
arg = data.arginfo
|
42
82
|
case arg.direction
|
43
83
|
when :inout
|
44
|
-
process_inout_arg
|
84
|
+
process_inout_arg data
|
45
85
|
when :in
|
46
|
-
process_in_arg
|
86
|
+
process_in_arg data
|
47
87
|
when :out
|
48
|
-
process_out_arg
|
88
|
+
process_out_arg data
|
49
89
|
else
|
50
90
|
raise ArgumentError
|
51
91
|
end
|
52
92
|
end
|
53
93
|
|
54
|
-
def process_inout_arg
|
94
|
+
def process_inout_arg data
|
95
|
+
arg = data.arginfo
|
96
|
+
|
55
97
|
raise NotImplementedError unless arg.ownership_transfer == :everything
|
56
98
|
|
57
|
-
|
58
|
-
prevar = new_var
|
59
|
-
postvar = new_var
|
99
|
+
tag = arg.type.tag
|
60
100
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
@pre << "#{prevar} = GirFFI::ArgHelper.int_to_inoutptr #{name}"
|
65
|
-
@post << "#{postvar} = GirFFI::ArgHelper.outptr_to_int #{prevar}"
|
101
|
+
case tag
|
102
|
+
when :interface
|
103
|
+
raise NotImplementedError
|
66
104
|
when :array
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
105
|
+
tag = arg.type.param_type(0).tag
|
106
|
+
data.pre << "#{data.callarg} = GirFFI::ArgHelper.#{tag}_array_to_inoutptr #{data.inarg}"
|
107
|
+
if arg.type.array_length > -1
|
108
|
+
idx = arg.type.array_length
|
109
|
+
lendata = @data[idx]
|
110
|
+
rv = lendata.retval
|
111
|
+
lendata.retval = nil
|
112
|
+
lname = lendata.inarg
|
113
|
+
lendata.inarg = nil
|
114
|
+
lendata.pre.unshift "#{lname} = #{data.inarg}.length"
|
115
|
+
data.post << "#{data.retval} = GirFFI::ArgHelper.outptr_to_#{tag}_array #{data.callarg}, #{rv}"
|
116
|
+
if tag == :utf8
|
117
|
+
data.post << "GirFFI::ArgHelper.cleanup_ptr_array_ptr #{data.callarg}, #{rv}"
|
118
|
+
else
|
119
|
+
data.post << "GirFFI::ArgHelper.cleanup_ptr_ptr #{data.callarg}"
|
120
|
+
end
|
71
121
|
else
|
72
122
|
raise NotImplementedError
|
73
123
|
end
|
74
124
|
else
|
75
|
-
|
125
|
+
data.pre << "#{data.callarg} = GirFFI::ArgHelper.#{tag}_to_inoutptr #{data.inarg}"
|
126
|
+
data.post << "#{data.retval} = GirFFI::ArgHelper.outptr_to_#{tag} #{data.callarg}"
|
127
|
+
data.post << "GirFFI::ArgHelper.cleanup_ptr #{data.callarg}"
|
76
128
|
end
|
77
|
-
|
78
|
-
|
129
|
+
|
130
|
+
data
|
79
131
|
end
|
80
132
|
|
81
|
-
def process_out_arg
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
@pre << "#{prevar} = GirFFI::ArgHelper.int_to_inoutptr 0"
|
88
|
-
@post << "#{postvar} = GirFFI::ArgHelper.outptr_to_int #{prevar}"
|
89
|
-
when :double
|
90
|
-
@pre << "#{prevar} = GirFFI::ArgHelper.double_to_inoutptr 0"
|
91
|
-
@post << "#{postvar} = GirFFI::ArgHelper.outptr_to_double #{prevar}"
|
133
|
+
def process_out_arg data
|
134
|
+
arg = data.arginfo
|
135
|
+
type = arg.type
|
136
|
+
tag = type.tag
|
137
|
+
|
138
|
+
case tag
|
92
139
|
when :interface
|
93
140
|
iface = arg.type.interface
|
94
|
-
if
|
95
|
-
|
96
|
-
|
141
|
+
if arg.caller_allocates?
|
142
|
+
data.pre << "#{data.callarg} = #{iface.namespace}::#{iface.name}.allocate"
|
143
|
+
data.post << "#{data.retval} = #{data.callarg}"
|
97
144
|
else
|
98
|
-
|
99
|
-
|
145
|
+
data.pre << "#{data.callarg} = GirFFI::ArgHelper.pointer_outptr"
|
146
|
+
tmpvar = new_var
|
147
|
+
data.post << "#{tmpvar} = GirFFI::ArgHelper.outptr_to_pointer #{data.callarg}"
|
148
|
+
data.post << "#{data.retval} = #{iface.namespace}::#{iface.name}.wrap #{tmpvar}"
|
149
|
+
end
|
150
|
+
when :array
|
151
|
+
data.pre << "#{data.callarg} = GirFFI::ArgHelper.pointer_outptr"
|
152
|
+
|
153
|
+
tag = arg.type.param_type(0).tag
|
154
|
+
size = type.array_fixed_size
|
155
|
+
idx = type.array_length
|
156
|
+
|
157
|
+
if size <= 0
|
158
|
+
if idx > -1
|
159
|
+
size = @data[idx].retval
|
160
|
+
@data[idx].retval = nil
|
161
|
+
else
|
162
|
+
raise NotImplementedError
|
163
|
+
end
|
164
|
+
end
|
165
|
+
data.postpost << "#{data.retval} = GirFFI::ArgHelper.outptr_to_#{tag}_array #{data.callarg}, #{size}"
|
166
|
+
if arg.ownership_transfer == :everything
|
167
|
+
if tag == :utf8
|
168
|
+
data.postpost << "GirFFI::ArgHelper.cleanup_ptr_array_ptr #{data.callarg}, #{rv}"
|
169
|
+
else
|
170
|
+
data.postpost << "GirFFI::ArgHelper.cleanup_ptr_ptr #{data.callarg}"
|
171
|
+
end
|
100
172
|
end
|
101
173
|
else
|
102
|
-
|
103
|
-
|
174
|
+
data.pre << "#{data.callarg} = GirFFI::ArgHelper.#{tag}_outptr"
|
175
|
+
data.post << "#{data.retname} = GirFFI::ArgHelper.outptr_to_#{tag} #{data.callarg}"
|
176
|
+
if arg.ownership_transfer == :everything
|
177
|
+
data.post << "GirFFI::ArgHelper.cleanup_ptr #{data.callarg}"
|
178
|
+
end
|
104
179
|
end
|
105
|
-
|
106
|
-
|
180
|
+
|
181
|
+
data
|
107
182
|
end
|
108
183
|
|
109
|
-
def process_in_arg
|
110
|
-
|
184
|
+
def process_in_arg data
|
185
|
+
arg = data.arginfo
|
186
|
+
|
111
187
|
type = arg.type
|
112
188
|
tag = type.tag
|
113
189
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
190
|
+
case tag
|
191
|
+
when :interface
|
192
|
+
if type.interface.type == :callback
|
193
|
+
data.pre << "#{data.callarg} = GirFFI::ArgHelper.mapped_callback_args #{data.inarg}"
|
194
|
+
data.pre << "::#{@libmodule}::CALLBACKS << #{data.callarg}"
|
195
|
+
else
|
196
|
+
data.pre << "#{data.callarg} = #{data.inarg}"
|
197
|
+
end
|
198
|
+
when :void
|
123
199
|
raise NotImplementedError unless arg.type.pointer?
|
124
|
-
|
125
|
-
|
126
|
-
|
200
|
+
data.pre << "#{data.callarg} = GirFFI::ArgHelper.object_to_inptr #{data.inarg}"
|
201
|
+
when :array
|
202
|
+
if type.array_fixed_size > 0
|
203
|
+
data.pre << "GirFFI::ArgHelper.check_fixed_array_size #{type.array_fixed_size}, #{data.inarg}, \"#{data.inarg}\""
|
204
|
+
elsif type.array_length > -1
|
205
|
+
idx = type.array_length
|
206
|
+
lenvar = @data[idx].inarg
|
207
|
+
@data[idx].inarg = nil
|
208
|
+
@data[idx].pre.unshift "#{lenvar} = #{data.inarg}.nil? ? 0 : #{data.inarg}.length"
|
209
|
+
end
|
210
|
+
|
211
|
+
tag = arg.type.param_type(0).tag
|
212
|
+
data.pre << "#{data.callarg} = GirFFI::ArgHelper.#{tag}_array_to_inptr #{data.inarg}"
|
213
|
+
unless arg.ownership_transfer == :everything
|
214
|
+
if tag == :utf8
|
215
|
+
data.post << "GirFFI::ArgHelper.cleanup_ptr_ptr #{data.callarg}"
|
216
|
+
else
|
217
|
+
data.post << "GirFFI::ArgHelper.cleanup_ptr #{data.callarg}"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
when :utf8
|
221
|
+
data.pre << "#{data.callarg} = GirFFI::ArgHelper.utf8_to_inptr #{data.name}"
|
222
|
+
# TODO:
|
223
|
+
#data.post << "GirFFI::ArgHelper.cleanup_ptr #{data.callarg}"
|
127
224
|
else
|
128
|
-
|
225
|
+
data.pre << "#{data.callarg} = #{data.name}"
|
129
226
|
end
|
227
|
+
|
228
|
+
data
|
130
229
|
end
|
131
230
|
|
132
231
|
def process_return_value
|
232
|
+
@rvdata = ArgData.new
|
133
233
|
type = @info.return_type
|
134
234
|
tag = type.tag
|
135
235
|
return if tag == :void
|
136
236
|
cvar = new_var
|
137
237
|
@capture = "#{cvar} = "
|
138
238
|
|
139
|
-
|
239
|
+
case tag
|
240
|
+
when :interface
|
140
241
|
interface = type.interface
|
141
242
|
namespace = interface.namespace
|
142
243
|
name = interface.name
|
143
244
|
GirFFI::Builder.build_class namespace, name
|
144
245
|
retval = new_var
|
145
|
-
@post << "#{retval} = ::#{namespace}::#{name}.
|
246
|
+
@rvdata.post << "#{retval} = ::#{namespace}::#{name}.wrap(#{cvar})"
|
146
247
|
if interface.type == :object
|
147
|
-
@post << "GirFFI::ArgHelper.sink_if_floating(#{retval})"
|
248
|
+
@rvdata.post << "GirFFI::ArgHelper.sink_if_floating(#{retval})"
|
148
249
|
end
|
149
|
-
@
|
250
|
+
@rvdata.retval = retval
|
251
|
+
when :array
|
252
|
+
tag = type.param_type(0).tag
|
253
|
+
size = type.array_fixed_size
|
254
|
+
idx = type.array_length
|
255
|
+
|
256
|
+
retval = new_var
|
257
|
+
if size > 0
|
258
|
+
@rvdata.post << "#{retval} = GirFFI::ArgHelper.ptr_to_#{tag}_array #{cvar}, #{size}"
|
259
|
+
elsif idx > -1
|
260
|
+
lendata = @data[idx]
|
261
|
+
rv = lendata.retval
|
262
|
+
lendata.retval = nil
|
263
|
+
@rvdata.post << "#{retval} = GirFFI::ArgHelper.ptr_to_#{tag}_array #{cvar}, #{rv}"
|
264
|
+
end
|
265
|
+
@rvdata.retval = retval
|
150
266
|
else
|
151
|
-
@
|
267
|
+
@rvdata.retval = cvar
|
152
268
|
end
|
153
269
|
end
|
154
270
|
|
155
271
|
def adjust_accumulators
|
272
|
+
@retvals << @rvdata.retval
|
273
|
+
@data.each do |data|
|
274
|
+
@inargs << data.inarg
|
275
|
+
@callargs << data.callarg
|
276
|
+
@retvals << data.retval
|
277
|
+
@pre += data.pre
|
278
|
+
@post += data.post
|
279
|
+
end
|
280
|
+
@data.each do |data|
|
281
|
+
@post += data.postpost
|
282
|
+
end
|
283
|
+
@post += @rvdata.post
|
284
|
+
|
156
285
|
if @info.throws?
|
157
286
|
errvar = new_var
|
158
287
|
@pre << "#{errvar} = FFI::MemoryPointer.new(:pointer).write_pointer nil"
|
@@ -160,7 +289,8 @@ module GirFFI
|
|
160
289
|
@callargs << errvar
|
161
290
|
end
|
162
291
|
|
163
|
-
@
|
292
|
+
@retvals = @retvals.compact
|
293
|
+
@post << "return #{@retvals.compact.join(', ')}" unless @retvals.empty?
|
164
294
|
|
165
295
|
if @info.method?
|
166
296
|
@callargs.unshift "self"
|
@@ -169,9 +299,9 @@ module GirFFI
|
|
169
299
|
|
170
300
|
def filled_out_template
|
171
301
|
return <<-CODE
|
172
|
-
def #{@info.name} #{@inargs.join(', ')}
|
302
|
+
def #{@info.name} #{@inargs.compact.join(', ')}
|
173
303
|
#{@pre.join("\n")}
|
174
|
-
#{@capture}::#{@libmodule}.#{@info.symbol} #{@callargs.join(', ')}
|
304
|
+
#{@capture}::#{@libmodule}.#{@info.symbol} #{@callargs.compact.join(', ')}
|
175
305
|
#{@post.join("\n")}
|
176
306
|
end
|
177
307
|
CODE
|
data/lib/gir_ffi/i_arg_info.rb
CHANGED
@@ -1,7 +1,72 @@
|
|
1
1
|
module GirFFI
|
2
|
-
# Wraps a
|
2
|
+
# Wraps a IInterfaceInfo struct.
|
3
3
|
# Represents an interface.
|
4
|
-
# Not implemented yet.
|
5
4
|
class IInterfaceInfo < IRegisteredTypeInfo
|
5
|
+
def n_prerequisites
|
6
|
+
Lib.g_interface_info_get_n_prerequisites @gobj
|
7
|
+
end
|
8
|
+
def prerequisite index
|
9
|
+
IBaseInfo.wrap(Lib.g_interface_info_get_prerequisite @gobj, index)
|
10
|
+
end
|
11
|
+
##
|
12
|
+
build_array_method :prerequisites
|
13
|
+
|
14
|
+
def n_properties
|
15
|
+
Lib.g_interface_info_get_n_properties @gobj
|
16
|
+
end
|
17
|
+
def property index
|
18
|
+
IPropertyInfo.wrap(Lib.g_interface_info_get_property @gobj, index)
|
19
|
+
end
|
20
|
+
##
|
21
|
+
build_array_method :properties, :property
|
22
|
+
|
23
|
+
def n_methods
|
24
|
+
Lib.g_interface_info_get_n_methods @gobj
|
25
|
+
end
|
26
|
+
def method index
|
27
|
+
IFunctionInfo.wrap(Lib.g_interface_info_get_method @gobj, index)
|
28
|
+
end
|
29
|
+
##
|
30
|
+
build_array_method :methods
|
31
|
+
|
32
|
+
def find_method name
|
33
|
+
IFunctionInfo.wrap(Lib.g_interface_info_find_method @gobj, name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def n_signals
|
37
|
+
Lib.g_interface_info_get_n_signals @gobj
|
38
|
+
end
|
39
|
+
def signal index
|
40
|
+
ISignalInfo.wrap(Lib.g_interface_info_get_signal @gobj, index)
|
41
|
+
end
|
42
|
+
##
|
43
|
+
build_array_method :signals
|
44
|
+
|
45
|
+
def n_vfuncs
|
46
|
+
Lib.g_interface_info_get_n_vfuncs @gobj
|
47
|
+
end
|
48
|
+
def vfunc index
|
49
|
+
IVFuncInfo.wrap(Lib.g_interface_info_get_vfunc @gobj, index)
|
50
|
+
end
|
51
|
+
##
|
52
|
+
build_array_method :vfuncs
|
53
|
+
|
54
|
+
def find_vfunc name
|
55
|
+
IVFuncInfo.wrap(Lib.g_interface_info_find_vfunc @gobj, name)
|
56
|
+
end
|
57
|
+
|
58
|
+
def n_constants
|
59
|
+
Lib.g_interface_info_get_n_constants @gobj
|
60
|
+
end
|
61
|
+
def constant index
|
62
|
+
IConstantInfo.wrap(Lib.g_interface_info_get_constant @gobj, index)
|
63
|
+
end
|
64
|
+
##
|
65
|
+
build_array_method :constants
|
66
|
+
|
67
|
+
def iface_struct
|
68
|
+
IStructInfo.wrap(Lib.g_interface_info_get_iface_struct @gobj)
|
69
|
+
end
|
70
|
+
|
6
71
|
end
|
7
72
|
end
|
data/lib/gir_ffi/i_repository.rb
CHANGED
@@ -96,6 +96,11 @@ module GirFFI
|
|
96
96
|
return wrap ptr
|
97
97
|
end
|
98
98
|
|
99
|
+
def find_by_gtype gtype
|
100
|
+
ptr = Lib.g_irepository_find_by_gtype @gobj, gtype
|
101
|
+
return wrap ptr
|
102
|
+
end
|
103
|
+
|
99
104
|
def shared_library namespace
|
100
105
|
Lib.g_irepository_get_shared_library @gobj, namespace
|
101
106
|
end
|
data/lib/gir_ffi/lib.rb
CHANGED
@@ -17,6 +17,8 @@ module GirFFI
|
|
17
17
|
[:pointer, :string, :int], :pointer
|
18
18
|
attach_function :g_irepository_find_by_name,
|
19
19
|
[:pointer, :string, :string], :pointer
|
20
|
+
attach_function :g_irepository_find_by_gtype, [:pointer, :size_t], :pointer
|
21
|
+
|
20
22
|
attach_function :g_irepository_get_shared_library,
|
21
23
|
[:pointer, :string], :string
|
22
24
|
|
@@ -85,6 +87,7 @@ module GirFFI
|
|
85
87
|
attach_function :g_arg_info_get_direction, [:pointer], :IDirection
|
86
88
|
attach_function :g_arg_info_is_return_value, [:pointer], :bool
|
87
89
|
attach_function :g_arg_info_is_optional, [:pointer], :bool
|
90
|
+
attach_function :g_arg_info_is_caller_allocates, [:pointer], :bool
|
88
91
|
attach_function :g_arg_info_may_be_null, [:pointer], :bool
|
89
92
|
attach_function :g_arg_info_get_ownership_transfer, [:pointer], :ITransfer
|
90
93
|
attach_function :g_arg_info_get_scope, [:pointer], :IScopeType
|
@@ -150,7 +153,7 @@ module GirFFI
|
|
150
153
|
# IRegisteredTypeInfo
|
151
154
|
attach_function :g_registered_type_info_get_type_name, [:pointer], :string
|
152
155
|
attach_function :g_registered_type_info_get_type_init, [:pointer], :string
|
153
|
-
attach_function :g_registered_type_info_get_g_type, [:pointer], :
|
156
|
+
attach_function :g_registered_type_info_get_g_type, [:pointer], :size_t
|
154
157
|
|
155
158
|
# IEnumInfo
|
156
159
|
attach_function :g_enum_info_get_storage_type, [:pointer], :ITypeTag
|
@@ -192,5 +195,23 @@ module GirFFI
|
|
192
195
|
attach_function :g_vfunc_info_get_offset, [:pointer], :int
|
193
196
|
attach_function :g_vfunc_info_get_signal, [:pointer], :pointer
|
194
197
|
attach_function :g_vfunc_info_get_invoker, [:pointer], :pointer
|
198
|
+
|
199
|
+
# IInterfaceInfo
|
200
|
+
attach_function :g_interface_info_get_n_prerequisites, [:pointer], :int
|
201
|
+
attach_function :g_interface_info_get_prerequisite, [:pointer, :int], :pointer
|
202
|
+
attach_function :g_interface_info_get_n_properties, [:pointer], :int
|
203
|
+
attach_function :g_interface_info_get_property, [:pointer, :int], :pointer
|
204
|
+
attach_function :g_interface_info_get_n_methods, [:pointer], :int
|
205
|
+
attach_function :g_interface_info_get_method, [:pointer, :int], :pointer
|
206
|
+
attach_function :g_interface_info_find_method, [:pointer, :string], :pointer
|
207
|
+
attach_function :g_interface_info_get_n_signals, [:pointer], :int
|
208
|
+
attach_function :g_interface_info_get_signal, [:pointer, :int], :pointer
|
209
|
+
attach_function :g_interface_info_get_n_vfuncs, [:pointer], :int
|
210
|
+
attach_function :g_interface_info_get_vfunc, [:pointer, :int], :pointer
|
211
|
+
attach_function :g_interface_info_find_vfunc, [:pointer, :string], :pointer
|
212
|
+
attach_function :g_interface_info_get_n_constants, [:pointer], :int
|
213
|
+
attach_function :g_interface_info_get_constant, [:pointer, :int], :pointer
|
214
|
+
attach_function :g_interface_info_get_iface_struct, [:pointer], :pointer
|
215
|
+
|
195
216
|
end
|
196
217
|
end
|
@@ -7,9 +7,10 @@ module GirFFI
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
+
# FIXME: These four helper methods belong elsewhere.
|
10
11
|
def type_from_instance_pointer inst_ptr
|
11
|
-
base = ::GObject::TypeInstance.
|
12
|
-
kls = ::GObject::TypeClass.
|
12
|
+
base = ::GObject::TypeInstance.wrap inst_ptr
|
13
|
+
kls = ::GObject::TypeClass.wrap(base[:g_class])
|
13
14
|
kls[:g_type]
|
14
15
|
end
|
15
16
|
|
@@ -38,14 +39,6 @@ module GirFFI
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
# FIXME: This is a private helper function. Move elsewhere?
|
42
|
-
def signal_callback_args sig, klass, &block
|
43
|
-
return Proc.new do |*args|
|
44
|
-
mapped = Helper.cast_back_signal_arguments sig, klass, *args
|
45
|
-
block.call(*mapped)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
42
|
def signal_emit object, signal, *args
|
50
43
|
type = type_from_instance object
|
51
44
|
|
@@ -80,19 +73,29 @@ module GirFFI
|
|
80
73
|
if sig.nil?
|
81
74
|
raise "Signal #{signal} is invalid for #{object}"
|
82
75
|
end
|
76
|
+
if block.nil?
|
77
|
+
raise ArgumentError, "Block needed"
|
78
|
+
end
|
83
79
|
|
84
80
|
rettype = GirFFI::Builder.itypeinfo_to_ffitype sig.return_type
|
85
81
|
|
86
82
|
argtypes = [:pointer] + sig.args.map {|a| :pointer} + [:pointer]
|
87
83
|
|
88
84
|
callback = FFI::Function.new rettype, argtypes,
|
89
|
-
&(signal_callback_args(sig, object.class, &block))
|
85
|
+
&(Helper.signal_callback_args(sig, object.class, &block))
|
90
86
|
|
91
87
|
signal_connect_data object, signal, callback, data, nil, 0
|
92
88
|
end
|
93
89
|
end
|
94
90
|
|
95
91
|
module Helper
|
92
|
+
def self.signal_callback_args sig, klass, &block
|
93
|
+
return Proc.new do |*args|
|
94
|
+
mapped = cast_back_signal_arguments sig, klass, *args
|
95
|
+
block.call(*mapped)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
96
99
|
def self.signal_arguments_to_gvalue_array signal, instance, *rest
|
97
100
|
sig = instance.class.gir_ffi_builder.find_signal signal
|
98
101
|
|
@@ -137,7 +140,7 @@ module GirFFI
|
|
137
140
|
|
138
141
|
# Instance
|
139
142
|
instptr = args.shift
|
140
|
-
instance = klass.
|
143
|
+
instance = klass.wrap instptr
|
141
144
|
result << instance
|
142
145
|
|
143
146
|
# Extra arguments
|
@@ -146,7 +149,7 @@ module GirFFI
|
|
146
149
|
if info.type.tag == :interface
|
147
150
|
iface = info.type.interface
|
148
151
|
kls = GirFFI::Builder.build_class(iface.namespace, iface.name)
|
149
|
-
result << kls.
|
152
|
+
result << kls.wrap(arg)
|
150
153
|
else
|
151
154
|
result << arg
|
152
155
|
end
|