gir_ffi 0.7.4 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -5,7 +5,8 @@ module GObjectIntrospection
5
5
  def n_values
6
6
  Lib.g_enum_info_get_n_values @gobj
7
7
  end
8
- def value(index)
8
+
9
+ def value index
9
10
  IValueInfo.wrap(Lib.g_enum_info_get_value @gobj, index)
10
11
  end
11
12
  ##
@@ -14,7 +15,8 @@ module GObjectIntrospection
14
15
  def get_n_methods
15
16
  Lib.g_enum_info_get_n_methods @gobj
16
17
  end
17
- def get_method(index)
18
+
19
+ def get_method index
18
20
  IFunctionInfo.wrap(Lib.g_enum_info_get_method @gobj, index)
19
21
  end
20
22
 
@@ -27,4 +29,3 @@ module GObjectIntrospection
27
29
  end
28
30
  end
29
31
  end
30
-
@@ -5,26 +5,32 @@ module GObjectIntrospection
5
5
  def symbol
6
6
  Lib.g_function_info_get_symbol @gobj
7
7
  end
8
+
8
9
  def flags
9
10
  Lib.g_function_info_get_flags @gobj
10
11
  end
11
12
 
12
- #TODO: Use some sort of bitfield
13
+ # TODO: Use some sort of bitfield
13
14
  def method?
14
15
  flags & 1 != 0
15
16
  end
17
+
16
18
  def constructor?
17
19
  flags & 2 != 0
18
20
  end
21
+
19
22
  def getter?
20
23
  flags & 4 != 0
21
24
  end
25
+
22
26
  def setter?
23
27
  flags & 8 != 0
24
28
  end
29
+
25
30
  def wraps_vfunc?
26
31
  flags & 16 != 0
27
32
  end
33
+
28
34
  def throws?
29
35
  flags & 32 != 0
30
36
  end
@@ -5,27 +5,33 @@ module GObjectIntrospection
5
5
  def n_prerequisites
6
6
  Lib.g_interface_info_get_n_prerequisites @gobj
7
7
  end
8
+
8
9
  def prerequisite index
9
10
  IBaseInfo.wrap(Lib.g_interface_info_get_prerequisite @gobj, index)
10
11
  end
12
+
11
13
  ##
12
14
  build_array_method :prerequisites
13
15
 
14
16
  def n_properties
15
17
  Lib.g_interface_info_get_n_properties @gobj
16
18
  end
19
+
17
20
  def property index
18
21
  IPropertyInfo.wrap(Lib.g_interface_info_get_property @gobj, index)
19
22
  end
23
+
20
24
  ##
21
25
  build_array_method :properties, :property
22
26
 
23
27
  def get_n_methods
24
28
  Lib.g_interface_info_get_n_methods @gobj
25
29
  end
30
+
26
31
  def get_method index
27
32
  IFunctionInfo.wrap(Lib.g_interface_info_get_method @gobj, index)
28
33
  end
34
+
29
35
  ##
30
36
  build_array_method :get_methods
31
37
 
@@ -36,9 +42,11 @@ module GObjectIntrospection
36
42
  def n_signals
37
43
  Lib.g_interface_info_get_n_signals @gobj
38
44
  end
45
+
39
46
  def signal index
40
47
  ISignalInfo.wrap(Lib.g_interface_info_get_signal @gobj, index)
41
48
  end
49
+
42
50
  ##
43
51
  build_array_method :signals
44
52
  build_finder_method :find_signal
@@ -46,9 +54,11 @@ module GObjectIntrospection
46
54
  def n_vfuncs
47
55
  Lib.g_interface_info_get_n_vfuncs @gobj
48
56
  end
57
+
49
58
  def vfunc index
50
59
  IVFuncInfo.wrap(Lib.g_interface_info_get_vfunc @gobj, index)
51
60
  end
61
+
52
62
  ##
53
63
  build_array_method :vfuncs
54
64
 
@@ -59,9 +69,11 @@ module GObjectIntrospection
59
69
  def n_constants
60
70
  Lib.g_interface_info_get_n_constants @gobj
61
71
  end
72
+
62
73
  def constant index
63
74
  IConstantInfo.wrap(Lib.g_interface_info_get_constant @gobj, index)
64
75
  end
76
+
65
77
  ##
66
78
  build_array_method :constants
67
79
 
@@ -25,27 +25,33 @@ module GObjectIntrospection
25
25
  def n_interfaces
26
26
  Lib.g_object_info_get_n_interfaces @gobj
27
27
  end
28
- def interface(index)
28
+
29
+ def interface index
29
30
  IInterfaceInfo.wrap(Lib.g_object_info_get_interface @gobj, index)
30
31
  end
32
+
31
33
  ##
32
34
  build_array_method :interfaces
33
35
 
34
36
  def n_fields
35
37
  Lib.g_object_info_get_n_fields @gobj
36
38
  end
37
- def field(index)
39
+
40
+ def field index
38
41
  IFieldInfo.wrap(Lib.g_object_info_get_field @gobj, index)
39
42
  end
43
+
40
44
  ##
41
45
  build_array_method :fields
42
46
 
43
47
  def n_properties
44
48
  Lib.g_object_info_get_n_properties @gobj
45
49
  end
46
- def property(index)
50
+
51
+ def property index
47
52
  IPropertyInfo.wrap(Lib.g_object_info_get_property @gobj, index)
48
53
  end
54
+
49
55
  ##
50
56
  build_array_method :properties, :property
51
57
  build_finder_method :find_property, :n_properties
@@ -54,23 +60,25 @@ module GObjectIntrospection
54
60
  Lib.g_object_info_get_n_methods @gobj
55
61
  end
56
62
 
57
- def get_method(index)
63
+ def get_method index
58
64
  IFunctionInfo.wrap(Lib.g_object_info_get_method @gobj, index)
59
65
  end
60
66
 
61
67
  ##
62
68
  build_array_method :get_methods
63
69
 
64
- def find_method(name)
70
+ def find_method name
65
71
  IFunctionInfo.wrap(Lib.g_object_info_find_method @gobj, name)
66
72
  end
67
73
 
68
74
  def n_signals
69
75
  Lib.g_object_info_get_n_signals @gobj
70
76
  end
71
- def signal(index)
77
+
78
+ def signal index
72
79
  ISignalInfo.wrap(Lib.g_object_info_get_signal @gobj, index)
73
80
  end
81
+
74
82
  ##
75
83
  build_array_method :signals
76
84
  build_finder_method :find_signal
@@ -78,9 +86,11 @@ module GObjectIntrospection
78
86
  def n_vfuncs
79
87
  Lib.g_object_info_get_n_vfuncs @gobj
80
88
  end
81
- def vfunc(index)
89
+
90
+ def vfunc index
82
91
  IVFuncInfo.wrap(Lib.g_object_info_get_vfunc @gobj, index)
83
92
  end
93
+
84
94
  def find_vfunc name
85
95
  IVFuncInfo.wrap(Lib.g_object_info_find_vfunc @gobj, name)
86
96
  end
@@ -90,7 +100,8 @@ module GObjectIntrospection
90
100
  def n_constants
91
101
  Lib.g_object_info_get_n_constants @gobj
92
102
  end
93
- def constant(index)
103
+
104
+ def constant index
94
105
  IConstantInfo.wrap(Lib.g_object_info_get_constant @gobj, index)
95
106
  end
96
107
  ##
@@ -15,4 +15,3 @@ module GObjectIntrospection
15
15
  end
16
16
  end
17
17
  end
18
-
@@ -22,9 +22,9 @@ require 'ffi-gobject_introspection/i_union_info'
22
22
  require 'ffi-gobject_introspection/i_enum_info'
23
23
  require 'ffi-gobject_introspection/i_flags_info'
24
24
 
25
- module GObjectIntrospection
26
- GObject.type_init
25
+ GObject.type_init
27
26
 
27
+ module GObjectIntrospection
28
28
  # The Gobject Introspection Repository. This class is the point of
29
29
  # access to the introspection typelibs.
30
30
  # This class wraps the GIRepository struct.
@@ -55,13 +55,13 @@ module GObjectIntrospection
55
55
  }
56
56
 
57
57
  def initialize
58
- @gobj = Lib::g_irepository_get_default
58
+ @gobj = Lib.g_irepository_get_default
59
59
  end
60
60
 
61
61
  include Singleton
62
62
 
63
63
  def self.default
64
- self.instance
64
+ instance
65
65
  end
66
66
 
67
67
  def self.prepend_search_path path
@@ -86,8 +86,7 @@ module GObjectIntrospection
86
86
  end
87
87
 
88
88
  def info namespace, index
89
- ptr = Lib.g_irepository_get_info @gobj, namespace, index
90
- return wrap ptr
89
+ wrap_info Lib.g_irepository_get_info(@gobj, namespace, index)
91
90
  end
92
91
 
93
92
  # Utility method
@@ -98,14 +97,12 @@ module GObjectIntrospection
98
97
  end
99
98
 
100
99
  def find_by_name namespace, name
101
- ptr = Lib.g_irepository_find_by_name @gobj, namespace, name
102
- return wrap ptr
100
+ wrap_info Lib.g_irepository_find_by_name(@gobj, namespace, name)
103
101
  end
104
102
 
105
103
  def find_by_gtype gtype
106
104
  raise ArgumentError, "Type #{gtype} is not a valid type" if gtype == 0
107
- ptr = Lib.g_irepository_find_by_gtype @gobj, gtype
108
- return wrap ptr
105
+ wrap_info Lib.g_irepository_find_by_gtype(@gobj, gtype)
109
106
  end
110
107
 
111
108
  def dependencies namespace
@@ -120,17 +117,15 @@ module GObjectIntrospection
120
117
 
121
118
  def self.wrap_ibaseinfo_pointer ptr
122
119
  return nil if ptr.null?
123
-
124
120
  type = Lib.g_base_info_get_type ptr
125
121
  klass = TYPEMAP[type]
126
-
127
- return klass.wrap(ptr)
122
+ klass.wrap ptr
128
123
  end
129
124
 
130
125
  private
131
126
 
132
- def wrap ptr
133
- IRepository.wrap_ibaseinfo_pointer ptr
127
+ def wrap_info ptr
128
+ self.class.wrap_ibaseinfo_pointer ptr
134
129
  end
135
130
  end
136
131
  end
@@ -5,7 +5,8 @@ module GObjectIntrospection
5
5
  def n_fields
6
6
  Lib.g_struct_info_get_n_fields @gobj
7
7
  end
8
- def field(index)
8
+
9
+ def field index
9
10
  IFieldInfo.wrap(Lib.g_struct_info_get_field @gobj, index)
10
11
  end
11
12
 
@@ -16,7 +17,8 @@ module GObjectIntrospection
16
17
  def get_n_methods
17
18
  Lib.g_struct_info_get_n_methods @gobj
18
19
  end
19
- def get_method(index)
20
+
21
+ def get_method index
20
22
  IFunctionInfo.wrap(Lib.g_struct_info_get_method @gobj, index)
21
23
  end
22
24
 
@@ -5,12 +5,15 @@ module GObjectIntrospection
5
5
  def pointer?
6
6
  Lib.g_type_info_is_pointer @gobj
7
7
  end
8
+
8
9
  def tag
9
10
  Lib.g_type_info_get_tag @gobj
10
11
  end
11
- def param_type(index)
12
+
13
+ def param_type index
12
14
  ITypeInfo.wrap(Lib.g_type_info_get_param_type @gobj, index)
13
15
  end
16
+
14
17
  def interface
15
18
  ptr = Lib.g_type_info_get_interface @gobj
16
19
  IRepository.wrap_ibaseinfo_pointer ptr
@@ -37,4 +40,3 @@ module GObjectIntrospection
37
40
  end
38
41
  end
39
42
  end
40
-
@@ -5,7 +5,8 @@ module GObjectIntrospection
5
5
  def n_fields
6
6
  Lib.g_union_info_get_n_fields @gobj
7
7
  end
8
- def field(index)
8
+
9
+ def field index
9
10
  IFieldInfo.wrap(Lib.g_union_info_get_field @gobj, index)
10
11
  end
11
12
 
@@ -15,19 +16,22 @@ module GObjectIntrospection
15
16
  def get_n_methods
16
17
  Lib.g_union_info_get_n_methods @gobj
17
18
  end
18
- def get_method(index)
19
+
20
+ def get_method index
19
21
  IFunctionInfo.wrap(Lib.g_union_info_get_method @gobj, index)
20
22
  end
21
23
 
22
24
  ##
23
25
  build_array_method :get_methods
24
26
 
25
- def find_method(name)
27
+ def find_method name
26
28
  IFunctionInfo.wrap(Lib.g_union_info_find_method @gobj, name)
27
29
  end
30
+
28
31
  def size
29
32
  Lib.g_union_info_get_size @gobj
30
33
  end
34
+
31
35
  def alignment
32
36
  Lib.g_union_info_get_alignment @gobj
33
37
  end
@@ -7,4 +7,3 @@ module GObjectIntrospection
7
7
  end
8
8
  end
9
9
  end
10
-
@@ -1,6 +1,7 @@
1
1
  require 'ffi'
2
2
 
3
3
  module GObjectIntrospection
4
+ # Module for attaching functions from the girepository library
4
5
  module Lib
5
6
  extend FFI::Library
6
7
  ffi_lib "girepository-1.0"
@@ -121,8 +122,6 @@ module GObjectIntrospection
121
122
  # improved signature.
122
123
  attach_function :g_type_tag_to_string, [:ITypeTag], :string
123
124
 
124
- #define G_TYPE_TAG_IS_BASIC(tag) (tag < GI_TYPE_TAG_ARRAY)
125
-
126
125
  enum :IArrayType, [
127
126
  :c,
128
127
  :array,
@@ -1,2 +1 @@
1
1
  require 'ffi-gobject_introspection/i_repository'
2
-
@@ -1,6 +1,8 @@
1
1
  require 'gir_ffi/lib_c'
2
2
 
3
3
  module GirFFI
4
+ # Helper module providing a safe allocation method that raises an exception
5
+ # if memory cannot be allocated.
4
6
  module AllocationHelper
5
7
  def self.safe_malloc size
6
8
  ptr = LibC.malloc size
@@ -9,4 +11,3 @@ module GirFFI
9
11
  end
10
12
  end
11
13
  end
12
-
@@ -3,17 +3,21 @@ require 'gir_ffi/builder'
3
3
  require 'gir_ffi/glib_error'
4
4
 
5
5
  module GirFFI
6
+ # Helper module containing methods used during argument conversion in
7
+ # generated methods.
6
8
  module ArgHelper
9
+ # Helper class for storing objects for later retrieval. Used to store user
10
+ # data arguments.
7
11
  class ObjectStore
8
12
  def initialize
9
13
  @store = {}
10
14
  end
11
15
 
12
- def store(ptr, obj)
16
+ def store ptr, obj
13
17
  @store[ptr.address] = obj
14
18
  end
15
19
 
16
- def fetch(ptr)
20
+ def fetch ptr
17
21
  return if ptr.null?
18
22
  key = ptr.address
19
23
  if @store.has_key? key
@@ -1,4 +1,5 @@
1
1
  module GirFFI
2
+ # Set of helper methods used in the builders.
2
3
  module BuilderHelper
3
4
  def optionally_define_constant parent, name
4
5
  if parent.const_defined? name, false
@@ -0,0 +1,67 @@
1
+ module GirFFI
2
+ module Builders
3
+ # Class representing the argument and return value builders for a callback
4
+ # mapping function or marshaller. Implements collecting the conversion code
5
+ # and parameter and variable names for use by function builders.
6
+ class ArgumentBuilderCollection
7
+ attr_reader :return_value_builder
8
+ attr_reader :argument_builders
9
+
10
+ def initialize return_value_builder, argument_builders, options = {}
11
+ @receiver_builder = options[:receiver_builder]
12
+ @argument_builders = argument_builders
13
+ @return_value_builder = return_value_builder
14
+ self.class.set_up_argument_relations argument_builders
15
+ @argument_builders.unshift @receiver_builder if @receiver_builder
16
+ end
17
+
18
+ def parameter_preparation
19
+ argument_builders.sort_by.with_index {|arg, i|
20
+ [arg.type_info.array_length, i] }.map(&:pre_conversion).flatten
21
+ end
22
+
23
+ def return_value_conversion
24
+ all_builders.map(&:post_conversion).flatten
25
+ end
26
+
27
+ def capture_variable_names
28
+ @capture_variable_names ||=
29
+ all_builders.map(&:capture_variable_name).compact
30
+ end
31
+
32
+ def call_argument_names
33
+ @call_argument_names ||= argument_builders.map(&:call_argument_name).compact
34
+ end
35
+
36
+ def method_argument_names
37
+ @method_argument_names ||= argument_builders.map(&:method_argument_name)
38
+ end
39
+
40
+ def return_value_name
41
+ return_value_builder.return_value_name if return_value_builder.is_relevant?
42
+ end
43
+
44
+ def self.set_up_argument_relations argument_builders
45
+ argument_builders.each do |arg|
46
+ if (idx = arg.arginfo.closure) >= 0
47
+ argument_builders[idx].is_closure = true
48
+ end
49
+ end
50
+ argument_builders.each do |bldr|
51
+ if (idx = bldr.array_length_idx) >= 0
52
+ other = argument_builders[idx]
53
+
54
+ bldr.length_arg = other
55
+ other.array_arg = bldr
56
+ end
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def all_builders
63
+ @all_builders ||= [return_value_builder] + argument_builders
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,3 +1,5 @@
1
+ # Builder that generates code to convert values from C to Ruby. Used by
2
+ # argument builders.
1
3
  class GirFFI::Builders::CToRubyConvertor
2
4
  def initialize type_info, argument_name, length_arg
3
5
  @type_info = type_info
@@ -5,6 +5,8 @@ require 'gir_ffi/builders/null_convertor'
5
5
 
6
6
  module GirFFI
7
7
  module Builders
8
+ # Convertor for arguments for ruby callbacks. Used when building the
9
+ # argument mapper for callbacks.
8
10
  class CallbackArgumentBuilder < BaseArgumentBuilder
9
11
  def method_argument_name
10
12
  @method_argument_name ||= name || new_variable
@@ -62,7 +64,7 @@ module GirFFI
62
64
  def pre_convertor
63
65
  @pre_convertor ||= if is_closure
64
66
  ClosureConvertor.new(method_argument_name)
65
- elsif type_info.needs_c_to_ruby_conversion_for_callbacks?
67
+ elsif needs_c_to_ruby_conversion?
66
68
  CToRubyConvertor.new(type_info,
67
69
  method_argument_name,
68
70
  length_argument_name)
@@ -71,6 +73,10 @@ module GirFFI
71
73
  end
72
74
  end
73
75
 
76
+ def needs_c_to_ruby_conversion?
77
+ type_info.needs_c_to_ruby_conversion_for_callbacks?
78
+ end
79
+
74
80
  def outgoing_post_conversion
75
81
  "#{pre_converted_name}.set_value #{outgoing_convertor.conversion}"
76
82
  end
@@ -106,10 +112,6 @@ module GirFFI
106
112
  def length_argument_name
107
113
  length_arg && length_arg.pre_converted_name
108
114
  end
109
-
110
- def is_void_return_value?
111
- specialized_type_tag == :void && !type_info.pointer?
112
- end
113
115
  end
114
116
  end
115
117
  end
@@ -29,7 +29,9 @@ module GirFFI
29
29
  end
30
30
 
31
31
  def mapping_method_definition
32
- MappingMethodBuilder.for_callback(info.args, info.return_type).method_definition
32
+ return_value_info = ReturnValueInfo.new info.return_type
33
+ MappingMethodBuilder.for_callback(info.args,
34
+ return_value_info).method_definition
33
35
  end
34
36
 
35
37
  def callback_sym
@@ -3,6 +3,8 @@ require 'gir_ffi/builders/ruby_to_c_convertor'
3
3
 
4
4
  module GirFFI
5
5
  module Builders
6
+ # Implements building post-processing statements for return values of
7
+ # callbacks.
6
8
  class CallbackReturnValueBuilder < BaseArgumentBuilder
7
9
  def is_relevant?
8
10
  !is_void_return_value? && !arginfo.skip?
@@ -0,0 +1,13 @@
1
+ require 'gir_ffi/builders/callback_argument_builder'
2
+
3
+ module GirFFI
4
+ module Builders
5
+ # Convertor for arguments for RubyClosure objects. Used when building the
6
+ # marshaller for signal handler closures.
7
+ class ClosureArgumentBuilder < CallbackArgumentBuilder
8
+ def needs_c_to_ruby_conversion?
9
+ type_info.needs_c_to_ruby_conversion_for_closures?
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ # Builder that generates code to convert closure arguments ('user data') from
2
+ # C to Ruby. Used by argument builders.
1
3
  class GirFFI::Builders::ClosureConvertor
2
4
  def initialize argument_name
3
5
  @argument_name = argument_name
@@ -1,3 +1,5 @@
1
+ # Builder that generates code to convert closure arguments ('user data') from
2
+ # Ruby to C. Used by argument builders.
1
3
  class GirFFI::Builders::ClosureToPointerConvertor
2
4
  def initialize argument_name
3
5
  @argument_name = argument_name
@@ -1,3 +1,4 @@
1
+ # Builds conversion code for the result of a GObject constructor method.
1
2
  class GirFFI::Builders::ConstructorResultConvertor
2
3
  def initialize argument_name
3
4
  @argument_name = argument_name
@@ -1,5 +1,4 @@
1
1
  require 'gir_ffi/builders/registered_type_builder'
2
- require 'gir_ffi/builders/with_methods'
3
2
  require 'gir_ffi/enum_base'
4
3
 
5
4
  module GirFFI
@@ -8,8 +7,6 @@ module GirFFI
8
7
  # attached to the appropriate namespace module, and will be defined
9
8
  # as an enum for FFI.
10
9
  class EnumBuilder < RegisteredTypeBuilder
11
- include WithMethods
12
-
13
10
  private
14
11
 
15
12
  def enum_sym
@@ -17,7 +14,7 @@ module GirFFI
17
14
  end
18
15
 
19
16
  def value_spec
20
- return info.values.map {|vinfo|
17
+ info.values.map {|vinfo|
21
18
  val = GirFFI::ArgHelper.cast_uint32_to_int32(vinfo.value)
22
19
  [vinfo.name.to_sym, val]
23
20
  }.flatten
@@ -40,7 +40,7 @@ module GirFFI
40
40
  field_ptr = builder.new_variable
41
41
  typed_ptr = builder.new_variable
42
42
 
43
- return <<-CODE.reset_indentation
43
+ <<-CODE.reset_indentation
44
44
  def #{info.name}
45
45
  #{field_ptr} = @struct.to_ptr + #{info.offset}
46
46
  #{typed_ptr} = GirFFI::InOutPointer.new(#{field_type_tag_or_class.inspect}, #{field_ptr})
@@ -57,7 +57,7 @@ module GirFFI
57
57
  field_ptr = builder.new_variable
58
58
  typed_ptr = builder.new_variable
59
59
 
60
- return <<-CODE.reset_indentation
60
+ <<-CODE.reset_indentation
61
61
  def #{info.name}= #{builder.method_argument_name}
62
62
  #{field_ptr} = @struct.to_ptr + #{info.offset}
63
63
  #{typed_ptr} = GirFFI::InOutPointer.new(#{field_type_tag_or_class.inspect}, #{field_ptr})
@@ -24,7 +24,8 @@ module GirFFI
24
24
 
25
25
  set_up_argument_relations
26
26
  setup_error_argument vargen
27
- return filled_out_template
27
+
28
+ filled_out_template
28
29
  end
29
30
 
30
31
  private