gir_ffi 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/README.md +1 -1
- data/TODO.rdoc +12 -4
- data/lib/ffi-glib.rb +0 -5
- data/lib/ffi-glib/list.rb +1 -1
- data/lib/ffi-glib/s_list.rb +1 -1
- data/lib/ffi-gobject.rb +2 -3
- data/lib/ffi-gobject/closure.rb +4 -3
- data/lib/ffi-gobject_introspection/i_base_info.rb +11 -14
- data/lib/ffi-gobject_introspection/i_constant_info.rb +1 -1
- data/lib/ffi-gobject_introspection/i_function_info.rb +0 -6
- data/lib/ffi-gobject_introspection/lib.rb +8 -2
- data/lib/gir_ffi.rb +5 -0
- data/lib/gir_ffi/arg_helper.rb +1 -1
- data/lib/gir_ffi/argument_builder.rb +161 -0
- data/lib/gir_ffi/base_argument_builder.rb +146 -0
- data/lib/gir_ffi/builder/field.rb +7 -5
- data/lib/gir_ffi/builder/module.rb +3 -14
- data/lib/gir_ffi/builder/property.rb +0 -2
- data/lib/gir_ffi/builder/type/callback.rb +0 -8
- data/lib/gir_ffi/builder/type/constant.rb +0 -4
- data/lib/gir_ffi/builder/type/enum.rb +0 -4
- data/lib/gir_ffi/builder/type/interface.rb +0 -4
- data/lib/gir_ffi/builder/type/object.rb +0 -1
- data/lib/gir_ffi/builder/type/struct_based.rb +0 -6
- data/lib/gir_ffi/builder/type/union.rb +0 -4
- data/lib/gir_ffi/builder/type/with_layout.rb +0 -1
- data/lib/gir_ffi/builder/type/with_methods.rb +1 -7
- data/lib/gir_ffi/callback.rb +9 -0
- data/lib/gir_ffi/callback_helper.rb +8 -1
- data/lib/gir_ffi/class_base.rb +6 -26
- data/lib/gir_ffi/error_argument_builder.rb +17 -0
- data/lib/gir_ffi/{builder/function.rb → function_builder.rb} +14 -11
- data/lib/gir_ffi/in_out_pointer.rb +29 -36
- data/lib/gir_ffi/in_pointer.rb +1 -1
- data/lib/gir_ffi/info_ext.rb +6 -0
- data/lib/gir_ffi/info_ext/i_field_info.rb +0 -2
- data/lib/gir_ffi/info_ext/i_type_info.rb +29 -10
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +21 -0
- data/lib/gir_ffi/info_ext/safe_function_name.rb +13 -0
- data/lib/gir_ffi/interface_base.rb +1 -11
- data/lib/gir_ffi/module_base.rb +0 -10
- data/lib/gir_ffi/null_argument_builder.rb +9 -0
- data/lib/gir_ffi/return_value_builder.rb +75 -0
- data/lib/gir_ffi/setter_argument_info.rb +16 -0
- data/lib/gir_ffi/type_map.rb +10 -1
- data/lib/gir_ffi/version.rb +1 -1
- data/tasks/test.rake +61 -0
- data/test/base_test_helper.rb +0 -2
- data/test/ffi-gobject/value_test.rb +15 -0
- data/test/ffi-gobject_introspection/i_base_info_test.rb +31 -6
- data/test/ffi-gobject_introspection/i_function_info_test.rb +0 -17
- data/test/ffi-gobject_introspection/lib_test.rb +0 -55
- data/test/ffi-gobject_test.rb +2 -1
- data/test/gir_ffi/argument_builder_test.rb +414 -0
- data/test/gir_ffi/base_argument_builder_test.rb +13 -0
- data/test/gir_ffi/builder/module_test.rb +4 -40
- data/test/gir_ffi/builder/type/callback_test.rb +0 -27
- data/test/gir_ffi/builder/type/constant_test.rb +0 -12
- data/test/gir_ffi/builder/type/enum_test.rb +0 -20
- data/test/gir_ffi/builder/type/interface_test.rb +0 -11
- data/test/gir_ffi/builder/type/object_test.rb +2 -2
- data/test/gir_ffi/builder/type/struct_test.rb +0 -39
- data/test/gir_ffi/builder/type/unintrospectable_test.rb +1 -1
- data/test/gir_ffi/builder/type/union_test.rb +0 -11
- data/test/gir_ffi/builder_test.rb +3 -11
- data/test/gir_ffi/callback_helper_test.rb +7 -0
- data/test/gir_ffi/{builder/function_test.rb → function_builder_test.rb} +16 -28
- data/test/gir_ffi/in_out_pointer_test.rb +0 -20
- data/test/gir_ffi/info_ext/i_type_info_test.rb +112 -26
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +16 -0
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +22 -0
- data/test/gir_ffi/return_value_builder_test.rb +355 -0
- data/test/integration/generated_gimarshallingtests_test.rb +608 -296
- data/test/integration/generated_regress_test.rb +879 -494
- metadata +35 -24
- data/lib/gir_ffi/builder/argument.rb +0 -569
- data/lib/gir_ffi/builder/argument/base.rb +0 -151
- data/lib/gir_ffi/builder/argument/in_base.rb +0 -14
- data/lib/gir_ffi/builder/argument/in_out_base.rb +0 -18
- data/lib/gir_ffi/builder/argument/out_base.rb +0 -15
- data/test/gir_ffi/builder/argument/base_test.rb +0 -55
- data/test/integration/pretty_print_test.rb +0 -33
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
|
+
version: 0.5.0
|
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:
|
12
|
+
date: 2013-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.0
|
21
|
+
version: 1.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.0
|
29
|
+
version: 1.2.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: indentation
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,17 +48,17 @@ dependencies:
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 4.3.3
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 4.3.3
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: rr
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.0.
|
69
|
+
version: 1.0.4
|
70
70
|
type: :development
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 1.0.
|
77
|
+
version: 1.0.4
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: rake
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
requirements:
|
83
83
|
- - ~>
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.
|
85
|
+
version: 10.0.3
|
86
86
|
type: :development
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
requirements:
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: 0.
|
93
|
+
version: 10.0.3
|
94
94
|
description:
|
95
95
|
email:
|
96
96
|
- matijs@matijs.net
|
@@ -106,7 +106,6 @@ files:
|
|
106
106
|
- lib/ffi-gobject_introspection.rb
|
107
107
|
- lib/gir_ffi.rb
|
108
108
|
- lib/gir_ffi/lib_c.rb
|
109
|
-
- lib/gir_ffi/builder/function.rb
|
110
109
|
- lib/gir_ffi/builder/type/constant.rb
|
111
110
|
- lib/gir_ffi/builder/type/union.rb
|
112
111
|
- lib/gir_ffi/builder/type/base.rb
|
@@ -125,35 +124,41 @@ files:
|
|
125
124
|
- lib/gir_ffi/builder/type.rb
|
126
125
|
- lib/gir_ffi/builder/module.rb
|
127
126
|
- lib/gir_ffi/builder/property.rb
|
128
|
-
- lib/gir_ffi/builder/argument.rb
|
129
|
-
- lib/gir_ffi/builder/argument/base.rb
|
130
|
-
- lib/gir_ffi/builder/argument/out_base.rb
|
131
|
-
- lib/gir_ffi/builder/argument/in_out_base.rb
|
132
|
-
- lib/gir_ffi/builder/argument/in_base.rb
|
133
127
|
- lib/gir_ffi/method_stubber.rb
|
134
128
|
- lib/gir_ffi/arg_helper.rb
|
129
|
+
- lib/gir_ffi/info_ext.rb
|
135
130
|
- lib/gir_ffi/allocation_helper.rb
|
136
131
|
- lib/gir_ffi/type_map.rb
|
137
132
|
- lib/gir_ffi/user_defined/i_property_info.rb
|
138
133
|
- lib/gir_ffi/user_defined/i_base_info.rb
|
139
134
|
- lib/gir_ffi/user_defined/i_object_info.rb
|
140
135
|
- lib/gir_ffi/user_defined/i_registered_type_info.rb
|
136
|
+
- lib/gir_ffi/callback.rb
|
137
|
+
- lib/gir_ffi/argument_builder.rb
|
138
|
+
- lib/gir_ffi/error_argument_builder.rb
|
141
139
|
- lib/gir_ffi/ffi_ext/pointer.rb
|
140
|
+
- lib/gir_ffi/setter_argument_info.rb
|
142
141
|
- lib/gir_ffi/builder_helper.rb
|
143
142
|
- lib/gir_ffi/variable_name_generator.rb
|
144
143
|
- lib/gir_ffi/in_pointer.rb
|
144
|
+
- lib/gir_ffi/return_value_builder.rb
|
145
145
|
- lib/gir_ffi/in_out_pointer.rb
|
146
146
|
- lib/gir_ffi/version.rb
|
147
|
+
- lib/gir_ffi/null_argument_builder.rb
|
147
148
|
- lib/gir_ffi/callback_helper.rb
|
148
149
|
- lib/gir_ffi/builder.rb
|
149
150
|
- lib/gir_ffi/interface_base.rb
|
150
151
|
- lib/gir_ffi/info_ext/i_type_info.rb
|
151
152
|
- lib/gir_ffi/info_ext/i_field_info.rb
|
153
|
+
- lib/gir_ffi/info_ext/safe_constant_name.rb
|
152
154
|
- lib/gir_ffi/info_ext/i_property_info.rb
|
155
|
+
- lib/gir_ffi/info_ext/safe_function_name.rb
|
153
156
|
- lib/gir_ffi/info_ext/i_registered_type_info.rb
|
154
157
|
- lib/gir_ffi/module_base.rb
|
158
|
+
- lib/gir_ffi/base_argument_builder.rb
|
155
159
|
- lib/gir_ffi/class_base.rb
|
156
160
|
- lib/gir_ffi/object_base.rb
|
161
|
+
- lib/gir_ffi/function_builder.rb
|
157
162
|
- lib/gir_ffi-base/gobject/lib.rb
|
158
163
|
- lib/gir_ffi-base/glib/strv.rb
|
159
164
|
- lib/ffi-gobject/ruby_style.rb
|
@@ -208,7 +213,6 @@ files:
|
|
208
213
|
- test/integration/method_lookup_test.rb
|
209
214
|
- test/integration/generated_gimarshallingtests_test.rb
|
210
215
|
- test/integration/generated_gio_test.rb
|
211
|
-
- test/integration/pretty_print_test.rb
|
212
216
|
- test/integration/generated_gobject_test.rb
|
213
217
|
- test/gir_ffi/builder/type/user_defined_test.rb
|
214
218
|
- test/gir_ffi/builder/type/enum_test.rb
|
@@ -220,8 +224,6 @@ files:
|
|
220
224
|
- test/gir_ffi/builder/type/unintrospectable_test.rb
|
221
225
|
- test/gir_ffi/builder/type/interface_test.rb
|
222
226
|
- test/gir_ffi/builder/module_test.rb
|
223
|
-
- test/gir_ffi/builder/function_test.rb
|
224
|
-
- test/gir_ffi/builder/argument/base_test.rb
|
225
227
|
- test/gir_ffi/object_base_test.rb
|
226
228
|
- test/gir_ffi/user_defined/i_registered_type_info_test.rb
|
227
229
|
- test/gir_ffi/user_defined/i_object_info_test.rb
|
@@ -230,10 +232,16 @@ files:
|
|
230
232
|
- test/gir_ffi/in_pointer_test.rb
|
231
233
|
- test/gir_ffi/in_out_pointer_test.rb
|
232
234
|
- test/gir_ffi/arg_helper_test.rb
|
235
|
+
- test/gir_ffi/function_builder_test.rb
|
233
236
|
- test/gir_ffi/variable_name_generator_test.rb
|
234
237
|
- test/gir_ffi/callback_helper_test.rb
|
238
|
+
- test/gir_ffi/base_argument_builder_test.rb
|
235
239
|
- test/gir_ffi/class_base_test.rb
|
240
|
+
- test/gir_ffi/argument_builder_test.rb
|
241
|
+
- test/gir_ffi/return_value_builder_test.rb
|
236
242
|
- test/gir_ffi/info_ext/i_type_info_test.rb
|
243
|
+
- test/gir_ffi/info_ext/safe_constant_name_test.rb
|
244
|
+
- test/gir_ffi/info_ext/safe_function_name_test.rb
|
237
245
|
- test/gir_ffi/info_ext/i_field_info_test.rb
|
238
246
|
- test/gir_ffi/interface_base_test.rb
|
239
247
|
- test/gir_ffi-base/glib/strv_test.rb
|
@@ -324,8 +332,8 @@ test_files:
|
|
324
332
|
- test/ffi-gobject_test.rb
|
325
333
|
- test/gir_ffi-base/glib/strv_test.rb
|
326
334
|
- test/gir_ffi/arg_helper_test.rb
|
327
|
-
- test/gir_ffi/
|
328
|
-
- test/gir_ffi/
|
335
|
+
- test/gir_ffi/argument_builder_test.rb
|
336
|
+
- test/gir_ffi/base_argument_builder_test.rb
|
329
337
|
- test/gir_ffi/builder/module_test.rb
|
330
338
|
- test/gir_ffi/builder/type/callback_test.rb
|
331
339
|
- test/gir_ffi/builder/type/constant_test.rb
|
@@ -339,12 +347,16 @@ test_files:
|
|
339
347
|
- test/gir_ffi/builder_test.rb
|
340
348
|
- test/gir_ffi/callback_helper_test.rb
|
341
349
|
- test/gir_ffi/class_base_test.rb
|
350
|
+
- test/gir_ffi/function_builder_test.rb
|
342
351
|
- test/gir_ffi/in_out_pointer_test.rb
|
343
352
|
- test/gir_ffi/in_pointer_test.rb
|
344
353
|
- test/gir_ffi/info_ext/i_field_info_test.rb
|
345
354
|
- test/gir_ffi/info_ext/i_type_info_test.rb
|
355
|
+
- test/gir_ffi/info_ext/safe_constant_name_test.rb
|
356
|
+
- test/gir_ffi/info_ext/safe_function_name_test.rb
|
346
357
|
- test/gir_ffi/interface_base_test.rb
|
347
358
|
- test/gir_ffi/object_base_test.rb
|
359
|
+
- test/gir_ffi/return_value_builder_test.rb
|
348
360
|
- test/gir_ffi/user_defined/i_object_info_test.rb
|
349
361
|
- test/gir_ffi/user_defined/i_property_info_test.rb
|
350
362
|
- test/gir_ffi/user_defined/i_registered_type_info_test.rb
|
@@ -357,7 +369,6 @@ test_files:
|
|
357
369
|
- test/integration/generated_gobject_test.rb
|
358
370
|
- test/integration/generated_regress_test.rb
|
359
371
|
- test/integration/method_lookup_test.rb
|
360
|
-
- test/integration/pretty_print_test.rb
|
361
372
|
- test/introspection_test_helper.rb
|
362
373
|
- test/lib/Makefile.am
|
363
374
|
- test/lib/autogen.sh
|
@@ -1,569 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
require 'gir_ffi/in_pointer'
|
4
|
-
require 'gir_ffi/in_out_pointer'
|
5
|
-
|
6
|
-
require 'gir_ffi/builder/argument/base'
|
7
|
-
require 'gir_ffi/builder/argument/in_base'
|
8
|
-
require 'gir_ffi/builder/argument/out_base'
|
9
|
-
require 'gir_ffi/builder/argument/in_out_base'
|
10
|
-
|
11
|
-
module GirFFI::Builder
|
12
|
-
module Argument
|
13
|
-
def self.build var_gen, arginfo, libmodule
|
14
|
-
{
|
15
|
-
:inout => InOutArgument,
|
16
|
-
:in => InArgument,
|
17
|
-
:out => OutArgument
|
18
|
-
}[arginfo.direction].build var_gen, arginfo, libmodule
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module InArgument
|
23
|
-
def self.build var_gen, arginfo, libmodule
|
24
|
-
type = arginfo.argument_type
|
25
|
-
builder_for var_gen, arginfo.name, type, arginfo.direction, libmodule
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.builder_for var_gen, name, type, direction, libmodule
|
29
|
-
klass = case type.tag
|
30
|
-
when :interface
|
31
|
-
case type.interface.info_type
|
32
|
-
when :callback
|
33
|
-
return CallbackInArgument.new var_gen, name, type, libmodule
|
34
|
-
else
|
35
|
-
RegularArgument
|
36
|
-
end
|
37
|
-
else
|
38
|
-
RegularArgument
|
39
|
-
end
|
40
|
-
return klass.new var_gen, name, type, direction
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Implements argument processing for callback arguments with direction
|
45
|
-
# :in.
|
46
|
-
class CallbackInArgument < Argument::InBase
|
47
|
-
def initialize var_gen, name, type, libmodule
|
48
|
-
super var_gen, name, type, :in
|
49
|
-
@libmodule = libmodule
|
50
|
-
end
|
51
|
-
|
52
|
-
def pre
|
53
|
-
iface = type_info.interface
|
54
|
-
[ "#{callarg} = GirFFI::CallbackHelper.wrap_in_callback_args_mapper \"#{iface.namespace}\", \"#{iface.name}\", #{@name}",
|
55
|
-
"#{@libmodule}::CALLBACKS << #{callarg}" ]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Implements argument processing for arguments with direction :in whose
|
60
|
-
# type-specific processing is left to FFI (e.g., ints and floats, and
|
61
|
-
# objects that implement to_ptr.).
|
62
|
-
#
|
63
|
-
# Implements argument processing for arguments with direction :in that
|
64
|
-
# are GObjects.
|
65
|
-
#
|
66
|
-
# Implements argument processing for UTF8 string arguments with direction
|
67
|
-
# :in.
|
68
|
-
#
|
69
|
-
# Implements argument processing for void pointer arguments with
|
70
|
-
# direction :in.
|
71
|
-
#
|
72
|
-
# Implements argument processing for interface arguments with direction
|
73
|
-
# :inout (structs, objects, etc.).
|
74
|
-
#
|
75
|
-
# Implements argument processing for arguments with direction
|
76
|
-
# :out that are neither arrays nor 'interfaces'.
|
77
|
-
class RegularArgument < Argument::Base
|
78
|
-
def initialize var_gen, name, typeinfo, direction
|
79
|
-
super var_gen, name, typeinfo, direction
|
80
|
-
@direction = direction
|
81
|
-
end
|
82
|
-
|
83
|
-
def inarg
|
84
|
-
if has_input_value?
|
85
|
-
@array_arg.nil? ? @name : nil
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def retname
|
90
|
-
if has_output_value?
|
91
|
-
@retname ||= @var_gen.new_var
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def pre
|
96
|
-
pr = []
|
97
|
-
if has_input_value?
|
98
|
-
pr << fixed_array_size_check if needs_size_check?
|
99
|
-
pr << array_length_assignment if is_array_length_parameter?
|
100
|
-
end
|
101
|
-
pr << set_function_call_argument
|
102
|
-
pr
|
103
|
-
end
|
104
|
-
|
105
|
-
def post
|
106
|
-
result = []
|
107
|
-
if has_output_value?
|
108
|
-
value = case @direction
|
109
|
-
when :inout
|
110
|
-
"#{argument_class_name}.wrap(#{output_conversion_arguments})"
|
111
|
-
when :out
|
112
|
-
"#{callarg}.to_value"
|
113
|
-
end
|
114
|
-
result << "#{retname} = #{value}"
|
115
|
-
end
|
116
|
-
result
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
def is_array_length_parameter?
|
122
|
-
@array_arg
|
123
|
-
end
|
124
|
-
|
125
|
-
def needs_size_check?
|
126
|
-
if type_tag == :array
|
127
|
-
size = type_info.array_fixed_size
|
128
|
-
if size > -1
|
129
|
-
true
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def fixed_array_size_check
|
135
|
-
size = type_info.array_fixed_size
|
136
|
-
"GirFFI::ArgHelper.check_fixed_array_size #{size}, #{@name}, \"#{@name}\""
|
137
|
-
end
|
138
|
-
|
139
|
-
def has_output_value?
|
140
|
-
@direction == :inout || @direction == :out
|
141
|
-
end
|
142
|
-
|
143
|
-
def has_input_value?
|
144
|
-
@direction == :inout || @direction == :in
|
145
|
-
end
|
146
|
-
|
147
|
-
def array_length_assignment
|
148
|
-
arrname = @array_arg.name
|
149
|
-
"#{@name} = #{arrname}.nil? ? 0 : #{arrname}.length"
|
150
|
-
end
|
151
|
-
|
152
|
-
def set_function_call_argument
|
153
|
-
value = if @direction == :out
|
154
|
-
"GirFFI::InOutPointer.for #{type_tag.inspect}"
|
155
|
-
else
|
156
|
-
if needs_ingoing_parameter_conversion?
|
157
|
-
parameter_conversion
|
158
|
-
else
|
159
|
-
@name
|
160
|
-
end
|
161
|
-
end
|
162
|
-
"#{callarg} = #{value}"
|
163
|
-
end
|
164
|
-
|
165
|
-
def needs_outgoing_parameter_conversion?
|
166
|
-
case specialized_type_tag
|
167
|
-
when :object, :struct, :utf8, :void, :glist, :gslist, :ghash, :array, :c, :strv
|
168
|
-
true
|
169
|
-
else
|
170
|
-
false
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def needs_ingoing_parameter_conversion?
|
175
|
-
case specialized_type_tag
|
176
|
-
when :object, :struct, :utf8, :void, :glist, :gslist, :ghash, :array, :c, :strv
|
177
|
-
true
|
178
|
-
else
|
179
|
-
false
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def parameter_conversion
|
184
|
-
base = "#{argument_class_name}.from(#{parameter_conversion_arguments})"
|
185
|
-
if has_output_value?
|
186
|
-
"GirFFI::InOutPointer.from :pointer, #{base}"
|
187
|
-
else
|
188
|
-
base
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def output_conversion_arguments
|
193
|
-
conversion_arguments "#{callarg}.to_value"
|
194
|
-
end
|
195
|
-
|
196
|
-
def parameter_conversion_arguments
|
197
|
-
conversion_arguments @name
|
198
|
-
end
|
199
|
-
|
200
|
-
def conversion_arguments name
|
201
|
-
case specialized_type_tag
|
202
|
-
when :utf8, :void
|
203
|
-
"#{self_t}, #{name}"
|
204
|
-
when :glist, :gslist, :ghash, :array
|
205
|
-
"#{elm_t}, #{name}"
|
206
|
-
when :c
|
207
|
-
"#{type_specification}, #{name}"
|
208
|
-
when :strv
|
209
|
-
"#{name}"
|
210
|
-
else
|
211
|
-
"#{name}"
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
def self_t
|
216
|
-
type_tag.inspect
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
# Implements argument processing for arguments with direction :out.
|
221
|
-
module OutArgument
|
222
|
-
def self.build var_gen, arginfo, libmodule
|
223
|
-
type = arginfo.argument_type
|
224
|
-
direction = arginfo.direction
|
225
|
-
klass = case type.tag
|
226
|
-
when :interface
|
227
|
-
case type.interface.info_type
|
228
|
-
when :enum, :flags
|
229
|
-
EnumOutArgument
|
230
|
-
else
|
231
|
-
if arginfo.caller_allocates?
|
232
|
-
AllocatedInterfaceOutArgument
|
233
|
-
else
|
234
|
-
InterfaceOutArgument
|
235
|
-
end
|
236
|
-
end
|
237
|
-
when :array
|
238
|
-
if type.zero_terminated?
|
239
|
-
InterfaceOutArgument
|
240
|
-
else
|
241
|
-
case type.array_type
|
242
|
-
when :c
|
243
|
-
CArrayOutArgument
|
244
|
-
when :array
|
245
|
-
it = PointerLikeOutArgument.new var_gen, arginfo.name, type, direction
|
246
|
-
it.extend WithTypedContainerPostMethod
|
247
|
-
return it
|
248
|
-
end
|
249
|
-
end
|
250
|
-
when :glist, :gslist, :ghash
|
251
|
-
it = PointerLikeOutArgument.new var_gen, arginfo.name, type, direction
|
252
|
-
it.extend WithTypedContainerPostMethod
|
253
|
-
return it
|
254
|
-
else
|
255
|
-
RegularArgument
|
256
|
-
end
|
257
|
-
klass.new var_gen, arginfo.name, type, direction
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
# Implements argument processing for arguments with direction
|
262
|
-
# :out that are enums
|
263
|
-
class EnumOutArgument < Argument::OutBase
|
264
|
-
def pre
|
265
|
-
[ "#{callarg} = GirFFI::InOutPointer.for :gint32" ]
|
266
|
-
end
|
267
|
-
|
268
|
-
def post
|
269
|
-
[ "#{retname} = #{argument_class_name}[#{callarg}.to_value]" ]
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
# Implements argument processing for interface arguments with direction
|
274
|
-
# :out (structs, objects, etc.), allocated by the caller.
|
275
|
-
class AllocatedInterfaceOutArgument < Argument::OutBase
|
276
|
-
def pre
|
277
|
-
[ "#{callarg} = #{argument_class_name}.allocate" ]
|
278
|
-
end
|
279
|
-
|
280
|
-
def post
|
281
|
-
[ "#{retname} = #{callarg}" ]
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
# Implements argument processing for array arguments with direction
|
286
|
-
# :out.
|
287
|
-
class CArrayOutArgument < Argument::OutBase
|
288
|
-
def pre
|
289
|
-
[ "#{callarg} = GirFFI::InOutPointer.for_array #{subtype_tag_or_class_name}" ]
|
290
|
-
end
|
291
|
-
|
292
|
-
def postpost
|
293
|
-
[ "#{retname} = #{callarg}.to_sized_array_value #{array_size}" ]
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
# Base class for arguments with direction :out for which the base type is
|
298
|
-
# a pointer: For these, a pointer to a pointer needs to be passed to the
|
299
|
-
# C function.
|
300
|
-
class PointerLikeOutArgument < Argument::OutBase
|
301
|
-
def pre
|
302
|
-
[ "#{callarg} = GirFFI::InOutPointer.for :pointer" ]
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
# Implements argument processing for interface arguments with direction
|
307
|
-
# :out (structs, objects, etc.).
|
308
|
-
#
|
309
|
-
# Implements argument processing for strv arguments with direction
|
310
|
-
# :out.
|
311
|
-
class InterfaceOutArgument < PointerLikeOutArgument
|
312
|
-
def post
|
313
|
-
[ "#{retname} = #{argument_class_name}.wrap #{callarg}.to_value" ]
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
module WithTypedContainerPostMethod
|
318
|
-
def post
|
319
|
-
[ "#{retname} = #{argument_class_name}.wrap #{elm_t}, #{callarg}.to_value" ]
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
# Implements argument processing for arguments with direction :inout.
|
324
|
-
module InOutArgument
|
325
|
-
def self.build var_gen, arginfo, libmodule
|
326
|
-
type = arginfo.argument_type
|
327
|
-
direction = arginfo.direction
|
328
|
-
klass = case type.tag
|
329
|
-
when :interface
|
330
|
-
case type.interface.info_type
|
331
|
-
when :enum, :flags
|
332
|
-
EnumInOutArgument
|
333
|
-
else
|
334
|
-
RegularArgument
|
335
|
-
end
|
336
|
-
when :array
|
337
|
-
if type.zero_terminated?
|
338
|
-
StrvInOutArgument
|
339
|
-
else
|
340
|
-
case type.array_type
|
341
|
-
when :c
|
342
|
-
CArrayInOutArgument
|
343
|
-
when :array
|
344
|
-
RegularArgument
|
345
|
-
end
|
346
|
-
end
|
347
|
-
when :glist, :gslist, :ghash
|
348
|
-
RegularArgument
|
349
|
-
else
|
350
|
-
RegularInOutArgument
|
351
|
-
end
|
352
|
-
|
353
|
-
klass.new var_gen, arginfo.name, type, direction
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
# Implements argument processing for arguments with direction
|
358
|
-
# :inout that are enums.
|
359
|
-
class EnumInOutArgument < Argument::InOutBase
|
360
|
-
def pre
|
361
|
-
pr = []
|
362
|
-
pr << "#{callarg} = GirFFI::InOutPointer.from :gint32, #{argument_class_name}[#{@name}]"
|
363
|
-
pr
|
364
|
-
end
|
365
|
-
|
366
|
-
def post
|
367
|
-
[ "#{retname} = #{argument_class_name}[#{callarg}.to_value]" ]
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
# Implements argument processing for strv arguments with direction
|
372
|
-
# :inout.
|
373
|
-
class StrvInOutArgument < Argument::InOutBase
|
374
|
-
def pre
|
375
|
-
[ "#{callarg} = GirFFI::InOutPointer.from #{type_specification}, #{@name}" ]
|
376
|
-
end
|
377
|
-
|
378
|
-
def post
|
379
|
-
[ "#{retname} = GLib::Strv.wrap(#{callarg}.to_value)" ]
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
# Implements argument processing for array arguments with direction
|
384
|
-
# :inout.
|
385
|
-
class CArrayInOutArgument < Argument::InOutBase
|
386
|
-
def pre
|
387
|
-
[ "#{callarg} = GirFFI::InOutPointer.from_array #{elm_t}, #{@name}" ]
|
388
|
-
end
|
389
|
-
|
390
|
-
def postpost
|
391
|
-
size = array_size
|
392
|
-
pst = [ "#{retname} = #{callarg}.to_sized_array_value #{size}" ]
|
393
|
-
pst
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
# Implements argument processing for arguments with direction
|
398
|
-
# :inout that are neither arrays nor 'interfaces'.
|
399
|
-
class RegularInOutArgument < Argument::InOutBase
|
400
|
-
def pre
|
401
|
-
pr = []
|
402
|
-
if @array_arg
|
403
|
-
pr << "#{@name} = #{@array_arg.name}.length"
|
404
|
-
end
|
405
|
-
pr << "#{callarg} = GirFFI::InOutPointer.from #{type_tag.inspect}, #{@name}"
|
406
|
-
pr
|
407
|
-
end
|
408
|
-
|
409
|
-
def post
|
410
|
-
[ "#{retname} = #{callarg}.to_value" ]
|
411
|
-
end
|
412
|
-
end
|
413
|
-
|
414
|
-
module ReturnValueFactory
|
415
|
-
def self.build var_gen, arginfo
|
416
|
-
builder_for(var_gen,
|
417
|
-
arginfo.name,
|
418
|
-
arginfo.return_type,
|
419
|
-
:return,
|
420
|
-
arginfo.constructor?)
|
421
|
-
end
|
422
|
-
|
423
|
-
def self.builder_for var_gen, name, type, direction, is_constructor
|
424
|
-
if type.tag == :interface and
|
425
|
-
[:interface, :object].include? type.interface.info_type
|
426
|
-
klass = if is_constructor
|
427
|
-
ConstructorReturnValue
|
428
|
-
else
|
429
|
-
WrappingReturnValue
|
430
|
-
end
|
431
|
-
klass.new var_gen, name, type, direction
|
432
|
-
else
|
433
|
-
builder_for_field_getter var_gen, name, type, direction
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
def self.builder_for_field_getter var_gen, name, type, direction
|
438
|
-
klass = case type.tag
|
439
|
-
when :void
|
440
|
-
if type.pointer?
|
441
|
-
RegularReturnValue
|
442
|
-
else
|
443
|
-
VoidReturnValue
|
444
|
-
end
|
445
|
-
when :interface
|
446
|
-
case type.interface.info_type
|
447
|
-
when :struct, :union, :interface, :object
|
448
|
-
WrappingReturnValue
|
449
|
-
else
|
450
|
-
RegularReturnValue
|
451
|
-
end
|
452
|
-
when :array
|
453
|
-
if type.zero_terminated?
|
454
|
-
WrappingReturnValue
|
455
|
-
else
|
456
|
-
case type.array_type
|
457
|
-
when :c
|
458
|
-
CArrayReturnValue
|
459
|
-
when :array
|
460
|
-
it = ReturnValue.new var_gen, name, type, direction
|
461
|
-
it.extend WithTypedContainerPostMethod
|
462
|
-
return it
|
463
|
-
else
|
464
|
-
WrappingReturnValue
|
465
|
-
end
|
466
|
-
end
|
467
|
-
when :glist, :gslist, :ghash
|
468
|
-
it = ReturnValue.new var_gen, name, type, direction
|
469
|
-
it.extend WithTypedContainerPostMethod
|
470
|
-
return it
|
471
|
-
when :utf8
|
472
|
-
Utf8ReturnValue
|
473
|
-
else
|
474
|
-
RegularReturnValue
|
475
|
-
end
|
476
|
-
klass.new var_gen, name, type, direction
|
477
|
-
end
|
478
|
-
end
|
479
|
-
|
480
|
-
# Implements argument processing for return values.
|
481
|
-
class ReturnValue < Argument::Base
|
482
|
-
def cvar
|
483
|
-
callarg
|
484
|
-
end
|
485
|
-
|
486
|
-
def retname
|
487
|
-
@retname ||= @var_gen.new_var
|
488
|
-
end
|
489
|
-
|
490
|
-
def inarg
|
491
|
-
nil
|
492
|
-
end
|
493
|
-
end
|
494
|
-
|
495
|
-
# Null object to represent the case where no actual value is returned.
|
496
|
-
class VoidReturnValue < ReturnValue
|
497
|
-
def cvar; end
|
498
|
-
def retname; end
|
499
|
-
end
|
500
|
-
|
501
|
-
# Implements argument processing for interface return values (interfaces
|
502
|
-
# and structs, but not objects, which need special handling for
|
503
|
-
# polymorphism and constructors).
|
504
|
-
#
|
505
|
-
# Implements argument processing for object return values when the method is
|
506
|
-
# not a constructor.
|
507
|
-
#
|
508
|
-
# Implements argument processing for NULL-terminated string array return values.
|
509
|
-
#
|
510
|
-
# Implements argument processing for GByteArray return values.
|
511
|
-
#
|
512
|
-
# Implements argument processing for GPtrArray return values.
|
513
|
-
class WrappingReturnValue < ReturnValue
|
514
|
-
def post
|
515
|
-
[ "#{retname} = #{argument_class_name}.wrap(#{cvar})" ]
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
# Implements argument processing for object constructors.
|
520
|
-
class ConstructorReturnValue < ReturnValue
|
521
|
-
def post
|
522
|
-
[ "#{retname} = self.constructor_wrap(#{cvar})" ]
|
523
|
-
end
|
524
|
-
end
|
525
|
-
|
526
|
-
# Implements argument processing for array return values.
|
527
|
-
class CArrayReturnValue < ReturnValue
|
528
|
-
def post
|
529
|
-
size = array_size
|
530
|
-
|
531
|
-
[ "#{retname} = GirFFI::ArgHelper.ptr_to_typed_array #{subtype_tag_or_class_name}, #{cvar}, #{size}" ]
|
532
|
-
end
|
533
|
-
end
|
534
|
-
|
535
|
-
# Implements argument processing for UTF8 string return values.
|
536
|
-
class Utf8ReturnValue < ReturnValue
|
537
|
-
def post
|
538
|
-
[ "#{retname} = GirFFI::ArgHelper.ptr_to_utf8 #{cvar}" ]
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|
542
|
-
# Implements argument processing for other return values.
|
543
|
-
class RegularReturnValue < ReturnValue
|
544
|
-
def retval
|
545
|
-
@callarg
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
# Implements argument processing for error handling arguments. These
|
550
|
-
# arguments are not part of the introspected signature, but their
|
551
|
-
# presence is indicated by the 'throws' attribute of the function.
|
552
|
-
class ErrorArgument < Argument::Base
|
553
|
-
def pre
|
554
|
-
[ "#{callarg} = FFI::MemoryPointer.new(:pointer).write_pointer nil" ]
|
555
|
-
end
|
556
|
-
|
557
|
-
def post
|
558
|
-
[ "GirFFI::ArgHelper.check_error(#{callarg})" ]
|
559
|
-
end
|
560
|
-
end
|
561
|
-
|
562
|
-
# Argument builder that does nothing. Implements Null Object pattern.
|
563
|
-
class NullArgument
|
564
|
-
def initialize *args; end
|
565
|
-
def pre; []; end
|
566
|
-
def post; []; end
|
567
|
-
def callarg; end
|
568
|
-
end
|
569
|
-
end
|