gir_ffi 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +7 -0
- data/Gemfile +2 -1
- data/README.md +6 -0
- data/TODO.md +1 -0
- data/examples/clutter.rb +106 -0
- data/examples/main_loop.rb +0 -8
- data/lib/ffi-glib/array.rb +1 -0
- data/lib/ffi-glib/array_methods.rb +1 -0
- data/lib/ffi-glib/byte_array.rb +1 -0
- data/lib/ffi-glib/bytes.rb +1 -0
- data/lib/ffi-glib/container_class_methods.rb +1 -0
- data/lib/ffi-glib/destroy_notify.rb +1 -0
- data/lib/ffi-glib/error.rb +1 -0
- data/lib/ffi-glib/hash_table.rb +2 -1
- data/lib/ffi-glib/iconv.rb +1 -0
- data/lib/ffi-glib/list.rb +1 -0
- data/lib/ffi-glib/list_methods.rb +1 -0
- data/lib/ffi-glib/main_loop.rb +1 -0
- data/lib/ffi-glib/ptr_array.rb +1 -0
- data/lib/ffi-glib/s_list.rb +1 -0
- data/lib/ffi-glib/strv.rb +1 -0
- data/lib/ffi-glib/variant.rb +1 -0
- data/lib/ffi-glib.rb +1 -0
- data/lib/ffi-gobject/base.rb +1 -0
- data/lib/ffi-gobject/closure.rb +1 -0
- data/lib/ffi-gobject/initially_unowned.rb +1 -0
- data/lib/ffi-gobject/object.rb +1 -0
- data/lib/ffi-gobject/object_class.rb +1 -0
- data/lib/ffi-gobject/ruby_closure.rb +1 -0
- data/lib/ffi-gobject/value.rb +1 -0
- data/lib/ffi-gobject.rb +1 -0
- data/lib/ffi-gobject_introspection/g_error.rb +1 -0
- data/lib/ffi-gobject_introspection/i_arg_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_base_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_callable_info.rb +5 -0
- data/lib/ffi-gobject_introspection/i_callback_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_constant_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_field_info.rb +3 -2
- data/lib/ffi-gobject_introspection/i_flags_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_function_info.rb +7 -7
- data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_object_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_property_info.rb +5 -4
- data/lib/ffi-gobject_introspection/i_registered_type_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_repository.rb +1 -0
- data/lib/ffi-gobject_introspection/i_signal_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_struct_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_type_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_union_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_unresolved_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_value_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_vfunc_info.rb +1 -0
- data/lib/ffi-gobject_introspection/lib.rb +27 -10
- data/lib/ffi-gobject_introspection.rb +1 -0
- data/lib/gir_ffi/allocation_helper.rb +1 -0
- data/lib/gir_ffi/arg_helper.rb +1 -0
- data/lib/gir_ffi/boxed_base.rb +1 -0
- data/lib/gir_ffi/builder.rb +1 -0
- data/lib/gir_ffi/builder_helper.rb +1 -0
- data/lib/gir_ffi/builders/argument_builder.rb +18 -6
- data/lib/gir_ffi/builders/argument_builder_collection.rb +24 -12
- data/lib/gir_ffi/builders/base_argument_builder.rb +1 -0
- data/lib/gir_ffi/builders/base_method_builder.rb +33 -9
- data/lib/gir_ffi/builders/base_type_builder.rb +1 -0
- data/lib/gir_ffi/builders/boxed_builder.rb +1 -0
- data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +1 -0
- data/lib/gir_ffi/builders/callback_argument_builder.rb +5 -0
- data/lib/gir_ffi/builders/callback_builder.rb +2 -5
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +1 -0
- data/lib/gir_ffi/builders/closure_argument_builder.rb +1 -0
- data/lib/gir_ffi/builders/closure_convertor.rb +1 -0
- data/lib/gir_ffi/builders/closure_return_value_builder.rb +1 -0
- data/lib/gir_ffi/builders/closure_to_pointer_convertor.rb +1 -0
- data/lib/gir_ffi/builders/constant_builder.rb +1 -0
- data/lib/gir_ffi/builders/constructor_builder.rb +2 -0
- data/lib/gir_ffi/builders/enum_builder.rb +2 -1
- data/lib/gir_ffi/builders/field_builder.rb +2 -0
- data/lib/gir_ffi/builders/flags_builder.rb +2 -1
- data/lib/gir_ffi/builders/full_c_to_ruby_convertor.rb +1 -0
- data/lib/gir_ffi/builders/function_builder.rb +2 -3
- data/lib/gir_ffi/builders/initializer_builder.rb +2 -3
- data/lib/gir_ffi/builders/initializer_return_value_builder.rb +1 -0
- data/lib/gir_ffi/builders/interface_builder.rb +1 -0
- data/lib/gir_ffi/builders/mapping_method_builder.rb +15 -37
- data/lib/gir_ffi/builders/marshalling_method_builder.rb +9 -26
- data/lib/gir_ffi/builders/method_template.rb +4 -3
- data/lib/gir_ffi/builders/module_builder.rb +2 -1
- data/lib/gir_ffi/builders/null_argument_builder.rb +1 -0
- data/lib/gir_ffi/builders/null_class_builder.rb +1 -0
- data/lib/gir_ffi/builders/null_convertor.rb +1 -0
- data/lib/gir_ffi/builders/null_return_value_builder.rb +1 -0
- data/lib/gir_ffi/builders/object_builder.rb +1 -0
- data/lib/gir_ffi/builders/property_builder.rb +1 -0
- data/lib/gir_ffi/builders/registered_type_builder.rb +1 -0
- data/lib/gir_ffi/builders/return_value_builder.rb +1 -0
- data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +1 -0
- data/lib/gir_ffi/builders/signal_closure_builder.rb +2 -7
- data/lib/gir_ffi/builders/struct_builder.rb +1 -0
- data/lib/gir_ffi/builders/type_builder.rb +1 -0
- data/lib/gir_ffi/builders/unintrospectable_boxed_builder.rb +1 -0
- data/lib/gir_ffi/builders/unintrospectable_builder.rb +1 -0
- data/lib/gir_ffi/builders/union_builder.rb +1 -0
- data/lib/gir_ffi/builders/user_defined_builder.rb +1 -0
- data/lib/gir_ffi/builders/vfunc_argument_builder.rb +1 -0
- data/lib/gir_ffi/builders/vfunc_builder.rb +2 -9
- data/lib/gir_ffi/builders/with_layout.rb +1 -0
- data/lib/gir_ffi/callback_base.rb +1 -0
- data/lib/gir_ffi/class_base.rb +1 -0
- data/lib/gir_ffi/core.rb +1 -0
- data/lib/gir_ffi/enum_base.rb +1 -0
- data/lib/gir_ffi/error_argument_info.rb +1 -0
- data/lib/gir_ffi/error_type_info.rb +1 -0
- data/lib/gir_ffi/ffi_ext/pointer.rb +1 -0
- data/lib/gir_ffi/ffi_ext.rb +1 -0
- data/lib/gir_ffi/field_argument_info.rb +1 -0
- data/lib/gir_ffi/flags_base.rb +1 -0
- data/lib/gir_ffi/g_type.rb +1 -0
- data/lib/gir_ffi/glib_error.rb +1 -0
- data/lib/gir_ffi/in_out_pointer.rb +1 -0
- data/lib/gir_ffi/in_pointer.rb +1 -0
- data/lib/gir_ffi/info_ext/full_type_name.rb +1 -0
- data/lib/gir_ffi/info_ext/i_arg_info.rb +1 -0
- data/lib/gir_ffi/info_ext/i_callable_info.rb +1 -0
- data/lib/gir_ffi/info_ext/i_callback_info.rb +1 -0
- data/lib/gir_ffi/info_ext/i_field_info.rb +1 -0
- data/lib/gir_ffi/info_ext/i_function_info.rb +1 -0
- data/lib/gir_ffi/info_ext/i_property_info.rb +1 -0
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +1 -0
- data/lib/gir_ffi/info_ext/i_signal_info.rb +1 -0
- data/lib/gir_ffi/info_ext/i_type_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_unresolved_info.rb +1 -0
- data/lib/gir_ffi/info_ext/i_vfunc_info.rb +1 -0
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +1 -0
- data/lib/gir_ffi/info_ext/safe_function_name.rb +1 -0
- data/lib/gir_ffi/info_ext.rb +1 -0
- data/lib/gir_ffi/interface_base.rb +1 -0
- data/lib/gir_ffi/lib_c.rb +1 -0
- data/lib/gir_ffi/method_stubber.rb +1 -0
- data/lib/gir_ffi/module_base.rb +1 -0
- data/lib/gir_ffi/object_base.rb +1 -0
- data/lib/gir_ffi/object_store.rb +1 -0
- data/lib/gir_ffi/property_not_found_error.rb +1 -0
- data/lib/gir_ffi/receiver_argument_info.rb +1 -0
- data/lib/gir_ffi/receiver_type_info.rb +1 -0
- data/lib/gir_ffi/registered_type_base.rb +1 -0
- data/lib/gir_ffi/return_value_info.rb +1 -0
- data/lib/gir_ffi/signal_not_found_error.rb +1 -0
- data/lib/gir_ffi/sized_array.rb +1 -0
- data/lib/gir_ffi/struct_base.rb +1 -0
- data/lib/gir_ffi/type_base.rb +1 -0
- data/lib/gir_ffi/type_map.rb +1 -0
- data/lib/gir_ffi/unintrospectable_signal_info.rb +1 -0
- data/lib/gir_ffi/unintrospectable_type_info.rb +1 -0
- data/lib/gir_ffi/union_base.rb +1 -0
- data/lib/gir_ffi/user_data_argument_info.rb +1 -0
- data/lib/gir_ffi/user_data_type_info.rb +1 -0
- data/lib/gir_ffi/user_defined_property_info.rb +1 -0
- data/lib/gir_ffi/user_defined_type_info.rb +1 -0
- data/lib/gir_ffi/variable_name_generator.rb +1 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi/vfunc_implementation.rb +1 -0
- data/lib/gir_ffi/zero_terminated.rb +1 -0
- data/lib/gir_ffi-base/glib/boolean.rb +1 -0
- data/lib/gir_ffi-base/glib/strv.rb +1 -0
- data/lib/gir_ffi-base/gobject/lib.rb +1 -0
- data/lib/gir_ffi-base/gobject.rb +1 -0
- data/lib/gir_ffi-base.rb +1 -0
- data/lib/gir_ffi.rb +1 -0
- data/test/base_test_helper.rb +1 -0
- data/test/ffi-glib/array_test.rb +1 -0
- data/test/ffi-glib/byte_array_test.rb +1 -0
- data/test/ffi-glib/bytes_test.rb +1 -0
- data/test/ffi-glib/destroy_notify_test.rb +1 -0
- data/test/ffi-glib/hash_table_test.rb +1 -0
- data/test/ffi-glib/iconv_test.rb +1 -0
- data/test/ffi-glib/list_test.rb +1 -0
- data/test/ffi-glib/main_loop_test.rb +1 -0
- data/test/ffi-glib/ptr_array_test.rb +1 -0
- data/test/ffi-glib/ruby_closure_test.rb +1 -0
- data/test/ffi-glib/s_list_test.rb +1 -0
- data/test/ffi-glib/strv_test.rb +1 -0
- data/test/ffi-glib/variant_test.rb +1 -0
- data/test/ffi-gobject/gobject_test.rb +1 -0
- data/test/ffi-gobject/object_class_test.rb +1 -0
- data/test/ffi-gobject/object_test.rb +1 -0
- data/test/ffi-gobject/value_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_base_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_constant_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_function_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_interface_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_object_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_property_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_registered_type_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_repository_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_struct_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_type_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/i_union_info_test.rb +1 -0
- data/test/ffi-gobject_introspection/lib_test.rb +1 -0
- data/test/ffi-gobject_test.rb +1 -0
- data/test/gir_ffi/arg_helper_test.rb +1 -0
- data/test/gir_ffi/builder_test.rb +1 -0
- data/test/gir_ffi/builders/argument_builder_test.rb +17 -0
- data/test/gir_ffi/builders/base_argument_builder_test.rb +1 -0
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +1 -0
- data/test/gir_ffi/builders/callback_builder_test.rb +1 -0
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +1 -0
- data/test/gir_ffi/builders/constant_builder_test.rb +1 -0
- data/test/gir_ffi/builders/constructor_builder_test.rb +1 -0
- data/test/gir_ffi/builders/enum_builder_test.rb +1 -0
- data/test/gir_ffi/builders/field_builder_test.rb +1 -0
- data/test/gir_ffi/builders/function_builder_test.rb +30 -1
- data/test/gir_ffi/builders/initializer_builder_test.rb +1 -0
- data/test/gir_ffi/builders/interface_builder_test.rb +1 -0
- data/test/gir_ffi/builders/module_builder_test.rb +1 -0
- data/test/gir_ffi/builders/object_builder_test.rb +1 -0
- data/test/gir_ffi/builders/property_builder_test.rb +1 -0
- data/test/gir_ffi/builders/registered_type_builder_test.rb +1 -0
- data/test/gir_ffi/builders/return_value_builder_test.rb +1 -0
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +1 -0
- data/test/gir_ffi/builders/struct_builder_test.rb +1 -0
- data/test/gir_ffi/builders/unintrospectable_boxed_builder_test.rb +1 -0
- data/test/gir_ffi/builders/unintrospectable_builder_test.rb +1 -0
- data/test/gir_ffi/builders/union_builder_test.rb +1 -0
- data/test/gir_ffi/builders/user_defined_builder_test.rb +1 -0
- data/test/gir_ffi/builders/vfunc_builder_test.rb +1 -0
- data/test/gir_ffi/callback_base_test.rb +1 -0
- data/test/gir_ffi/class_base_test.rb +1 -0
- data/test/gir_ffi/error_type_info_test.rb +1 -0
- data/test/gir_ffi/ffi_ext/pointer_test.rb +1 -0
- data/test/gir_ffi/g_type_test.rb +1 -0
- data/test/gir_ffi/in_out_pointer_test.rb +1 -0
- data/test/gir_ffi/in_pointer_test.rb +1 -0
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +1 -0
- data/test/gir_ffi/info_ext/i_callback_info_test.rb +1 -0
- data/test/gir_ffi/info_ext/i_field_info_test.rb +1 -0
- data/test/gir_ffi/info_ext/i_function_info_test.rb +1 -0
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +1 -0
- data/test/gir_ffi/info_ext/i_type_info_test.rb +1 -0
- data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +1 -0
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +1 -0
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +1 -0
- data/test/gir_ffi/interface_base_test.rb +1 -0
- data/test/gir_ffi/method_stubber_test.rb +1 -0
- data/test/gir_ffi/object_base_test.rb +1 -0
- data/test/gir_ffi/sized_array_test.rb +1 -0
- data/test/gir_ffi/type_map_test.rb +1 -0
- data/test/gir_ffi/unintrospectable_type_info_test.rb +1 -0
- data/test/gir_ffi/user_defined_property_info_test.rb +1 -0
- data/test/gir_ffi/user_defined_type_info_test.rb +1 -0
- data/test/gir_ffi/variable_name_generator_test.rb +1 -0
- data/test/gir_ffi/version_test.rb +1 -0
- data/test/gir_ffi/zero_terminated_test.rb +1 -0
- data/test/gir_ffi-base/glib/boolean_test.rb +2 -1
- data/test/gir_ffi-base/glib/strv_test.rb +1 -0
- data/test/gir_ffi_test.rb +1 -0
- data/test/gir_ffi_test_helper.rb +1 -0
- data/test/integration/callback_exceptions_test.rb +1 -0
- data/test/integration/derived_classes_test.rb +1 -0
- data/test/integration/generated_everything_test.rb +1 -0
- data/test/integration/generated_gimarshallingtests_test.rb +1 -0
- data/test/integration/generated_gio_test.rb +1 -0
- data/test/integration/generated_glib_test.rb +1 -0
- data/test/integration/generated_gobject_test.rb +1 -0
- data/test/integration/generated_gst_test.rb +1 -0
- data/test/integration/generated_gtop_test.rb +1 -0
- data/test/integration/generated_pango_ft2_test.rb +1 -0
- data/test/integration/generated_pango_test.rb +1 -0
- data/test/integration/generated_regress_test.rb +2 -2
- data/test/integration/generated_secret_test.rb +1 -0
- data/test/integration/generated_warnlib_test.rb +1 -0
- data/test/integration/method_lookup_test.rb +1 -0
- data/test/introspection_test_helper.rb +1 -0
- data/test/minitest/stats_plugin.rb +1 -0
- metadata +19 -19
- data/lib/gir_ffi/builders/error_argument_builder.rb +0 -34
data/lib/gir_ffi/arg_helper.rb
CHANGED
data/lib/gir_ffi/boxed_base.rb
CHANGED
data/lib/gir_ffi/builder.rb
CHANGED
@@ -18,6 +18,10 @@ module GirFFI
|
|
18
18
|
specialized_type_tag == :callback
|
19
19
|
end
|
20
20
|
|
21
|
+
def allow_none?
|
22
|
+
arginfo.may_be_null?
|
23
|
+
end
|
24
|
+
|
21
25
|
def post_converted_name
|
22
26
|
@post_converted_name ||= if has_post_conversion?
|
23
27
|
new_variable
|
@@ -38,24 +42,28 @@ module GirFFI
|
|
38
42
|
|
39
43
|
def pre_conversion
|
40
44
|
pr = []
|
41
|
-
|
42
|
-
when :in
|
45
|
+
if has_ingoing_component?
|
43
46
|
pr << fixed_array_size_check if needs_size_check?
|
44
47
|
pr << array_length_assignment if array_length_parameter?
|
48
|
+
end
|
49
|
+
case direction
|
50
|
+
when :in
|
45
51
|
pr << "#{call_argument_name} = #{ingoing_convertor.conversion}"
|
46
52
|
when :inout
|
47
|
-
pr << fixed_array_size_check if needs_size_check?
|
48
|
-
pr << array_length_assignment if array_length_parameter?
|
49
53
|
pr << out_parameter_preparation
|
50
54
|
pr << "#{call_argument_name}.set_value #{ingoing_convertor.conversion}"
|
51
55
|
when :out
|
52
56
|
pr << out_parameter_preparation
|
57
|
+
when :error
|
58
|
+
pr << "#{call_argument_name} = FFI::MemoryPointer.new(:pointer).write_pointer nil"
|
53
59
|
end
|
54
60
|
pr
|
55
61
|
end
|
56
62
|
|
57
63
|
def post_conversion
|
58
|
-
if
|
64
|
+
if direction == :error
|
65
|
+
["GirFFI::ArgHelper.check_error(#{call_argument_name})"]
|
66
|
+
elsif has_post_conversion?
|
59
67
|
value = output_value
|
60
68
|
["#{post_converted_name} = #{value}"]
|
61
69
|
else
|
@@ -122,7 +130,11 @@ module GirFFI
|
|
122
130
|
end
|
123
131
|
|
124
132
|
def has_input_value?
|
125
|
-
|
133
|
+
has_ingoing_component? && !skipped?
|
134
|
+
end
|
135
|
+
|
136
|
+
def has_ingoing_component?
|
137
|
+
(direction == :inout || direction == :in)
|
126
138
|
end
|
127
139
|
|
128
140
|
def array_length_assignment
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GirFFI
|
2
3
|
module Builders
|
3
4
|
# Class representing the argument and return value builders for a method,
|
@@ -36,18 +37,10 @@ module GirFFI
|
|
36
37
|
def method_argument_names
|
37
38
|
@method_argument_names ||=
|
38
39
|
begin
|
39
|
-
base =
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
if !block && it.block_argument?
|
44
|
-
block = "&#{name}"
|
45
|
-
else
|
46
|
-
base << name
|
47
|
-
end
|
48
|
-
end
|
49
|
-
base << block if block
|
50
|
-
base.compact
|
40
|
+
base, block = split_off_block_argument
|
41
|
+
args = base_argument_names(base)
|
42
|
+
args << "&#{block.method_argument_name}" if block
|
43
|
+
args
|
51
44
|
end
|
52
45
|
end
|
53
46
|
|
@@ -117,6 +110,25 @@ module GirFFI
|
|
117
110
|
@sorted_base_argument_builders ||= @base_argument_builders.
|
118
111
|
sort_by.with_index { |arg, i| [arg.array_length_idx, i] }
|
119
112
|
end
|
113
|
+
|
114
|
+
def split_off_block_argument
|
115
|
+
builders_with_name = argument_builders.select(&:method_argument_name)
|
116
|
+
blocks, base = builders_with_name.partition(&:block_argument?)
|
117
|
+
return base, blocks.first
|
118
|
+
end
|
119
|
+
|
120
|
+
def base_argument_names(arguments)
|
121
|
+
required_found = false
|
122
|
+
arguments.reverse.map do |it|
|
123
|
+
name = it.method_argument_name
|
124
|
+
if it.allow_none? && !required_found
|
125
|
+
"#{name} = nil"
|
126
|
+
else
|
127
|
+
required_found = true
|
128
|
+
name
|
129
|
+
end
|
130
|
+
end.compact.reverse
|
131
|
+
end
|
120
132
|
end
|
121
133
|
end
|
122
134
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/builders/argument_builder'
|
2
3
|
require 'gir_ffi/builders/argument_builder_collection'
|
3
|
-
require 'gir_ffi/builders/error_argument_builder'
|
4
4
|
require 'gir_ffi/builders/method_template'
|
5
5
|
require 'gir_ffi/builders/null_argument_builder'
|
6
6
|
require 'gir_ffi/error_argument_info'
|
@@ -11,8 +11,17 @@ module GirFFI
|
|
11
11
|
module Builders
|
12
12
|
# Base class for method definition builders.
|
13
13
|
class BaseMethodBuilder
|
14
|
-
def
|
15
|
-
|
14
|
+
def initialize(info, return_value_builder_class,
|
15
|
+
receiver_info: nil,
|
16
|
+
argument_builder_class: ArgumentBuilder)
|
17
|
+
@info = info
|
18
|
+
@return_value_builder_class = return_value_builder_class
|
19
|
+
@argument_builder_class = argument_builder_class
|
20
|
+
@receiver_info = receiver_info
|
21
|
+
end
|
22
|
+
|
23
|
+
def variable_generator
|
24
|
+
@variable_generator ||= VariableNameGenerator.new
|
16
25
|
end
|
17
26
|
|
18
27
|
def method_definition
|
@@ -26,7 +35,8 @@ module GirFFI
|
|
26
35
|
# Methods used for setting up the builders
|
27
36
|
|
28
37
|
def argument_builders
|
29
|
-
@argument_builders ||=
|
38
|
+
@argument_builders ||=
|
39
|
+
@info.args.map { |arg| make_argument_builder arg }
|
30
40
|
end
|
31
41
|
|
32
42
|
def return_value_info
|
@@ -35,16 +45,26 @@ module GirFFI
|
|
35
45
|
@info.skip_return?)
|
36
46
|
end
|
37
47
|
|
48
|
+
def return_value_builder
|
49
|
+
@return_value_builder = @return_value_builder_class.new(variable_generator,
|
50
|
+
return_value_info)
|
51
|
+
end
|
52
|
+
|
53
|
+
def receiver_builder
|
54
|
+
@receiver_builder ||= @receiver_info ? make_argument_builder(@receiver_info) : nil
|
55
|
+
end
|
56
|
+
|
38
57
|
def argument_builder_collection
|
39
|
-
@argument_builder_collection ||=
|
40
|
-
|
41
|
-
|
58
|
+
@argument_builder_collection ||=
|
59
|
+
ArgumentBuilderCollection.new(return_value_builder, argument_builders,
|
60
|
+
error_argument_builder: error_argument,
|
61
|
+
receiver_builder: receiver_builder)
|
42
62
|
end
|
43
63
|
|
44
64
|
def error_argument
|
45
65
|
@error_argument ||=
|
46
|
-
if @info.
|
47
|
-
|
66
|
+
if @info.can_throw_gerror?
|
67
|
+
make_argument_builder ErrorArgumentInfo.new
|
48
68
|
else
|
49
69
|
NullArgumentBuilder.new
|
50
70
|
end
|
@@ -69,6 +89,10 @@ module GirFFI
|
|
69
89
|
def lib_name
|
70
90
|
"#{@info.safe_namespace}::Lib"
|
71
91
|
end
|
92
|
+
|
93
|
+
def make_argument_builder(argument_info)
|
94
|
+
@argument_builder_class.new variable_generator, argument_info
|
95
|
+
end
|
72
96
|
end
|
73
97
|
end
|
74
98
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/builders/base_argument_builder'
|
2
3
|
require 'gir_ffi/builders/c_to_ruby_convertor'
|
3
4
|
require 'gir_ffi/builders/closure_convertor'
|
@@ -16,6 +17,10 @@ module GirFFI
|
|
16
17
|
false
|
17
18
|
end
|
18
19
|
|
20
|
+
def allow_none?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
19
24
|
def pre_converted_name
|
20
25
|
@pre_converted_name ||= new_variable
|
21
26
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/builders/base_type_builder'
|
2
3
|
require 'gir_ffi/builders/mapping_method_builder'
|
3
4
|
require 'gir_ffi/callback_base'
|
@@ -25,11 +26,7 @@ module GirFFI
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def mapping_method_definition
|
28
|
-
|
29
|
-
info.caller_owns,
|
30
|
-
info.skip_return?)
|
31
|
-
MappingMethodBuilder.for_callback(info.args,
|
32
|
-
return_value_info).method_definition
|
29
|
+
MappingMethodBuilder.for_callback(info).method_definition
|
33
30
|
end
|
34
31
|
|
35
32
|
def callback_sym
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/builders/argument_builder_collection'
|
2
3
|
require 'gir_ffi/builders/method_template'
|
3
4
|
require 'gir_ffi/builders/null_return_value_builder'
|
@@ -6,6 +7,7 @@ module GirFFI
|
|
6
7
|
module Builders
|
7
8
|
# Implements the creation of a Ruby constructor definition out of a
|
8
9
|
# GIR IFunctionInfo.
|
10
|
+
# TODO: Derive from BaseMethodBuilder
|
9
11
|
class ConstructorBuilder
|
10
12
|
def initialize(info)
|
11
13
|
@info = info
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/builders/registered_type_builder'
|
2
3
|
require 'gir_ffi/enum_base'
|
3
4
|
|
@@ -14,7 +15,7 @@ module GirFFI
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def value_spec
|
17
|
-
info.values.map do|vinfo|
|
18
|
+
info.values.map do |vinfo|
|
18
19
|
val = GirFFI::ArgHelper.cast_uint32_to_int32(vinfo.value)
|
19
20
|
[vinfo.name.to_sym, val]
|
20
21
|
end.flatten
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/builders/argument_builder'
|
2
3
|
require 'gir_ffi/variable_name_generator'
|
3
4
|
require 'gir_ffi/field_argument_info'
|
@@ -124,6 +125,7 @@ module GirFFI
|
|
124
125
|
end
|
125
126
|
|
126
127
|
# Builder for field getters
|
128
|
+
# TODO: Derive from BaseMethodBuilder
|
127
129
|
class GetterBuilder
|
128
130
|
def initialize(info)
|
129
131
|
@info = info
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/builders/enum_builder'
|
2
3
|
require 'gir_ffi/flags_base'
|
3
4
|
|
@@ -14,7 +15,7 @@ module GirFFI
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def value_spec
|
17
|
-
info.values.map do|vinfo|
|
18
|
+
info.values.map do |vinfo|
|
18
19
|
val = GirFFI::ArgHelper.cast_uint32_to_int32(vinfo.value)
|
19
20
|
{ vinfo.name.to_sym => val }
|
20
21
|
end.reduce(:merge)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/builders/return_value_builder'
|
2
3
|
require 'gir_ffi/builders/base_method_builder'
|
3
4
|
|
@@ -7,9 +8,7 @@ module GirFFI
|
|
7
8
|
# IFunctionInfo.
|
8
9
|
class FunctionBuilder < BaseMethodBuilder
|
9
10
|
def initialize(info)
|
10
|
-
|
11
|
-
@return_value_builder = ReturnValueBuilder.new(vargen,
|
12
|
-
return_value_info)
|
11
|
+
super(info, ReturnValueBuilder)
|
13
12
|
end
|
14
13
|
|
15
14
|
def method_name
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/builders/initializer_return_value_builder'
|
2
3
|
require 'gir_ffi/builders/base_method_builder'
|
3
4
|
|
@@ -7,9 +8,7 @@ module GirFFI
|
|
7
8
|
# GIR IFunctionInfo.
|
8
9
|
class InitializerBuilder < BaseMethodBuilder
|
9
10
|
def initialize(info)
|
10
|
-
|
11
|
-
@return_value_builder = InitializerReturnValueBuilder.new(vargen,
|
12
|
-
return_value_info)
|
11
|
+
super(info, InitializerReturnValueBuilder)
|
13
12
|
end
|
14
13
|
|
15
14
|
def singleton_method?
|
@@ -1,42 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/variable_name_generator'
|
2
3
|
require 'gir_ffi/builders/callback_argument_builder'
|
3
4
|
require 'gir_ffi/builders/vfunc_argument_builder'
|
4
5
|
require 'gir_ffi/builders/callback_return_value_builder'
|
5
6
|
require 'gir_ffi/builders/argument_builder_collection'
|
6
|
-
require 'gir_ffi/builders/
|
7
|
+
require 'gir_ffi/builders/base_method_builder'
|
7
8
|
|
8
9
|
module GirFFI
|
9
10
|
module Builders
|
10
11
|
# Implements the creation mapping method for a callback or vfunc
|
11
12
|
# handler. This method converts arguments from C to Ruby, and the
|
12
13
|
# result from Ruby to C.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def self.for_callback(argument_infos, return_value_info)
|
17
|
-
new nil, argument_infos, return_value_info, CallbackArgumentBuilder
|
14
|
+
class MappingMethodBuilder < BaseMethodBuilder
|
15
|
+
def self.for_callback(info)
|
16
|
+
new nil, info, CallbackArgumentBuilder
|
18
17
|
end
|
19
18
|
|
20
|
-
def self.for_vfunc(receiver_info,
|
21
|
-
new receiver_info,
|
19
|
+
def self.for_vfunc(receiver_info, info)
|
20
|
+
new receiver_info, info, VFuncArgumentBuilder
|
22
21
|
end
|
23
22
|
|
24
|
-
def initialize(receiver_info,
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
return_value_builder =
|
29
|
-
CallbackReturnValueBuilder.new(variable_generator, return_value_info)
|
30
|
-
|
31
|
-
@argument_builder_collection =
|
32
|
-
ArgumentBuilderCollection.new(return_value_builder, argument_builders,
|
33
|
-
receiver_builder: receiver_builder)
|
34
|
-
@template = MethodTemplate.new(self, @argument_builder_collection)
|
23
|
+
def initialize(receiver_info, info, builder_class)
|
24
|
+
super(info, CallbackReturnValueBuilder,
|
25
|
+
receiver_info: receiver_info,
|
26
|
+
argument_builder_class: builder_class)
|
35
27
|
end
|
36
28
|
|
37
|
-
|
38
|
-
@template.method_definition
|
39
|
-
end
|
29
|
+
## Methods used by MethodTemplate
|
40
30
|
|
41
31
|
def method_name
|
42
32
|
'call_with_argument_mapping'
|
@@ -44,11 +34,7 @@ module GirFFI
|
|
44
34
|
|
45
35
|
def method_arguments
|
46
36
|
@method_arguments ||=
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def preparation
|
51
|
-
[]
|
37
|
+
argument_builder_collection.method_argument_names.dup.unshift('_proc')
|
52
38
|
end
|
53
39
|
|
54
40
|
def invocation
|
@@ -56,7 +42,7 @@ module GirFFI
|
|
56
42
|
end
|
57
43
|
|
58
44
|
def result
|
59
|
-
if (name =
|
45
|
+
if (name = argument_builder_collection.return_value_name)
|
60
46
|
["return #{name}"]
|
61
47
|
else
|
62
48
|
[]
|
@@ -70,15 +56,7 @@ module GirFFI
|
|
70
56
|
private
|
71
57
|
|
72
58
|
def call_argument_list
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
def variable_generator
|
77
|
-
@variable_generator ||= VariableNameGenerator.new
|
78
|
-
end
|
79
|
-
|
80
|
-
def make_argument_builder(argument_info)
|
81
|
-
@argument_builder_class.new variable_generator, argument_info
|
59
|
+
argument_builder_collection.call_argument_names.join(', ')
|
82
60
|
end
|
83
61
|
end
|
84
62
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/variable_name_generator'
|
2
3
|
require 'gir_ffi/builders/closure_argument_builder'
|
3
4
|
require 'gir_ffi/builders/closure_return_value_builder'
|
@@ -9,28 +10,18 @@ module GirFFI
|
|
9
10
|
# Implements the creation mapping method for a signal
|
10
11
|
# handler. This method converts arguments from C to Ruby, and the
|
11
12
|
# result from Ruby to C.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def self.for_signal(receiver_info, argument_infos, return_value_info)
|
16
|
-
new receiver_info, argument_infos, return_value_info
|
13
|
+
class MarshallingMethodBuilder < BaseMethodBuilder
|
14
|
+
def self.for_signal(receiver_info, info)
|
15
|
+
new receiver_info, info
|
17
16
|
end
|
18
17
|
|
19
|
-
def initialize(receiver_info,
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
ClosureReturnValueBuilder.new(variable_generator, return_value_info)
|
24
|
-
|
25
|
-
@argument_builder_collection =
|
26
|
-
ArgumentBuilderCollection.new(return_value_builder, argument_builders,
|
27
|
-
receiver_builder: receiver_builder)
|
28
|
-
@template = MethodTemplate.new(self, @argument_builder_collection)
|
18
|
+
def initialize(receiver_info, info)
|
19
|
+
super(info, ClosureReturnValueBuilder,
|
20
|
+
receiver_info: receiver_info,
|
21
|
+
argument_builder_class: ClosureArgumentBuilder)
|
29
22
|
end
|
30
23
|
|
31
|
-
|
32
|
-
@template.method_definition
|
33
|
-
end
|
24
|
+
## Methods used by MethodTemplate
|
34
25
|
|
35
26
|
def method_name
|
36
27
|
'marshaller'
|
@@ -73,14 +64,6 @@ module GirFFI
|
|
73
64
|
def param_names
|
74
65
|
@param_names ||= @argument_builder_collection.method_argument_names
|
75
66
|
end
|
76
|
-
|
77
|
-
def variable_generator
|
78
|
-
@variable_generator ||= VariableNameGenerator.new
|
79
|
-
end
|
80
|
-
|
81
|
-
def make_argument_builder(argument_info)
|
82
|
-
ClosureArgumentBuilder.new variable_generator, argument_info
|
83
|
-
end
|
84
67
|
end
|
85
68
|
end
|
86
69
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GirFFI
|
2
3
|
module Builders
|
3
4
|
# Encapsulates the general structure of generated methods, consisting of a
|
@@ -17,9 +18,9 @@ module GirFFI
|
|
17
18
|
|
18
19
|
def method_definition
|
19
20
|
code = "def #{qualified_method_name}"
|
20
|
-
code
|
21
|
-
method_lines.each { |line| code
|
22
|
-
code
|
21
|
+
code += "(#{method_arguments.join(', ')})" if method_arguments.any?
|
22
|
+
method_lines.each { |line| code += "\n #{line}" }
|
23
|
+
code + "\nend\n"
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gir_ffi/builder_helper'
|
2
3
|
require 'gir_ffi/module_base'
|
3
4
|
require 'gir_ffi/builders/function_builder'
|
@@ -62,7 +63,7 @@ module GirFFI
|
|
62
63
|
|
63
64
|
def build_dependencies
|
64
65
|
deps = gir.dependencies @namespace
|
65
|
-
deps.each do|dep|
|
66
|
+
deps.each do |dep|
|
66
67
|
name, version = dep.split '-'
|
67
68
|
Builder.build_module name, version
|
68
69
|
end
|