gir_ffi 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +14 -0
- data/TODO.rdoc +23 -5
- data/lib/ffi-glib/array.rb +14 -15
- data/lib/ffi-glib/container_class_methods.rb +0 -1
- data/lib/ffi-glib/hash_table.rb +3 -4
- data/lib/ffi-glib/ptr_array.rb +12 -4
- data/lib/ffi-glib/sized_array.rb +27 -7
- data/lib/ffi-gobject.rb +14 -15
- data/lib/ffi-gobject/closure.rb +1 -1
- data/lib/ffi-gobject/object.rb +40 -15
- data/lib/ffi-gobject/ruby_closure.rb +0 -1
- data/lib/ffi-gobject/value.rb +45 -21
- data/lib/ffi-gobject_introspection/i_arg_info.rb +4 -0
- data/lib/ffi-gobject_introspection/i_base_info.rb +42 -2
- data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
- data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -4
- data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_object_info.rb +2 -0
- data/lib/ffi-gobject_introspection/i_repository.rb +2 -3
- data/lib/ffi-gobject_introspection/i_struct_info.rb +3 -8
- data/lib/ffi-gobject_introspection/lib.rb +3 -0
- data/lib/gir_ffi-base.rb +3 -1
- data/lib/gir_ffi-base/gir_ffi/struct.rb +27 -0
- data/lib/gir_ffi-base/glib/boolean.rb +13 -1
- data/lib/gir_ffi-base/gobject.rb +7 -0
- data/lib/gir_ffi-base/gobject/lib.rb +0 -2
- data/lib/gir_ffi.rb +1 -3
- data/lib/gir_ffi/arg_helper.rb +4 -85
- data/lib/gir_ffi/builder.rb +5 -5
- data/lib/gir_ffi/builder_helper.rb +7 -0
- data/lib/gir_ffi/builders/argument_builder.rb +132 -0
- data/lib/gir_ffi/{base_argument_builder.rb → builders/base_argument_builder.rb} +32 -41
- data/lib/gir_ffi/builders/base_type_builder.rb +47 -0
- data/lib/gir_ffi/builders/callback_builder.rb +38 -0
- data/lib/gir_ffi/builders/constant_builder.rb +18 -0
- data/lib/gir_ffi/builders/enum_builder.rb +62 -0
- data/lib/gir_ffi/builders/error_argument_builder.rb +18 -0
- data/lib/gir_ffi/builders/field_builder.rb +94 -0
- data/lib/gir_ffi/builders/function_builder.rb +123 -0
- data/lib/gir_ffi/builders/interface_builder.rb +29 -0
- data/lib/gir_ffi/builders/mapping_method_builder.rb +88 -0
- data/lib/gir_ffi/builders/module_builder.rb +124 -0
- data/lib/gir_ffi/{null_argument_builder.rb → builders/null_argument_builder.rb} +0 -0
- data/lib/gir_ffi/builders/null_builder.rb +11 -0
- data/lib/gir_ffi/builders/object_builder.rb +123 -0
- data/lib/gir_ffi/{builder/property.rb → builders/property_builder.rb} +0 -0
- data/lib/gir_ffi/builders/registered_type_builder.rb +50 -0
- data/lib/gir_ffi/builders/return_value_builder.rb +68 -0
- data/lib/gir_ffi/builders/signal_builder.rb +91 -0
- data/lib/gir_ffi/builders/struct_builder.rb +35 -0
- data/lib/gir_ffi/builders/type_builder.rb +40 -0
- data/lib/gir_ffi/builders/unintrospectable_builder.rb +35 -0
- data/lib/gir_ffi/builders/union_builder.rb +34 -0
- data/lib/gir_ffi/builders/user_defined_builder.rb +103 -0
- data/lib/gir_ffi/builders/with_layout.rb +55 -0
- data/lib/gir_ffi/builders/with_methods.rb +44 -0
- data/lib/gir_ffi/callback_base.rb +31 -0
- data/lib/gir_ffi/class_base.rb +16 -10
- data/lib/gir_ffi/enum_base.rb +8 -4
- data/lib/gir_ffi/ffi_ext/pointer.rb +19 -2
- data/lib/gir_ffi/in_out_pointer.rb +38 -39
- data/lib/gir_ffi/in_pointer.rb +33 -18
- data/lib/gir_ffi/info_ext.rb +0 -4
- data/lib/gir_ffi/info_ext/i_arg_info.rb +0 -18
- data/lib/gir_ffi/info_ext/i_callable_info.rb +2 -1
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +6 -8
- data/lib/gir_ffi/info_ext/i_signal_info.rb +6 -21
- data/lib/gir_ffi/info_ext/i_type_info.rb +54 -29
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -1
- data/lib/gir_ffi/interface_base.rb +1 -1
- data/lib/gir_ffi/module_base.rb +5 -1
- data/lib/gir_ffi/object_base.rb +5 -1
- data/lib/gir_ffi/setter_argument_info.rb +4 -0
- data/lib/gir_ffi/signal_base.rb +21 -0
- data/lib/gir_ffi/struct_base.rb +24 -0
- data/lib/gir_ffi/type_base.rb +11 -0
- data/lib/gir_ffi/type_map.rb +4 -2
- data/lib/gir_ffi/union_base.rb +24 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/tasks/test.rake +73 -7
- data/test/base_test_helper.rb +3 -19
- data/test/ffi-glib/array_test.rb +6 -0
- data/test/ffi-glib/ptr_array_test.rb +13 -0
- data/test/ffi-glib/ruby_closure_test.rb +7 -7
- data/test/ffi-glib/sized_array_test.rb +2 -2
- data/test/ffi-gobject/gobject_test.rb +3 -12
- data/test/ffi-gobject/object_test.rb +33 -2
- data/test/ffi-gobject/value_test.rb +114 -1
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +2 -2
- data/test/ffi-gobject_introspection/i_object_info_test.rb +3 -3
- data/test/ffi-gobject_introspection/i_repository_test.rb +26 -21
- data/test/ffi-gobject_test.rb +14 -14
- data/test/gir_ffi-base/glib/boolean_test.rb +6 -0
- data/test/gir_ffi/arg_helper_test.rb +2 -122
- data/test/gir_ffi/builder_test.rb +67 -204
- data/test/gir_ffi/{argument_builder_test.rb → builders/argument_builder_test.rb} +230 -108
- data/test/gir_ffi/builders/base_argument_builder_test.rb +5 -0
- data/test/gir_ffi/builders/callback_builder_test.rb +50 -0
- data/test/gir_ffi/builders/constant_builder_test.rb +4 -0
- data/test/gir_ffi/{builder/type/enum_test.rb → builders/enum_builder_test.rb} +2 -3
- data/test/gir_ffi/builders/field_builder_test.rb +94 -0
- data/test/gir_ffi/{function_builder_test.rb → builders/function_builder_test.rb} +43 -24
- data/test/gir_ffi/{builder/type/interface_test.rb → builders/interface_builder_test.rb} +2 -2
- data/test/gir_ffi/{builder/module_test.rb → builders/module_builder_test.rb} +12 -13
- data/test/gir_ffi/{builder/type/object_test.rb → builders/object_builder_test.rb} +9 -9
- data/test/gir_ffi/{return_value_builder_test.rb → builders/return_value_builder_test.rb} +94 -58
- data/test/gir_ffi/builders/signal_builder_test.rb +62 -0
- data/test/gir_ffi/{builder/type/struct_test.rb → builders/struct_builder_test.rb} +36 -19
- data/test/gir_ffi/{builder/type/unintrospectable_test.rb → builders/unintrospectable_builder_test.rb} +3 -3
- data/test/gir_ffi/builders/union_builder_test.rb +29 -0
- data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb} +2 -2
- data/test/gir_ffi/callback_base_test.rb +11 -0
- data/test/gir_ffi/class_base_test.rb +22 -22
- data/test/gir_ffi/ffi_ext/pointer_test.rb +18 -0
- data/test/gir_ffi/in_out_pointer_test.rb +0 -7
- data/test/gir_ffi/in_pointer_test.rb +27 -3
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +16 -44
- data/test/gir_ffi/info_ext/i_type_info_test.rb +315 -74
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +6 -0
- data/test/gir_ffi/interface_base_test.rb +3 -5
- data/test/gir_ffi/object_base_test.rb +10 -6
- data/test/gir_ffi/type_map_test.rb +2 -2
- data/test/gir_ffi/unintrospectable_type_info_test.rb +2 -2
- data/test/gir_ffi_test_helper.rb +12 -4
- data/test/integration/generated_gimarshallingtests_test.rb +436 -76
- data/test/integration/generated_gio_test.rb +5 -11
- data/test/integration/generated_gobject_test.rb +8 -0
- data/test/integration/generated_regress_test.rb +755 -309
- data/test/integration/generated_secret_test.rb +2 -1
- metadata +73 -72
- data/lib/ffi-gobject/ruby_style.rb +0 -23
- data/lib/gir_ffi/argument_builder.rb +0 -154
- data/lib/gir_ffi/builder/field.rb +0 -60
- data/lib/gir_ffi/builder/module.rb +0 -127
- data/lib/gir_ffi/builder/type.rb +0 -39
- data/lib/gir_ffi/builder/type/base.rb +0 -48
- data/lib/gir_ffi/builder/type/callback.rb +0 -30
- data/lib/gir_ffi/builder/type/constant.rb +0 -22
- data/lib/gir_ffi/builder/type/enum.rb +0 -66
- data/lib/gir_ffi/builder/type/interface.rb +0 -33
- data/lib/gir_ffi/builder/type/object.rb +0 -134
- data/lib/gir_ffi/builder/type/registered_type.rb +0 -62
- data/lib/gir_ffi/builder/type/struct.rb +0 -34
- data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -39
- data/lib/gir_ffi/builder/type/union.rb +0 -34
- data/lib/gir_ffi/builder/type/user_defined.rb +0 -107
- data/lib/gir_ffi/builder/type/with_layout.rb +0 -62
- data/lib/gir_ffi/builder/type/with_methods.rb +0 -64
- data/lib/gir_ffi/callback.rb +0 -72
- data/lib/gir_ffi/callback_helper.rb +0 -11
- data/lib/gir_ffi/error_argument_builder.rb +0 -17
- data/lib/gir_ffi/function_builder.rb +0 -112
- data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_object_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_struct_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_union_info.rb +0 -12
- data/lib/gir_ffi/return_value_builder.rb +0 -81
- data/test/ffi-gobject/ruby_style_test.rb +0 -38
- data/test/gir_ffi/base_argument_builder_test.rb +0 -13
- data/test/gir_ffi/builder/type/callback_test.rb +0 -6
- data/test/gir_ffi/builder/type/constant_test.rb +0 -4
- data/test/gir_ffi/builder/type/union_test.rb +0 -12
- data/test/gir_ffi/callback_helper_test.rb +0 -10
- data/test/gir_ffi/callback_test.rb +0 -49
- data/test/gir_ffi/info_ext/i_arg_info_test.rb +0 -39
- data/test/gir_ffi/info_ext/i_object_info_test.rb +0 -14
@@ -16,5 +16,12 @@ module GirFFI
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def get_or_define_class namespace, name, parent
|
20
|
+
optionally_define_constant(namespace, name) { Class.new parent }
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_or_define_module parent, name
|
24
|
+
optionally_define_constant(parent, name) { Module.new }
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'gir_ffi/builders/base_argument_builder'
|
2
|
+
|
3
|
+
module GirFFI
|
4
|
+
module Builders
|
5
|
+
# Implements building pre- and post-processing statements for arguments.
|
6
|
+
class ArgumentBuilder < BaseArgumentBuilder
|
7
|
+
def initialize var_gen, arginfo
|
8
|
+
super var_gen, arginfo.name, arginfo.argument_type, arginfo.direction
|
9
|
+
@arginfo = arginfo
|
10
|
+
end
|
11
|
+
|
12
|
+
def inarg
|
13
|
+
if has_input_value? && !is_array_length_parameter?
|
14
|
+
@name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def retname
|
19
|
+
if has_output_value?
|
20
|
+
@retname ||= @var_gen.new_var
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def pre
|
25
|
+
pr = []
|
26
|
+
if has_input_value?
|
27
|
+
pr << fixed_array_size_check if needs_size_check?
|
28
|
+
pr << array_length_assignment if is_array_length_parameter?
|
29
|
+
end
|
30
|
+
pr << set_function_call_argument
|
31
|
+
pr
|
32
|
+
end
|
33
|
+
|
34
|
+
def post
|
35
|
+
if has_output_value?
|
36
|
+
value = output_value
|
37
|
+
["#{retname} = #{value}"]
|
38
|
+
else
|
39
|
+
[]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def output_value
|
46
|
+
if is_caller_allocated_object?
|
47
|
+
callarg
|
48
|
+
else
|
49
|
+
base = "#{callarg}.to_value"
|
50
|
+
if needs_outgoing_parameter_conversion?
|
51
|
+
outgoing_conversion base
|
52
|
+
else
|
53
|
+
base
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def is_array_length_parameter?
|
59
|
+
@array_arg
|
60
|
+
end
|
61
|
+
|
62
|
+
def needs_size_check?
|
63
|
+
specialized_type_tag == :c && type_info.array_fixed_size > -1
|
64
|
+
end
|
65
|
+
|
66
|
+
def fixed_array_size_check
|
67
|
+
size = type_info.array_fixed_size
|
68
|
+
"GirFFI::ArgHelper.check_fixed_array_size #{size}, #{@name}, \"#{@name}\""
|
69
|
+
end
|
70
|
+
|
71
|
+
def skipped?
|
72
|
+
@arginfo.skip? ||
|
73
|
+
@array_arg && @array_arg.specialized_type_tag == :strv
|
74
|
+
end
|
75
|
+
|
76
|
+
def has_output_value?
|
77
|
+
(@direction == :inout || @direction == :out) && !skipped?
|
78
|
+
end
|
79
|
+
|
80
|
+
def has_input_value?
|
81
|
+
(@direction == :inout || @direction == :in) && !skipped?
|
82
|
+
end
|
83
|
+
|
84
|
+
def array_length_assignment
|
85
|
+
arrname = @array_arg.name
|
86
|
+
"#{@name} = #{arrname}.nil? ? 0 : #{arrname}.length"
|
87
|
+
end
|
88
|
+
|
89
|
+
def set_function_call_argument
|
90
|
+
value = if skipped?
|
91
|
+
@direction == :in ? "0" : "nil"
|
92
|
+
elsif !has_input_value?
|
93
|
+
if is_caller_allocated_object?
|
94
|
+
if specialized_type_tag == :array
|
95
|
+
"#{argument_class_name}.new #{type_info.element_type.inspect}"
|
96
|
+
else
|
97
|
+
"#{argument_class_name}.new"
|
98
|
+
end
|
99
|
+
else
|
100
|
+
"GirFFI::InOutPointer.for #{type_info.tag_or_class.inspect}"
|
101
|
+
end
|
102
|
+
else
|
103
|
+
ingoing_parameter_conversion
|
104
|
+
end
|
105
|
+
"#{callarg} = #{value}"
|
106
|
+
end
|
107
|
+
|
108
|
+
def is_caller_allocated_object?
|
109
|
+
[ :struct, :array ].include?(specialized_type_tag) &&
|
110
|
+
@arginfo.caller_allocates?
|
111
|
+
end
|
112
|
+
|
113
|
+
def ingoing_parameter_conversion
|
114
|
+
args = conversion_arguments @name
|
115
|
+
|
116
|
+
base = case specialized_type_tag
|
117
|
+
when :array, :c, :callback, :ghash, :glist, :gslist, :object, :ptr_array,
|
118
|
+
:struct, :strv, :utf8, :void, :zero_terminated
|
119
|
+
"#{argument_class_name}.from(#{args})"
|
120
|
+
else
|
121
|
+
args
|
122
|
+
end
|
123
|
+
|
124
|
+
if has_output_value?
|
125
|
+
"GirFFI::InOutPointer.from #{type_info.tag_or_class.inspect}, #{base}"
|
126
|
+
else
|
127
|
+
base
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -15,6 +15,8 @@ module GirFFI
|
|
15
15
|
|
16
16
|
attr_accessor :length_arg, :array_arg
|
17
17
|
|
18
|
+
attr_accessor :is_closure
|
19
|
+
|
18
20
|
def initialize var_gen, name, typeinfo, direction
|
19
21
|
@var_gen = var_gen
|
20
22
|
|
@@ -27,6 +29,8 @@ module GirFFI
|
|
27
29
|
|
28
30
|
@length_arg = nil
|
29
31
|
@array_arg = nil
|
32
|
+
|
33
|
+
@is_closure = false
|
30
34
|
end
|
31
35
|
|
32
36
|
def type_info
|
@@ -37,38 +41,9 @@ module GirFFI
|
|
37
41
|
type_info.flattened_tag
|
38
42
|
end
|
39
43
|
|
40
|
-
TAG_TO_WRAPPER_CLASS_MAP = {
|
41
|
-
:array => 'GLib::Array',
|
42
|
-
:byte_array => 'GLib::ByteArray',
|
43
|
-
:c => 'GLib::SizedArray',
|
44
|
-
:callback => 'GirFFI::Callback',
|
45
|
-
:error => 'GLib::Error',
|
46
|
-
:ghash => 'GLib::HashTable',
|
47
|
-
:glist => 'GLib::List',
|
48
|
-
:gslist => 'GLib::SList',
|
49
|
-
:ptr_array => 'GLib::PtrArray',
|
50
|
-
:strv => 'GLib::Strv',
|
51
|
-
:utf8 => 'GirFFI::InPointer',
|
52
|
-
:void => 'GirFFI::InPointer',
|
53
|
-
:zero_terminated => 'GirFFI::ZeroTerminated'
|
54
|
-
}
|
55
|
-
|
56
44
|
# TODO: Use class rather than class name
|
57
45
|
def argument_class_name
|
58
|
-
|
59
|
-
when :struct, :union, :object, :interface, :enum, :flags
|
60
|
-
type_info.interface_type_name
|
61
|
-
else
|
62
|
-
TAG_TO_WRAPPER_CLASS_MAP[tag]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def subtype_tag_or_class_name
|
67
|
-
type_info.subtype_tag_or_class_name
|
68
|
-
end
|
69
|
-
|
70
|
-
def elm_t
|
71
|
-
type_info.element_type.inspect
|
46
|
+
type_info.argument_class_name
|
72
47
|
end
|
73
48
|
|
74
49
|
def array_size
|
@@ -111,22 +86,38 @@ module GirFFI
|
|
111
86
|
[]
|
112
87
|
end
|
113
88
|
|
89
|
+
def new_variable
|
90
|
+
@var_gen.new_var
|
91
|
+
end
|
92
|
+
|
114
93
|
private
|
115
94
|
|
116
|
-
def
|
95
|
+
def needs_outgoing_parameter_conversion?
|
96
|
+
[ :array, :byte_array, :c, :error, :filename, :ghash, :glist,
|
97
|
+
:gslist, :interface, :object, :ptr_array, :struct, :strv, :union,
|
98
|
+
:utf8, :zero_terminated ].include?(specialized_type_tag)
|
99
|
+
end
|
100
|
+
|
101
|
+
def outgoing_conversion base
|
102
|
+
args = output_conversion_arguments base
|
117
103
|
case specialized_type_tag
|
118
|
-
when :utf8, :
|
119
|
-
"#{
|
120
|
-
|
121
|
-
"#{
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
104
|
+
when :utf8, :filename
|
105
|
+
"#{base}.to_utf8"
|
106
|
+
else
|
107
|
+
"#{argument_class_name}.wrap(#{args})"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def output_conversion_arguments arg
|
112
|
+
if specialized_type_tag == :c
|
113
|
+
"#{type_info.subtype_tag_or_class.inspect}, #{array_size}, #{arg}"
|
127
114
|
else
|
128
|
-
|
115
|
+
conversion_arguments arg
|
129
116
|
end
|
130
117
|
end
|
118
|
+
|
119
|
+
def conversion_arguments name
|
120
|
+
type_info.extra_conversion_arguments.map(&:inspect).push(name).join(", ")
|
121
|
+
end
|
131
122
|
end
|
132
123
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'gir_ffi/builder_helper'
|
2
|
+
|
3
|
+
module GirFFI
|
4
|
+
|
5
|
+
# Base class for type builders.
|
6
|
+
class BaseTypeBuilder
|
7
|
+
include BuilderHelper
|
8
|
+
|
9
|
+
def initialize info
|
10
|
+
@info = info
|
11
|
+
@namespace = @info.namespace
|
12
|
+
@classname = @info.safe_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def build_class
|
16
|
+
unless defined? @klass
|
17
|
+
instantiate_class
|
18
|
+
end
|
19
|
+
@klass
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :info
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def namespace_module
|
27
|
+
@namespace_module ||= Builder.build_module @namespace
|
28
|
+
end
|
29
|
+
|
30
|
+
def lib
|
31
|
+
@lib ||= namespace_module.const_get :Lib
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup_constants
|
35
|
+
@klass.const_set :GIR_INFO, info
|
36
|
+
@klass.const_set :GIR_FFI_BUILDER, self
|
37
|
+
end
|
38
|
+
|
39
|
+
def already_set_up
|
40
|
+
const_defined_for @klass, :GIR_FFI_BUILDER
|
41
|
+
end
|
42
|
+
|
43
|
+
def gir
|
44
|
+
@gir ||= GObjectIntrospection::IRepository.default
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'gir_ffi/builders/base_type_builder'
|
2
|
+
require 'gir_ffi/builders/mapping_method_builder'
|
3
|
+
require 'gir_ffi/callback_base'
|
4
|
+
|
5
|
+
module GirFFI
|
6
|
+
module Builders
|
7
|
+
# Implements the creation of a callback type. The type will be
|
8
|
+
# attached to the appropriate namespace module, and will be defined
|
9
|
+
# as a callback for FFI.
|
10
|
+
class CallbackBuilder < BaseTypeBuilder
|
11
|
+
def instantiate_class
|
12
|
+
@klass ||= optionally_define_constant namespace_module, @classname do
|
13
|
+
cb = lib.callback callback_sym, argument_types, return_type
|
14
|
+
cb.instance_eval mapping_method_definition
|
15
|
+
cb.extend CallbackBase
|
16
|
+
cb
|
17
|
+
end
|
18
|
+
@klass
|
19
|
+
end
|
20
|
+
|
21
|
+
def mapping_method_definition
|
22
|
+
MappingMethodBuilder.new(info.args, info.return_type).method_definition
|
23
|
+
end
|
24
|
+
|
25
|
+
def callback_sym
|
26
|
+
@classname.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
def argument_types
|
30
|
+
@info.argument_ffi_types
|
31
|
+
end
|
32
|
+
|
33
|
+
def return_type
|
34
|
+
@info.return_ffi_type
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'gir_ffi/builders/base_type_builder'
|
2
|
+
module GirFFI
|
3
|
+
module Builders
|
4
|
+
# Implements the creation of a constant. Though semantically not a
|
5
|
+
# type, its build method is like that of the types, in that it is
|
6
|
+
# triggered by a missing constant in the parent namespace. The
|
7
|
+
# constant will be attached to the appropriate namespace module.
|
8
|
+
class ConstantBuilder < BaseTypeBuilder
|
9
|
+
private
|
10
|
+
|
11
|
+
def instantiate_class
|
12
|
+
@klass = optionally_define_constant namespace_module, @classname do
|
13
|
+
info.value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'gir_ffi/builders/registered_type_builder'
|
2
|
+
require 'gir_ffi/builders/with_methods'
|
3
|
+
require 'gir_ffi/enum_base'
|
4
|
+
|
5
|
+
module GirFFI
|
6
|
+
module Builders
|
7
|
+
# Implements the creation of an enum or flags type. The type will be
|
8
|
+
# attached to the appropriate namespace module, and will be defined
|
9
|
+
# as an enum for FFI.
|
10
|
+
class EnumBuilder < RegisteredTypeBuilder
|
11
|
+
include WithMethods
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def enum_sym
|
16
|
+
@classname.to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def value_spec
|
20
|
+
return info.values.map {|vinfo|
|
21
|
+
val = GirFFI::ArgHelper.cast_uint32_to_int32(vinfo.value)
|
22
|
+
[vinfo.name.to_sym, val]
|
23
|
+
}.flatten
|
24
|
+
end
|
25
|
+
|
26
|
+
def instantiate_class
|
27
|
+
@klass = get_or_define_module namespace_module, @classname
|
28
|
+
@enum = optionally_define_constant @klass, :Enum do
|
29
|
+
lib.enum(enum_sym, value_spec)
|
30
|
+
end
|
31
|
+
unless already_set_up
|
32
|
+
@klass.extend superclass
|
33
|
+
setup_constants
|
34
|
+
setup_gtype_getter
|
35
|
+
stub_methods
|
36
|
+
setup_inspect
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def setup_inspect
|
41
|
+
@klass.instance_eval <<-EOS
|
42
|
+
def self.inspect
|
43
|
+
"#{@namespace}::#{@classname}"
|
44
|
+
end
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
|
48
|
+
def already_set_up
|
49
|
+
@klass.respond_to? :get_gtype
|
50
|
+
end
|
51
|
+
|
52
|
+
def superclass
|
53
|
+
@superclass ||= EnumBase
|
54
|
+
end
|
55
|
+
|
56
|
+
# FIXME: Remove duplication with ModuleBuilder
|
57
|
+
def get_or_define_module parent, name
|
58
|
+
optionally_define_constant(parent, name) { ::Module.new }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'gir_ffi/builders/base_argument_builder'
|
2
|
+
|
3
|
+
module GirFFI
|
4
|
+
module Builders
|
5
|
+
# Implements argument processing for error handling arguments. These
|
6
|
+
# arguments are not part of the introspected signature, but their
|
7
|
+
# presence is indicated by the 'throws' attribute of the function.
|
8
|
+
class ErrorArgumentBuilder < BaseArgumentBuilder
|
9
|
+
def pre
|
10
|
+
[ "#{callarg} = FFI::MemoryPointer.new(:pointer).write_pointer nil" ]
|
11
|
+
end
|
12
|
+
|
13
|
+
def post
|
14
|
+
[ "GirFFI::ArgHelper.check_error(#{callarg})" ]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'gir_ffi/builders/argument_builder'
|
2
|
+
require 'gir_ffi/builders/return_value_builder'
|
3
|
+
require 'gir_ffi/variable_name_generator'
|
4
|
+
require 'gir_ffi/setter_argument_info'
|
5
|
+
|
6
|
+
module GirFFI
|
7
|
+
module Builders
|
8
|
+
# Creates field getter and setter code for a given IFieldInfo.
|
9
|
+
class FieldBuilder
|
10
|
+
attr_reader :info
|
11
|
+
|
12
|
+
def initialize field_info
|
13
|
+
@info = field_info
|
14
|
+
end
|
15
|
+
|
16
|
+
def build
|
17
|
+
unless container_info.find_instance_method info.name
|
18
|
+
container_class.class_eval getter_def
|
19
|
+
end
|
20
|
+
container_class.class_eval setter_def if info.writable?
|
21
|
+
end
|
22
|
+
|
23
|
+
def getter_def
|
24
|
+
builder = return_value_builder
|
25
|
+
|
26
|
+
field_ptr = builder.new_variable
|
27
|
+
typed_ptr = builder.new_variable
|
28
|
+
|
29
|
+
return <<-CODE.reset_indentation
|
30
|
+
def #{info.name}
|
31
|
+
#{field_ptr} = @struct.to_ptr + #{info.offset}
|
32
|
+
#{typed_ptr} = GirFFI::InOutPointer.new(#{field_type_tag_or_class.inspect}, #{field_ptr})
|
33
|
+
#{builder.callarg} = #{typed_ptr}.to_value
|
34
|
+
#{builder.post.join("\n")}
|
35
|
+
#{builder.retval}
|
36
|
+
end
|
37
|
+
CODE
|
38
|
+
end
|
39
|
+
|
40
|
+
def setter_def
|
41
|
+
builder = setter_builder
|
42
|
+
|
43
|
+
field_ptr = builder.new_variable
|
44
|
+
typed_ptr = builder.new_variable
|
45
|
+
|
46
|
+
return <<-CODE.reset_indentation
|
47
|
+
def #{info.name}= #{builder.inarg}
|
48
|
+
#{field_ptr} = @struct.to_ptr + #{info.offset}
|
49
|
+
#{typed_ptr} = GirFFI::InOutPointer.new(#{field_type_tag_or_class.inspect}, #{field_ptr})
|
50
|
+
#{builder.pre.join("\n ")}
|
51
|
+
#{typed_ptr}.set_value #{builder.callarg}
|
52
|
+
end
|
53
|
+
CODE
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def struct_class
|
59
|
+
container_class::Struct
|
60
|
+
end
|
61
|
+
|
62
|
+
def field_type_tag_or_class
|
63
|
+
@field_type_tag_or_class ||= info.field_type.tag_or_class
|
64
|
+
end
|
65
|
+
|
66
|
+
def container_class
|
67
|
+
@container_class ||= container_module.const_get(container_info.safe_name)
|
68
|
+
end
|
69
|
+
|
70
|
+
def container_module
|
71
|
+
@container_module ||= Object.const_get(container_info.safe_namespace)
|
72
|
+
end
|
73
|
+
|
74
|
+
def container_info
|
75
|
+
@container_info ||= info.container
|
76
|
+
end
|
77
|
+
|
78
|
+
def field_symbol
|
79
|
+
@info.name.to_sym
|
80
|
+
end
|
81
|
+
|
82
|
+
def return_value_builder
|
83
|
+
vargen = VariableNameGenerator.new
|
84
|
+
@rv_builder ||= ReturnValueBuilder.new vargen, @info.field_type
|
85
|
+
end
|
86
|
+
|
87
|
+
def setter_builder
|
88
|
+
vargen = VariableNameGenerator.new
|
89
|
+
argument_info = SetterArgumentInfo.new "value", @info.field_type
|
90
|
+
ArgumentBuilder.new vargen, argument_info
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|