gir_ffi 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +7 -0
  3. data/TODO.md +8 -0
  4. data/lib/ffi-glib/array.rb +7 -7
  5. data/lib/ffi-glib/byte_array.rb +3 -4
  6. data/lib/ffi-glib/bytes.rb +3 -3
  7. data/lib/ffi-glib/error.rb +2 -2
  8. data/lib/ffi-glib/hash_table.rb +7 -7
  9. data/lib/ffi-glib/iconv.rb +3 -4
  10. data/lib/ffi-glib/list.rb +3 -3
  11. data/lib/ffi-glib/list_methods.rb +3 -3
  12. data/lib/ffi-glib/ptr_array.rb +6 -6
  13. data/lib/ffi-glib/s_list.rb +3 -3
  14. data/lib/ffi-glib/strv.rb +3 -3
  15. data/lib/ffi-glib/variant.rb +6 -2
  16. data/lib/ffi-glib.rb +3 -0
  17. data/lib/ffi-gobject/base.rb +1 -0
  18. data/lib/ffi-gobject/closure.rb +2 -2
  19. data/lib/ffi-gobject/initially_unowned.rb +4 -3
  20. data/lib/ffi-gobject/object.rb +5 -5
  21. data/lib/ffi-gobject/object_class.rb +2 -2
  22. data/lib/ffi-gobject/ruby_closure.rb +2 -3
  23. data/lib/ffi-gobject/value.rb +5 -5
  24. data/lib/ffi-gobject.rb +17 -22
  25. data/lib/ffi-gobject_introspection/i_arg_info.rb +0 -1
  26. data/lib/ffi-gobject_introspection/i_base_info.rb +3 -4
  27. data/lib/ffi-gobject_introspection/i_callable_info.rb +1 -2
  28. data/lib/ffi-gobject_introspection/i_constant_info.rb +19 -11
  29. data/lib/ffi-gobject_introspection/i_enum_info.rb +4 -3
  30. data/lib/ffi-gobject_introspection/i_function_info.rb +7 -1
  31. data/lib/ffi-gobject_introspection/i_interface_info.rb +12 -0
  32. data/lib/ffi-gobject_introspection/i_object_info.rb +19 -8
  33. data/lib/ffi-gobject_introspection/i_registered_type_info.rb +0 -1
  34. data/lib/ffi-gobject_introspection/i_repository.rb +10 -15
  35. data/lib/ffi-gobject_introspection/i_struct_info.rb +4 -2
  36. data/lib/ffi-gobject_introspection/i_type_info.rb +4 -2
  37. data/lib/ffi-gobject_introspection/i_union_info.rb +7 -3
  38. data/lib/ffi-gobject_introspection/i_value_info.rb +0 -1
  39. data/lib/ffi-gobject_introspection/lib.rb +1 -2
  40. data/lib/ffi-gobject_introspection.rb +0 -1
  41. data/lib/gir_ffi/allocation_helper.rb +2 -1
  42. data/lib/gir_ffi/arg_helper.rb +6 -2
  43. data/lib/gir_ffi/builder_helper.rb +1 -0
  44. data/lib/gir_ffi/builders/argument_builder_collection.rb +67 -0
  45. data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +2 -0
  46. data/lib/gir_ffi/builders/callback_argument_builder.rb +7 -5
  47. data/lib/gir_ffi/builders/callback_builder.rb +3 -1
  48. data/lib/gir_ffi/builders/callback_return_value_builder.rb +2 -0
  49. data/lib/gir_ffi/builders/closure_argument_builder.rb +13 -0
  50. data/lib/gir_ffi/builders/closure_convertor.rb +2 -0
  51. data/lib/gir_ffi/builders/closure_to_pointer_convertor.rb +2 -0
  52. data/lib/gir_ffi/builders/constructor_result_convertor.rb +1 -0
  53. data/lib/gir_ffi/builders/enum_builder.rb +1 -4
  54. data/lib/gir_ffi/builders/field_builder.rb +2 -2
  55. data/lib/gir_ffi/builders/function_builder.rb +2 -1
  56. data/lib/gir_ffi/builders/interface_builder.rb +0 -3
  57. data/lib/gir_ffi/builders/mapping_method_builder.rb +24 -92
  58. data/lib/gir_ffi/builders/marshalling_method_builder.rb +73 -0
  59. data/lib/gir_ffi/builders/null_argument_builder.rb +3 -0
  60. data/lib/gir_ffi/builders/null_builder.rb +1 -0
  61. data/lib/gir_ffi/builders/object_builder.rb +0 -2
  62. data/lib/gir_ffi/builders/property_builder.rb +4 -4
  63. data/lib/gir_ffi/builders/registered_type_builder.rb +35 -1
  64. data/lib/gir_ffi/builders/return_value_builder.rb +4 -6
  65. data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +2 -0
  66. data/lib/gir_ffi/builders/signal_closure_builder.rb +46 -0
  67. data/lib/gir_ffi/builders/struct_builder.rb +0 -2
  68. data/lib/gir_ffi/builders/type_builder.rb +1 -1
  69. data/lib/gir_ffi/builders/unintrospectable_builder.rb +1 -1
  70. data/lib/gir_ffi/builders/union_builder.rb +0 -2
  71. data/lib/gir_ffi/builders/user_defined_builder.rb +6 -18
  72. data/lib/gir_ffi/builders/vfunc_builder.rb +6 -4
  73. data/lib/gir_ffi/builders/with_layout.rb +1 -2
  74. data/lib/gir_ffi/callback_base.rb +4 -4
  75. data/lib/gir_ffi/class_base.rb +28 -18
  76. data/lib/gir_ffi/enum_base.rb +2 -2
  77. data/lib/gir_ffi/ffi_ext/pointer.rb +1 -0
  78. data/lib/gir_ffi/in_out_pointer.rb +4 -4
  79. data/lib/gir_ffi/in_pointer.rb +2 -2
  80. data/lib/gir_ffi/info_ext/full_type_name.rb +16 -0
  81. data/lib/gir_ffi/info_ext/i_arg_info.rb +2 -3
  82. data/lib/gir_ffi/info_ext/i_callback_info.rb +1 -8
  83. data/lib/gir_ffi/info_ext/i_property_info.rb +0 -1
  84. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +0 -1
  85. data/lib/gir_ffi/info_ext/i_signal_info.rb +8 -40
  86. data/lib/gir_ffi/info_ext/i_type_info.rb +12 -2
  87. data/lib/gir_ffi/info_ext/i_vfunc_info.rb +1 -6
  88. data/lib/gir_ffi/info_ext/safe_constant_name.rb +0 -5
  89. data/lib/gir_ffi/info_ext.rb +1 -0
  90. data/lib/gir_ffi/lib_c.rb +1 -0
  91. data/lib/gir_ffi/module_base.rb +2 -2
  92. data/lib/gir_ffi/object_base.rb +0 -16
  93. data/lib/gir_ffi/receiver_argument_info.rb +0 -4
  94. data/lib/gir_ffi/registered_type_base.rb +0 -1
  95. data/lib/gir_ffi/sized_array.rb +5 -5
  96. data/lib/gir_ffi/struct_base.rb +4 -0
  97. data/lib/gir_ffi/type_base.rb +2 -2
  98. data/lib/gir_ffi/type_map.rb +1 -0
  99. data/lib/gir_ffi/unintrospectable_type_info.rb +1 -3
  100. data/lib/gir_ffi/user_data_type_info.rb +2 -0
  101. data/lib/gir_ffi/version.rb +2 -1
  102. data/lib/gir_ffi/zero_terminated.rb +6 -6
  103. data/lib/gir_ffi-base/glib/boolean.rb +2 -2
  104. data/lib/gir_ffi-base/glib/strv.rb +1 -1
  105. data/lib/gir_ffi-base/gobject/lib.rb +1 -0
  106. data/lib/gir_ffi-base/gobject.rb +1 -1
  107. data/lib/gir_ffi.rb +2 -0
  108. data/test/ffi-glib/hash_table_test.rb +1 -1
  109. data/test/ffi-glib/strv_test.rb +27 -0
  110. data/test/ffi-gobject_introspection/i_constant_info_test.rb +1 -5
  111. data/test/ffi-gobject_test.rb +3 -3
  112. data/test/gir_ffi/builders/{with_methods_test.rb → registered_type_builder_test.rb} +1 -1
  113. data/test/gir_ffi/builders/signal_closure_builder_test.rb +136 -0
  114. data/test/gir_ffi/builders/user_defined_builder_test.rb +2 -1
  115. data/test/gir_ffi/info_ext/i_signal_info_test.rb +0 -11
  116. data/test/integration/generated_gimarshallingtests_test.rb +47 -2
  117. data/test/integration/generated_regress_test.rb +19 -11
  118. metadata +82 -25
  119. data/lib/gir_ffi/builders/signal_builder.rb +0 -51
  120. data/lib/gir_ffi/builders/with_methods.rb +0 -45
  121. data/lib/gir_ffi/signal_base.rb +0 -21
  122. data/lib/gir_ffi/vfunc_base.rb +0 -9
  123. data/test/gir_ffi/builders/signal_builder_test.rb +0 -106
@@ -1,13 +1,10 @@
1
1
  require 'gir_ffi/builders/registered_type_builder'
2
- require 'gir_ffi/builders/with_methods'
3
2
  require 'gir_ffi/interface_base'
4
3
 
5
4
  module GirFFI
6
5
  module Builders
7
6
  # Implements the creation of a module representing an Interface.
8
7
  class InterfaceBuilder < RegisteredTypeBuilder
9
- include WithMethods
10
-
11
8
  def interface_struct
12
9
  @interface_struct ||= Builder.build_class iface_struct_info
13
10
  end
@@ -1,5 +1,6 @@
1
1
  require 'gir_ffi/builders/callback_argument_builder'
2
2
  require 'gir_ffi/builders/callback_return_value_builder'
3
+ require 'gir_ffi/builders/argument_builder_collection'
3
4
 
4
5
  module GirFFI
5
6
  module Builders
@@ -7,72 +8,30 @@ module GirFFI
7
8
  # handler. This method converts arguments from C to Ruby, and the
8
9
  # result from Ruby to C.
9
10
  class MappingMethodBuilder
10
- def self.for_callback argument_infos, return_type_info
11
+ def self.for_callback argument_infos, return_value_info
11
12
  vargen = VariableNameGenerator.new
12
- argument_builders = argument_infos.map {|arg|
13
- CallbackArgumentBuilder.new vargen, arg }
14
- set_up_argument_relations argument_infos, argument_builders
15
- new return_type_info, vargen, argument_builders
16
- end
17
-
18
- def self.for_signal receiver_info, argument_infos, user_data_info, return_type_info
19
- vargen = VariableNameGenerator.new
20
-
21
- receiver_builder = CallbackArgumentBuilder.new vargen, receiver_info
22
- argument_builders = argument_infos.map {|arg|
23
- CallbackArgumentBuilder.new vargen, arg }
24
- user_data_builder = CallbackArgumentBuilder.new vargen, user_data_info
25
-
26
- set_up_argument_relations argument_infos, argument_builders
27
- user_data_builder.is_closure = true
28
13
 
29
- argument_builders.unshift receiver_builder
30
- argument_builders.push user_data_builder
14
+ argument_builders = argument_infos.map {|arg| CallbackArgumentBuilder.new vargen, arg }
15
+ return_value_builder = CallbackReturnValueBuilder.new(vargen, return_value_info)
31
16
 
32
- new return_type_info, vargen, argument_builders
17
+ new ArgumentBuilderCollection.new(return_value_builder, argument_builders)
33
18
  end
34
19
 
35
- def self.for_vfunc receiver_info, argument_infos, return_type_info
20
+ def self.for_vfunc receiver_info, argument_infos, return_value_info
36
21
  vargen = VariableNameGenerator.new
37
22
 
38
23
  receiver_builder = CallbackArgumentBuilder.new vargen, receiver_info
39
- argument_builders = argument_infos.map {|arg|
40
- CallbackArgumentBuilder.new vargen, arg }
41
-
42
- set_up_argument_relations argument_infos, argument_builders
43
-
44
- argument_builders.unshift receiver_builder
24
+ argument_builders = argument_infos.map {|arg| CallbackArgumentBuilder.new vargen, arg }
25
+ return_value_builder = CallbackReturnValueBuilder.new(vargen, return_value_info)
45
26
 
46
- new return_type_info, vargen, argument_builders
27
+ new ArgumentBuilderCollection.new(return_value_builder, argument_builders,
28
+ receiver_builder: receiver_builder)
47
29
  end
48
30
 
49
- def self.set_up_argument_relations argument_infos, argument_builders
50
- argument_infos.each do |arg|
51
- if (idx = arg.closure) >= 0
52
- argument_builders[idx].is_closure = true
53
- end
54
- end
55
- argument_builders.each do |bldr|
56
- if (idx = bldr.array_length_idx) >= 0
57
- other = argument_builders[idx]
58
-
59
- bldr.length_arg = other
60
- other.array_arg = bldr
61
- end
62
- end
31
+ def initialize argument_builder_collection
32
+ @argument_builder_collection = argument_builder_collection
63
33
  end
64
34
 
65
- def initialize return_type_info, vargen, argument_builders
66
- @vargen = vargen
67
- @argument_builders = argument_builders
68
-
69
- @return_type_info = return_type_info
70
- end
71
-
72
- attr_reader :return_type_info
73
- attr_reader :vargen
74
- attr_reader :argument_builders
75
-
76
35
  def method_definition
77
36
  code = "def self.call_with_argument_mapping(#{method_arguments.join(', ')})"
78
37
  method_lines.each { |line| code << "\n #{line}" }
@@ -80,61 +39,34 @@ module GirFFI
80
39
  end
81
40
 
82
41
  def method_lines
83
- parameter_preparation + call_to_proc + return_value_conversion + return_value
42
+ @argument_builder_collection.parameter_preparation +
43
+ call_to_proc +
44
+ @argument_builder_collection.return_value_conversion +
45
+ return_value
84
46
  end
85
47
 
86
48
  def return_value
87
- if return_value_builder.is_relevant?
88
- ["return #{return_value_builder.return_value_name}"]
49
+ if (name = @argument_builder_collection.return_value_name)
50
+ ["return #{name}"]
89
51
  else
90
52
  []
91
53
  end
92
54
  end
93
55
 
94
- def return_value_conversion
95
- all_builders.map(&:post_conversion).flatten
96
- end
97
-
98
56
  def call_to_proc
99
- ["#{capture}_proc.call(#{call_arguments.join(', ')})"]
100
- end
101
-
102
- def parameter_preparation
103
- argument_builders.sort_by.with_index {|arg, i|
104
- [arg.type_info.array_length, i] }.map(&:pre_conversion).flatten
57
+ ["#{capture}_proc.call(#{@argument_builder_collection.call_argument_names.join(', ')})"]
105
58
  end
106
59
 
107
60
  def capture
108
- @capture ||= capture_variable_names.any? ?
109
- "#{capture_variable_names.join(", ")} = " :
110
- ""
111
- end
112
-
113
- def capture_variable_names
114
- @capture_variable_names ||=
115
- all_builders.map(&:capture_variable_name).compact
116
- end
117
-
118
- def all_builders
119
- @all_builders ||= [return_value_builder] + argument_builders
120
- end
121
-
122
- def call_arguments
123
- @call_arguments ||= argument_builders.map(&:call_argument_name).compact
61
+ @capture ||= begin
62
+ names = @argument_builder_collection.capture_variable_names
63
+ names.any? ? "#{names.join(", ")} = " : ""
64
+ end
124
65
  end
125
66
 
126
67
  def method_arguments
127
- @method_arguments ||= argument_builders.map(&:method_argument_name).unshift('_proc')
128
- end
129
-
130
- def return_value_info
131
- @return_value_info ||= ReturnValueInfo.new(return_type_info)
132
- end
133
-
134
- def return_value_builder
135
- @return_value_builder ||= CallbackReturnValueBuilder.new(vargen, return_value_info)
68
+ @method_arguments ||= @argument_builder_collection.method_argument_names.dup.unshift('_proc')
136
69
  end
137
70
  end
138
71
  end
139
72
  end
140
-
@@ -0,0 +1,73 @@
1
+ require 'gir_ffi/builders/closure_argument_builder'
2
+ require 'gir_ffi/builders/callback_return_value_builder'
3
+ require 'gir_ffi/builders/argument_builder_collection'
4
+
5
+ module GirFFI
6
+ module Builders
7
+ # Implements the creation mapping method for a callback or signal
8
+ # handler. This method converts arguments from C to Ruby, and the
9
+ # result from Ruby to C.
10
+ class MarshallingMethodBuilder
11
+ def self.for_signal receiver_info, argument_infos, return_value_info
12
+ vargen = VariableNameGenerator.new
13
+
14
+ receiver_builder = ClosureArgumentBuilder.new vargen, receiver_info
15
+ argument_builders = argument_infos.map {|arg| ClosureArgumentBuilder.new vargen, arg }
16
+ return_value_builder = CallbackReturnValueBuilder.new(vargen, return_value_info)
17
+
18
+ new ArgumentBuilderCollection.new(return_value_builder, argument_builders,
19
+ receiver_builder: receiver_builder)
20
+ end
21
+
22
+ def initialize argument_builder_collection
23
+ @argument_builder_collection = argument_builder_collection
24
+ end
25
+
26
+ def method_definition
27
+ code = "def self.marshaller(#{marshaller_arguments.join(', ')})"
28
+ method_lines.each { |line| code << "\n #{line}" }
29
+ code << "\nend\n"
30
+ end
31
+
32
+ def method_lines
33
+ param_values_unpack +
34
+ @argument_builder_collection.parameter_preparation +
35
+ call_to_closure +
36
+ @argument_builder_collection.return_value_conversion +
37
+ return_value
38
+ end
39
+
40
+ def return_value
41
+ if (name = @argument_builder_collection.return_value_name)
42
+ ["return_value.set_value #{name}"]
43
+ else
44
+ []
45
+ end
46
+ end
47
+
48
+ def call_to_closure
49
+ ["#{capture}wrap(closure.to_ptr).invoke_block(#{@argument_builder_collection.call_argument_names.join(', ')})"]
50
+ end
51
+
52
+ def param_values_unpack
53
+ ["#{method_arguments.join(", ")} = param_values.map(&:get_value_plain)" ]
54
+ end
55
+
56
+ def capture
57
+ @capture ||= begin
58
+ names = @argument_builder_collection.capture_variable_names
59
+ names.any? ? "#{names.join(", ")} = " : ""
60
+ end
61
+ end
62
+
63
+ def method_arguments
64
+ # FIXME: Don't add _ if method_argument_names has more than one element
65
+ @method_arguments ||= @argument_builder_collection.method_argument_names.dup.push('_')
66
+ end
67
+
68
+ def marshaller_arguments
69
+ %w(closure return_value param_values _invocation_hint _marshal_data)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -2,8 +2,11 @@ module GirFFI
2
2
  # Argument builder that does nothing. Implements the Null Object pattern.
3
3
  class NullArgumentBuilder
4
4
  def initialize *; end
5
+
5
6
  def pre; []; end
7
+
6
8
  def post; []; end
9
+
7
10
  def callarg; end
8
11
  end
9
12
  end
@@ -1,4 +1,5 @@
1
1
  module GirFFI
2
+ # Object Builder that does nothing. Implements the Null Object pattern.
2
3
  class NullBuilder
3
4
  def find_signal _
4
5
  nil
@@ -1,6 +1,5 @@
1
1
  require 'gir_ffi/builders/registered_type_builder'
2
2
  require 'gir_ffi/builders/with_layout'
3
- require 'gir_ffi/builders/with_methods'
4
3
  require 'gir_ffi/builders/property_builder'
5
4
  require 'gir_ffi/object_base'
6
5
 
@@ -8,7 +7,6 @@ module GirFFI
8
7
  module Builders
9
8
  # Implements the creation of a class representing a GObject Object.
10
9
  class ObjectBuilder < RegisteredTypeBuilder
11
- include WithMethods
12
10
  include WithLayout
13
11
 
14
12
  def find_signal signal_name
@@ -44,7 +44,7 @@ module GirFFI
44
44
  private
45
45
 
46
46
  def converting_getter_def
47
- return <<-CODE.reset_indentation
47
+ <<-CODE.reset_indentation
48
48
  def #{getter_name}
49
49
  #{getter_builder.capture_variable_name} = get_property("#{property_name}").get_value_plain
50
50
  #{getter_builder.post_conversion.join("\n")}
@@ -54,7 +54,7 @@ module GirFFI
54
54
  end
55
55
 
56
56
  def simple_getter_def
57
- return <<-CODE.reset_indentation
57
+ <<-CODE.reset_indentation
58
58
  def #{getter_name}
59
59
  get_property("#{property_name}").get_value
60
60
  end
@@ -67,7 +67,7 @@ module GirFFI
67
67
  end
68
68
 
69
69
  def converting_setter_def
70
- return <<-CODE.reset_indentation
70
+ <<-CODE.reset_indentation
71
71
  def #{setter_name} value
72
72
  #{setter_builder.pre_conversion.join("\n")}
73
73
  set_property("#{property_name}", #{setter_builder.callarg})
@@ -76,7 +76,7 @@ module GirFFI
76
76
  end
77
77
 
78
78
  def simple_setter_def
79
- return <<-CODE.reset_indentation
79
+ <<-CODE.reset_indentation
80
80
  def #{setter_name} value
81
81
  set_property("#{property_name}", value)
82
82
  end
@@ -1,4 +1,5 @@
1
1
  require 'gir_ffi/builders/base_type_builder'
2
+ require 'gir_ffi/method_stubber'
2
3
  require 'gir_ffi/class_base'
3
4
 
4
5
  module GirFFI
@@ -7,12 +8,45 @@ module GirFFI
7
8
  # of IRegisteredTypeInfo. These are types whose C representation is
8
9
  # complex, i.e., a struct or a union.
9
10
  class RegisteredTypeBuilder < BaseTypeBuilder
10
- private
11
+ def setup_method method
12
+ go = info.find_method method
13
+ attach_and_define_method method, go, meta_class
14
+ end
15
+
16
+ def setup_instance_method method
17
+ go = info.find_instance_method method
18
+ attach_and_define_method method, go, build_class
19
+ end
11
20
 
12
21
  def target_gtype
13
22
  info.g_type
14
23
  end
15
24
 
25
+ private
26
+
27
+ def meta_class
28
+ (class << build_class; self; end)
29
+ end
30
+
31
+ def function_definition go
32
+ FunctionBuilder.new(go).generate
33
+ end
34
+
35
+ def attach_and_define_method method, go, modul
36
+ return unless go
37
+ method = go.safe_name
38
+ Builder.attach_ffi_function lib, go
39
+ modul.class_eval { remove_method method if method_defined? method }
40
+ build_class.class_eval function_definition(go)
41
+ method
42
+ end
43
+
44
+ def stub_methods
45
+ info.get_methods.each do |minfo|
46
+ klass.class_eval MethodStubber.new(minfo).method_stub
47
+ end
48
+ end
49
+
16
50
  def setup_constants
17
51
  klass.const_set :G_TYPE, target_gtype
18
52
  super
@@ -42,17 +42,19 @@ module GirFFI
42
42
  end
43
43
  end
44
44
 
45
+ attr_reader :is_constructor
46
+
45
47
  private
46
48
 
47
49
  def has_post_conversion?
48
- is_closure || needs_constructor_wrap? ||
50
+ is_closure || is_constructor ||
49
51
  type_info.needs_c_to_ruby_conversion_for_functions?
50
52
  end
51
53
 
52
54
  def post_convertor
53
55
  @post_convertor ||= if is_closure
54
56
  ClosureConvertor.new(capture_variable_name)
55
- elsif needs_constructor_wrap?
57
+ elsif is_constructor
56
58
  ConstructorResultConvertor.new(capture_variable_name)
57
59
  else
58
60
  CToRubyConvertor.new(type_info,
@@ -65,10 +67,6 @@ module GirFFI
65
67
  length_arg && length_arg.post_converted_name
66
68
  end
67
69
 
68
- def needs_constructor_wrap?
69
- @is_constructor && specialized_type_tag == :object
70
- end
71
-
72
70
  def is_void_return_value?
73
71
  specialized_type_tag == :void && !type_info.pointer?
74
72
  end
@@ -1,3 +1,5 @@
1
+ # Builder that generates code to convert values from Ruby to C. Used by
2
+ # argument builders.
1
3
  class GirFFI::Builders::RubyToCConvertor
2
4
  def initialize type_info, argument_name
3
5
  @type_info = type_info
@@ -0,0 +1,46 @@
1
+ require 'gir_ffi/builders/base_type_builder'
2
+ require 'gir_ffi/builders/marshalling_method_builder'
3
+
4
+ module GirFFI
5
+ module Builders
6
+ # Implements the creation of a closure class for handling a particular
7
+ # signal. The type will be attached to the appropriate class.
8
+ class SignalClosureBuilder < BaseTypeBuilder
9
+ def instantiate_class
10
+ unless already_set_up
11
+ setup_constants
12
+ klass.class_eval marshaller_definition
13
+ end
14
+ klass
15
+ end
16
+
17
+ def setup_method _method
18
+ nil
19
+ end
20
+
21
+ def marshaller_definition
22
+ arg_infos = info.args
23
+
24
+ container_type_info = ReceiverTypeInfo.new(container_info)
25
+ receiver_info = ReceiverArgumentInfo.new(container_type_info)
26
+ return_value_info = ReturnValueInfo.new info.return_type
27
+
28
+ MarshallingMethodBuilder.for_signal(receiver_info,
29
+ arg_infos,
30
+ return_value_info).method_definition
31
+ end
32
+
33
+ def klass
34
+ @klass ||= get_or_define_class container_class, @classname, GObject::RubyClosure
35
+ end
36
+
37
+ def container_class
38
+ @container_class ||= Builder.build_class(container_info)
39
+ end
40
+
41
+ def container_info
42
+ @container_info ||= info.container
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,13 +1,11 @@
1
1
  require 'gir_ffi/builders/registered_type_builder'
2
2
  require 'gir_ffi/builders/with_layout'
3
- require 'gir_ffi/builders/with_methods'
4
3
  require 'gir_ffi/struct_base'
5
4
 
6
5
  module GirFFI
7
6
  module Builders
8
7
  # Implements the creation of a class representing a Struct.
9
8
  class StructBuilder < RegisteredTypeBuilder
10
- include WithMethods
11
9
  include WithLayout
12
10
 
13
11
  private
@@ -4,7 +4,7 @@ require 'gir_ffi/builders/enum_builder'
4
4
  require 'gir_ffi/builders/interface_builder'
5
5
  require 'gir_ffi/builders/object_builder'
6
6
  require 'gir_ffi/builders/struct_builder'
7
- require 'gir_ffi/builders/signal_builder'
7
+ require 'gir_ffi/builders/signal_closure_builder'
8
8
  require 'gir_ffi/builders/unintrospectable_builder'
9
9
  require 'gir_ffi/builders/union_builder'
10
10
  require 'gir_ffi/builders/vfunc_builder'
@@ -20,7 +20,7 @@ module GirFFI
20
20
  setup_interfaces
21
21
  end
22
22
 
23
- def setup_instance_method method
23
+ def setup_instance_method _method
24
24
  false
25
25
  end
26
26
 
@@ -1,6 +1,5 @@
1
1
  require 'gir_ffi/builders/registered_type_builder'
2
2
  require 'gir_ffi/builders/with_layout'
3
- require 'gir_ffi/builders/with_methods'
4
3
  require 'gir_ffi/union_base'
5
4
 
6
5
  module GirFFI
@@ -8,7 +7,6 @@ module GirFFI
8
7
  # Implements the creation of a class representing union type. The
9
8
  # class will have a nested FFI::Union class to represent its C union.
10
9
  class UnionBuilder < RegisteredTypeBuilder
11
- include WithMethods
12
10
  include WithLayout
13
11
 
14
12
  def layout_superclass
@@ -28,24 +28,16 @@ module GirFFI
28
28
  def setup_class
29
29
  setup_layout
30
30
  setup_constants
31
- #stub_methods
32
31
  setup_property_accessors
33
- #setup_vfunc_invokers
34
- #setup_interfaces
35
32
  setup_constructor
36
33
  end
37
34
 
38
- def gtype
35
+ def target_gtype
39
36
  @gtype
40
37
  end
41
38
 
42
39
  private
43
40
 
44
- # FIXME: Is this really used?
45
- def target_gtype
46
- @gtype
47
- end
48
-
49
41
  def parent
50
42
  @parent ||= gir.find_by_gtype(parent_gtype.to_i)
51
43
  end
@@ -81,14 +73,14 @@ module GirFFI
81
73
  end
82
74
 
83
75
  def class_init_proc
84
- proc do |object_class_ptr, data|
76
+ proc do |object_class_ptr, _data|
85
77
  setup_properties object_class_ptr
86
78
  setup_vfuncs object_class_ptr
87
79
  end
88
80
  end
89
81
 
90
82
  def interface_init_proc interface
91
- proc do |interface_ptr, data|
83
+ proc do |interface_ptr, _data|
92
84
  setup_interface_vfuncs interface, interface_ptr
93
85
  end
94
86
  end
@@ -98,7 +90,7 @@ module GirFFI
98
90
  properties.each do
99
91
  size += FFI.type_size(:int32)
100
92
  end
101
- return size
93
+ size
102
94
  end
103
95
 
104
96
  def class_size
@@ -117,13 +109,13 @@ module GirFFI
117
109
  end
118
110
 
119
111
  def property_getter
120
- proc do |object, property_id, value, pspec|
112
+ proc do |object, _property_id, value, pspec|
121
113
  value.set_value object.send(pspec.get_name)
122
114
  end
123
115
  end
124
116
 
125
117
  def property_setter
126
- proc do |object, property_id, value, pspec|
118
+ proc do |object, _property_id, value, pspec|
127
119
  object.send("#{pspec.get_name}=", value.get_value)
128
120
  end
129
121
  end
@@ -167,10 +159,6 @@ module GirFFI
167
159
 
168
160
  def install_vfunc container_struct, vfunc_name, vfunc_info, implementation
169
161
  vfunc = VFuncBuilder.new(vfunc_info).build_class
170
- # NOTE: This assigns a VFuncBase to a CallbackBase.
171
- # This suggests that the two should be combined, but it seems
172
- # CallbackBase will not cast the first argument correctly if used
173
- # to map the implementation proc arguments.
174
162
  container_struct[vfunc_name] = vfunc.from implementation
175
163
  end
176
164
 
@@ -3,13 +3,14 @@ require 'gir_ffi/builders/base_type_builder'
3
3
  require 'gir_ffi/builders/mapping_method_builder'
4
4
  require 'gir_ffi/receiver_type_info'
5
5
  require 'gir_ffi/receiver_argument_info'
6
- require 'gir_ffi/vfunc_base'
6
+ require 'gir_ffi/callback_base'
7
7
 
8
8
  module GirFFI
9
9
  module Builders
10
10
  # Implements the creation of a class representing the implementation of a
11
11
  # vfunc. This class will be able to turn a proc into an FFI::Function that
12
- # can serve as such an implementation in C.
12
+ # can serve as such an implementation in C. The class will be namespaced
13
+ # inside class defining the vfunc.
13
14
  class VFuncBuilder < BaseTypeBuilder
14
15
  def instantiate_class
15
16
  unless already_set_up
@@ -27,11 +28,12 @@ module GirFFI
27
28
  arg_infos = info.args
28
29
  arg_infos << ErrorArgumentInfo.new if info.throws?
29
30
 
30
- receiver_info = ReceiverArgumentInfo.new(receiver_type_info)
31
+ receiver_info = ReceiverArgumentInfo.new receiver_type_info
32
+ return_value_info = ReturnValueInfo.new info.return_type
31
33
 
32
34
  MappingMethodBuilder.for_vfunc(receiver_info,
33
35
  arg_infos,
34
- info.return_type).method_definition
36
+ return_value_info).method_definition
35
37
  end
36
38
 
37
39
  def receiver_type_info
@@ -4,8 +4,7 @@ module GirFFI
4
4
  module Builders
5
5
  # Implements the creation of classes representing types with layout,
6
6
  # i.e., :union, :struct, :object.
7
- # Note: This module depends on the additional inclusion of
8
- # WithMethods.
7
+ # Note: This module depends on methods in RegisteredTypeBuilder.
9
8
  module WithLayout
10
9
  def layout_specification
11
10
  spec = base_layout_specification
@@ -1,7 +1,7 @@
1
1
  require 'gir_ffi/type_base'
2
2
 
3
3
  module GirFFI
4
- # Base module for callbacks.
4
+ # Base module for callbacks and vfuncs.
5
5
  # NOTE: Another option would be to derive this class from FFI::Function,
6
6
  # allowing a more natural implementation of from_native, to_native and wrap.
7
7
  class CallbackBase < Proc
@@ -12,13 +12,13 @@ module GirFFI
12
12
  FFI::Type::POINTER
13
13
  end
14
14
 
15
- def self.from_native(value, _context)
15
+ def self.from_native value, _context
16
16
  return nil if !value || value.null?
17
17
  FFI::Function.new(gir_ffi_builder.return_ffi_type,
18
18
  gir_ffi_builder.argument_ffi_types, value)
19
19
  end
20
20
 
21
- def self.to_native(value, _context)
21
+ def self.to_native value, _context
22
22
  return nil unless value
23
23
  return value if FFI::Function === value
24
24
  value.to_native
@@ -45,7 +45,7 @@ module GirFFI
45
45
  def self.wrap_in_callback_args_mapper prc
46
46
  return nil unless prc
47
47
  return prc if FFI::Function === prc
48
- return self.new do |*args|
48
+ new do |*args|
49
49
  call_with_argument_mapping(prc, *args)
50
50
  end
51
51
  end