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.
Files changed (278) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +7 -0
  3. data/Gemfile +2 -1
  4. data/README.md +6 -0
  5. data/TODO.md +1 -0
  6. data/examples/clutter.rb +106 -0
  7. data/examples/main_loop.rb +0 -8
  8. data/lib/ffi-glib/array.rb +1 -0
  9. data/lib/ffi-glib/array_methods.rb +1 -0
  10. data/lib/ffi-glib/byte_array.rb +1 -0
  11. data/lib/ffi-glib/bytes.rb +1 -0
  12. data/lib/ffi-glib/container_class_methods.rb +1 -0
  13. data/lib/ffi-glib/destroy_notify.rb +1 -0
  14. data/lib/ffi-glib/error.rb +1 -0
  15. data/lib/ffi-glib/hash_table.rb +2 -1
  16. data/lib/ffi-glib/iconv.rb +1 -0
  17. data/lib/ffi-glib/list.rb +1 -0
  18. data/lib/ffi-glib/list_methods.rb +1 -0
  19. data/lib/ffi-glib/main_loop.rb +1 -0
  20. data/lib/ffi-glib/ptr_array.rb +1 -0
  21. data/lib/ffi-glib/s_list.rb +1 -0
  22. data/lib/ffi-glib/strv.rb +1 -0
  23. data/lib/ffi-glib/variant.rb +1 -0
  24. data/lib/ffi-glib.rb +1 -0
  25. data/lib/ffi-gobject/base.rb +1 -0
  26. data/lib/ffi-gobject/closure.rb +1 -0
  27. data/lib/ffi-gobject/initially_unowned.rb +1 -0
  28. data/lib/ffi-gobject/object.rb +1 -0
  29. data/lib/ffi-gobject/object_class.rb +1 -0
  30. data/lib/ffi-gobject/ruby_closure.rb +1 -0
  31. data/lib/ffi-gobject/value.rb +1 -0
  32. data/lib/ffi-gobject.rb +1 -0
  33. data/lib/ffi-gobject_introspection/g_error.rb +1 -0
  34. data/lib/ffi-gobject_introspection/i_arg_info.rb +1 -0
  35. data/lib/ffi-gobject_introspection/i_base_info.rb +1 -0
  36. data/lib/ffi-gobject_introspection/i_callable_info.rb +5 -0
  37. data/lib/ffi-gobject_introspection/i_callback_info.rb +1 -0
  38. data/lib/ffi-gobject_introspection/i_constant_info.rb +1 -0
  39. data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -0
  40. data/lib/ffi-gobject_introspection/i_field_info.rb +3 -2
  41. data/lib/ffi-gobject_introspection/i_flags_info.rb +1 -0
  42. data/lib/ffi-gobject_introspection/i_function_info.rb +7 -7
  43. data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
  44. data/lib/ffi-gobject_introspection/i_object_info.rb +1 -0
  45. data/lib/ffi-gobject_introspection/i_property_info.rb +5 -4
  46. data/lib/ffi-gobject_introspection/i_registered_type_info.rb +1 -0
  47. data/lib/ffi-gobject_introspection/i_repository.rb +1 -0
  48. data/lib/ffi-gobject_introspection/i_signal_info.rb +1 -0
  49. data/lib/ffi-gobject_introspection/i_struct_info.rb +1 -0
  50. data/lib/ffi-gobject_introspection/i_type_info.rb +1 -0
  51. data/lib/ffi-gobject_introspection/i_union_info.rb +1 -0
  52. data/lib/ffi-gobject_introspection/i_unresolved_info.rb +1 -0
  53. data/lib/ffi-gobject_introspection/i_value_info.rb +1 -0
  54. data/lib/ffi-gobject_introspection/i_vfunc_info.rb +1 -0
  55. data/lib/ffi-gobject_introspection/lib.rb +27 -10
  56. data/lib/ffi-gobject_introspection.rb +1 -0
  57. data/lib/gir_ffi/allocation_helper.rb +1 -0
  58. data/lib/gir_ffi/arg_helper.rb +1 -0
  59. data/lib/gir_ffi/boxed_base.rb +1 -0
  60. data/lib/gir_ffi/builder.rb +1 -0
  61. data/lib/gir_ffi/builder_helper.rb +1 -0
  62. data/lib/gir_ffi/builders/argument_builder.rb +18 -6
  63. data/lib/gir_ffi/builders/argument_builder_collection.rb +24 -12
  64. data/lib/gir_ffi/builders/base_argument_builder.rb +1 -0
  65. data/lib/gir_ffi/builders/base_method_builder.rb +33 -9
  66. data/lib/gir_ffi/builders/base_type_builder.rb +1 -0
  67. data/lib/gir_ffi/builders/boxed_builder.rb +1 -0
  68. data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +1 -0
  69. data/lib/gir_ffi/builders/callback_argument_builder.rb +5 -0
  70. data/lib/gir_ffi/builders/callback_builder.rb +2 -5
  71. data/lib/gir_ffi/builders/callback_return_value_builder.rb +1 -0
  72. data/lib/gir_ffi/builders/closure_argument_builder.rb +1 -0
  73. data/lib/gir_ffi/builders/closure_convertor.rb +1 -0
  74. data/lib/gir_ffi/builders/closure_return_value_builder.rb +1 -0
  75. data/lib/gir_ffi/builders/closure_to_pointer_convertor.rb +1 -0
  76. data/lib/gir_ffi/builders/constant_builder.rb +1 -0
  77. data/lib/gir_ffi/builders/constructor_builder.rb +2 -0
  78. data/lib/gir_ffi/builders/enum_builder.rb +2 -1
  79. data/lib/gir_ffi/builders/field_builder.rb +2 -0
  80. data/lib/gir_ffi/builders/flags_builder.rb +2 -1
  81. data/lib/gir_ffi/builders/full_c_to_ruby_convertor.rb +1 -0
  82. data/lib/gir_ffi/builders/function_builder.rb +2 -3
  83. data/lib/gir_ffi/builders/initializer_builder.rb +2 -3
  84. data/lib/gir_ffi/builders/initializer_return_value_builder.rb +1 -0
  85. data/lib/gir_ffi/builders/interface_builder.rb +1 -0
  86. data/lib/gir_ffi/builders/mapping_method_builder.rb +15 -37
  87. data/lib/gir_ffi/builders/marshalling_method_builder.rb +9 -26
  88. data/lib/gir_ffi/builders/method_template.rb +4 -3
  89. data/lib/gir_ffi/builders/module_builder.rb +2 -1
  90. data/lib/gir_ffi/builders/null_argument_builder.rb +1 -0
  91. data/lib/gir_ffi/builders/null_class_builder.rb +1 -0
  92. data/lib/gir_ffi/builders/null_convertor.rb +1 -0
  93. data/lib/gir_ffi/builders/null_return_value_builder.rb +1 -0
  94. data/lib/gir_ffi/builders/object_builder.rb +1 -0
  95. data/lib/gir_ffi/builders/property_builder.rb +1 -0
  96. data/lib/gir_ffi/builders/registered_type_builder.rb +1 -0
  97. data/lib/gir_ffi/builders/return_value_builder.rb +1 -0
  98. data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +1 -0
  99. data/lib/gir_ffi/builders/signal_closure_builder.rb +2 -7
  100. data/lib/gir_ffi/builders/struct_builder.rb +1 -0
  101. data/lib/gir_ffi/builders/type_builder.rb +1 -0
  102. data/lib/gir_ffi/builders/unintrospectable_boxed_builder.rb +1 -0
  103. data/lib/gir_ffi/builders/unintrospectable_builder.rb +1 -0
  104. data/lib/gir_ffi/builders/union_builder.rb +1 -0
  105. data/lib/gir_ffi/builders/user_defined_builder.rb +1 -0
  106. data/lib/gir_ffi/builders/vfunc_argument_builder.rb +1 -0
  107. data/lib/gir_ffi/builders/vfunc_builder.rb +2 -9
  108. data/lib/gir_ffi/builders/with_layout.rb +1 -0
  109. data/lib/gir_ffi/callback_base.rb +1 -0
  110. data/lib/gir_ffi/class_base.rb +1 -0
  111. data/lib/gir_ffi/core.rb +1 -0
  112. data/lib/gir_ffi/enum_base.rb +1 -0
  113. data/lib/gir_ffi/error_argument_info.rb +1 -0
  114. data/lib/gir_ffi/error_type_info.rb +1 -0
  115. data/lib/gir_ffi/ffi_ext/pointer.rb +1 -0
  116. data/lib/gir_ffi/ffi_ext.rb +1 -0
  117. data/lib/gir_ffi/field_argument_info.rb +1 -0
  118. data/lib/gir_ffi/flags_base.rb +1 -0
  119. data/lib/gir_ffi/g_type.rb +1 -0
  120. data/lib/gir_ffi/glib_error.rb +1 -0
  121. data/lib/gir_ffi/in_out_pointer.rb +1 -0
  122. data/lib/gir_ffi/in_pointer.rb +1 -0
  123. data/lib/gir_ffi/info_ext/full_type_name.rb +1 -0
  124. data/lib/gir_ffi/info_ext/i_arg_info.rb +1 -0
  125. data/lib/gir_ffi/info_ext/i_callable_info.rb +1 -0
  126. data/lib/gir_ffi/info_ext/i_callback_info.rb +1 -0
  127. data/lib/gir_ffi/info_ext/i_field_info.rb +1 -0
  128. data/lib/gir_ffi/info_ext/i_function_info.rb +1 -0
  129. data/lib/gir_ffi/info_ext/i_property_info.rb +1 -0
  130. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +1 -0
  131. data/lib/gir_ffi/info_ext/i_signal_info.rb +1 -0
  132. data/lib/gir_ffi/info_ext/i_type_info.rb +1 -1
  133. data/lib/gir_ffi/info_ext/i_unresolved_info.rb +1 -0
  134. data/lib/gir_ffi/info_ext/i_vfunc_info.rb +1 -0
  135. data/lib/gir_ffi/info_ext/safe_constant_name.rb +1 -0
  136. data/lib/gir_ffi/info_ext/safe_function_name.rb +1 -0
  137. data/lib/gir_ffi/info_ext.rb +1 -0
  138. data/lib/gir_ffi/interface_base.rb +1 -0
  139. data/lib/gir_ffi/lib_c.rb +1 -0
  140. data/lib/gir_ffi/method_stubber.rb +1 -0
  141. data/lib/gir_ffi/module_base.rb +1 -0
  142. data/lib/gir_ffi/object_base.rb +1 -0
  143. data/lib/gir_ffi/object_store.rb +1 -0
  144. data/lib/gir_ffi/property_not_found_error.rb +1 -0
  145. data/lib/gir_ffi/receiver_argument_info.rb +1 -0
  146. data/lib/gir_ffi/receiver_type_info.rb +1 -0
  147. data/lib/gir_ffi/registered_type_base.rb +1 -0
  148. data/lib/gir_ffi/return_value_info.rb +1 -0
  149. data/lib/gir_ffi/signal_not_found_error.rb +1 -0
  150. data/lib/gir_ffi/sized_array.rb +1 -0
  151. data/lib/gir_ffi/struct_base.rb +1 -0
  152. data/lib/gir_ffi/type_base.rb +1 -0
  153. data/lib/gir_ffi/type_map.rb +1 -0
  154. data/lib/gir_ffi/unintrospectable_signal_info.rb +1 -0
  155. data/lib/gir_ffi/unintrospectable_type_info.rb +1 -0
  156. data/lib/gir_ffi/union_base.rb +1 -0
  157. data/lib/gir_ffi/user_data_argument_info.rb +1 -0
  158. data/lib/gir_ffi/user_data_type_info.rb +1 -0
  159. data/lib/gir_ffi/user_defined_property_info.rb +1 -0
  160. data/lib/gir_ffi/user_defined_type_info.rb +1 -0
  161. data/lib/gir_ffi/variable_name_generator.rb +1 -0
  162. data/lib/gir_ffi/version.rb +1 -1
  163. data/lib/gir_ffi/vfunc_implementation.rb +1 -0
  164. data/lib/gir_ffi/zero_terminated.rb +1 -0
  165. data/lib/gir_ffi-base/glib/boolean.rb +1 -0
  166. data/lib/gir_ffi-base/glib/strv.rb +1 -0
  167. data/lib/gir_ffi-base/gobject/lib.rb +1 -0
  168. data/lib/gir_ffi-base/gobject.rb +1 -0
  169. data/lib/gir_ffi-base.rb +1 -0
  170. data/lib/gir_ffi.rb +1 -0
  171. data/test/base_test_helper.rb +1 -0
  172. data/test/ffi-glib/array_test.rb +1 -0
  173. data/test/ffi-glib/byte_array_test.rb +1 -0
  174. data/test/ffi-glib/bytes_test.rb +1 -0
  175. data/test/ffi-glib/destroy_notify_test.rb +1 -0
  176. data/test/ffi-glib/hash_table_test.rb +1 -0
  177. data/test/ffi-glib/iconv_test.rb +1 -0
  178. data/test/ffi-glib/list_test.rb +1 -0
  179. data/test/ffi-glib/main_loop_test.rb +1 -0
  180. data/test/ffi-glib/ptr_array_test.rb +1 -0
  181. data/test/ffi-glib/ruby_closure_test.rb +1 -0
  182. data/test/ffi-glib/s_list_test.rb +1 -0
  183. data/test/ffi-glib/strv_test.rb +1 -0
  184. data/test/ffi-glib/variant_test.rb +1 -0
  185. data/test/ffi-gobject/gobject_test.rb +1 -0
  186. data/test/ffi-gobject/object_class_test.rb +1 -0
  187. data/test/ffi-gobject/object_test.rb +1 -0
  188. data/test/ffi-gobject/value_test.rb +1 -0
  189. data/test/ffi-gobject_introspection/i_base_info_test.rb +1 -0
  190. data/test/ffi-gobject_introspection/i_constant_info_test.rb +1 -0
  191. data/test/ffi-gobject_introspection/i_enum_info_test.rb +1 -0
  192. data/test/ffi-gobject_introspection/i_function_info_test.rb +1 -0
  193. data/test/ffi-gobject_introspection/i_interface_info_test.rb +1 -0
  194. data/test/ffi-gobject_introspection/i_object_info_test.rb +1 -0
  195. data/test/ffi-gobject_introspection/i_property_info_test.rb +1 -0
  196. data/test/ffi-gobject_introspection/i_registered_type_info_test.rb +1 -0
  197. data/test/ffi-gobject_introspection/i_repository_test.rb +1 -0
  198. data/test/ffi-gobject_introspection/i_struct_info_test.rb +1 -0
  199. data/test/ffi-gobject_introspection/i_type_info_test.rb +1 -0
  200. data/test/ffi-gobject_introspection/i_union_info_test.rb +1 -0
  201. data/test/ffi-gobject_introspection/lib_test.rb +1 -0
  202. data/test/ffi-gobject_test.rb +1 -0
  203. data/test/gir_ffi/arg_helper_test.rb +1 -0
  204. data/test/gir_ffi/builder_test.rb +1 -0
  205. data/test/gir_ffi/builders/argument_builder_test.rb +17 -0
  206. data/test/gir_ffi/builders/base_argument_builder_test.rb +1 -0
  207. data/test/gir_ffi/builders/callback_argument_builder_test.rb +1 -0
  208. data/test/gir_ffi/builders/callback_builder_test.rb +1 -0
  209. data/test/gir_ffi/builders/callback_return_value_builder_test.rb +1 -0
  210. data/test/gir_ffi/builders/constant_builder_test.rb +1 -0
  211. data/test/gir_ffi/builders/constructor_builder_test.rb +1 -0
  212. data/test/gir_ffi/builders/enum_builder_test.rb +1 -0
  213. data/test/gir_ffi/builders/field_builder_test.rb +1 -0
  214. data/test/gir_ffi/builders/function_builder_test.rb +30 -1
  215. data/test/gir_ffi/builders/initializer_builder_test.rb +1 -0
  216. data/test/gir_ffi/builders/interface_builder_test.rb +1 -0
  217. data/test/gir_ffi/builders/module_builder_test.rb +1 -0
  218. data/test/gir_ffi/builders/object_builder_test.rb +1 -0
  219. data/test/gir_ffi/builders/property_builder_test.rb +1 -0
  220. data/test/gir_ffi/builders/registered_type_builder_test.rb +1 -0
  221. data/test/gir_ffi/builders/return_value_builder_test.rb +1 -0
  222. data/test/gir_ffi/builders/signal_closure_builder_test.rb +1 -0
  223. data/test/gir_ffi/builders/struct_builder_test.rb +1 -0
  224. data/test/gir_ffi/builders/unintrospectable_boxed_builder_test.rb +1 -0
  225. data/test/gir_ffi/builders/unintrospectable_builder_test.rb +1 -0
  226. data/test/gir_ffi/builders/union_builder_test.rb +1 -0
  227. data/test/gir_ffi/builders/user_defined_builder_test.rb +1 -0
  228. data/test/gir_ffi/builders/vfunc_builder_test.rb +1 -0
  229. data/test/gir_ffi/callback_base_test.rb +1 -0
  230. data/test/gir_ffi/class_base_test.rb +1 -0
  231. data/test/gir_ffi/error_type_info_test.rb +1 -0
  232. data/test/gir_ffi/ffi_ext/pointer_test.rb +1 -0
  233. data/test/gir_ffi/g_type_test.rb +1 -0
  234. data/test/gir_ffi/in_out_pointer_test.rb +1 -0
  235. data/test/gir_ffi/in_pointer_test.rb +1 -0
  236. data/test/gir_ffi/info_ext/i_callable_info_test.rb +1 -0
  237. data/test/gir_ffi/info_ext/i_callback_info_test.rb +1 -0
  238. data/test/gir_ffi/info_ext/i_field_info_test.rb +1 -0
  239. data/test/gir_ffi/info_ext/i_function_info_test.rb +1 -0
  240. data/test/gir_ffi/info_ext/i_signal_info_test.rb +1 -0
  241. data/test/gir_ffi/info_ext/i_type_info_test.rb +1 -0
  242. data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +1 -0
  243. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +1 -0
  244. data/test/gir_ffi/info_ext/safe_function_name_test.rb +1 -0
  245. data/test/gir_ffi/interface_base_test.rb +1 -0
  246. data/test/gir_ffi/method_stubber_test.rb +1 -0
  247. data/test/gir_ffi/object_base_test.rb +1 -0
  248. data/test/gir_ffi/sized_array_test.rb +1 -0
  249. data/test/gir_ffi/type_map_test.rb +1 -0
  250. data/test/gir_ffi/unintrospectable_type_info_test.rb +1 -0
  251. data/test/gir_ffi/user_defined_property_info_test.rb +1 -0
  252. data/test/gir_ffi/user_defined_type_info_test.rb +1 -0
  253. data/test/gir_ffi/variable_name_generator_test.rb +1 -0
  254. data/test/gir_ffi/version_test.rb +1 -0
  255. data/test/gir_ffi/zero_terminated_test.rb +1 -0
  256. data/test/gir_ffi-base/glib/boolean_test.rb +2 -1
  257. data/test/gir_ffi-base/glib/strv_test.rb +1 -0
  258. data/test/gir_ffi_test.rb +1 -0
  259. data/test/gir_ffi_test_helper.rb +1 -0
  260. data/test/integration/callback_exceptions_test.rb +1 -0
  261. data/test/integration/derived_classes_test.rb +1 -0
  262. data/test/integration/generated_everything_test.rb +1 -0
  263. data/test/integration/generated_gimarshallingtests_test.rb +1 -0
  264. data/test/integration/generated_gio_test.rb +1 -0
  265. data/test/integration/generated_glib_test.rb +1 -0
  266. data/test/integration/generated_gobject_test.rb +1 -0
  267. data/test/integration/generated_gst_test.rb +1 -0
  268. data/test/integration/generated_gtop_test.rb +1 -0
  269. data/test/integration/generated_pango_ft2_test.rb +1 -0
  270. data/test/integration/generated_pango_test.rb +1 -0
  271. data/test/integration/generated_regress_test.rb +2 -2
  272. data/test/integration/generated_secret_test.rb +1 -0
  273. data/test/integration/generated_warnlib_test.rb +1 -0
  274. data/test/integration/method_lookup_test.rb +1 -0
  275. data/test/introspection_test_helper.rb +1 -0
  276. data/test/minitest/stats_plugin.rb +1 -0
  277. metadata +19 -19
  278. data/lib/gir_ffi/builders/error_argument_builder.rb +0 -34
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/allocation_helper'
2
3
  require 'gir_ffi/builder'
3
4
  require 'gir_ffi/glib_error'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/class_base'
2
3
 
3
4
  module GirFFI
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/builders/type_builder'
2
3
  require 'gir_ffi/builders/module_builder'
3
4
  require 'gir_ffi/builder_helper'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  # Set of helper methods used in the builders.
3
4
  module BuilderHelper
@@ -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
- case direction
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 has_post_conversion?
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
- (direction == :inout || direction == :in) && !skipped?
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
- block = nil
41
- argument_builders.each do |it|
42
- name = it.method_argument_name
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,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  module Builders
3
4
  # Abstract parent class of the argument building classes. These
@@ -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 vargen
15
- @vargen ||= VariableNameGenerator.new
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 ||= @info.args.map { |arg| ArgumentBuilder.new vargen, arg }
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 ||= ArgumentBuilderCollection.new(
40
- @return_value_builder, argument_builders,
41
- error_argument_builder: error_argument)
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.throws?
47
- ErrorArgumentBuilder.new vargen, ErrorArgumentInfo.new
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/builder_helper'
2
3
 
3
4
  module GirFFI
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/builders/registered_type_builder'
2
3
  require 'gir_ffi/builders/with_layout'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  module Builders
3
4
  # Builder that generates code to convert values from C to Ruby. Used by
@@ -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
- return_value_info = ReturnValueInfo.new(info.return_type,
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/return_value_builder'
2
3
  require 'gir_ffi/builders/ruby_to_c_convertor'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/builders/callback_argument_builder'
2
3
 
3
4
  module GirFFI
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  module Builders
3
4
  # Builder that generates code to convert closure arguments ('user data')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/builders/callback_return_value_builder'
2
3
 
3
4
  module GirFFI
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  module Builders
3
4
  # Builder that generates code to convert closure arguments ('user data')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/builders/base_type_builder'
2
3
  module GirFFI
3
4
  module Builders
@@ -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/c_to_ruby_convertor'
2
3
 
3
4
  module GirFFI
@@ -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
- @info = info
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
- @info = info
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,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/builders/base_argument_builder'
2
3
 
3
4
  module GirFFI
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/builders/registered_type_builder'
2
3
  require 'gir_ffi/interface_base'
3
4
 
@@ -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/method_template'
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
- # TODO: Inherit from BaseMethodBuilder
15
- class MappingMethodBuilder
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, argument_infos, return_value_info)
21
- new receiver_info, argument_infos, return_value_info, VFuncArgumentBuilder
19
+ def self.for_vfunc(receiver_info, info)
20
+ new receiver_info, info, VFuncArgumentBuilder
22
21
  end
23
22
 
24
- def initialize(receiver_info, argument_infos, return_value_info, builder_class)
25
- @argument_builder_class = builder_class
26
- receiver_builder = make_argument_builder receiver_info if receiver_info
27
- argument_builders = argument_infos.map { |info| make_argument_builder info }
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
- def method_definition
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
- @argument_builder_collection.method_argument_names.dup.unshift('_proc')
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 = @argument_builder_collection.return_value_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
- @argument_builder_collection.call_argument_names.join(', ')
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
- # TODO: Inherit from BaseMethodBuilder
14
- class MarshallingMethodBuilder
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, argument_infos, return_value_info)
20
- receiver_builder = make_argument_builder receiver_info
21
- argument_builders = argument_infos.map { |arg| make_argument_builder arg }
22
- return_value_builder =
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
- def method_definition
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 << "(#{method_arguments.join(', ')})" if method_arguments.any?
21
- method_lines.each { |line| code << "\n #{line}" }
22
- code << "\nend\n"
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  # Argument builder that does nothing. Implements the Null Object pattern.
3
4
  class NullArgumentBuilder
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  module Builders
3
4
  # Class builder that does nothing
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  module Builders
3
4
  # Argument convertor that does nothing
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  module Builders
3
4
  # Implements a blank return value matching ReturnValueBuilder's interface.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/builders/registered_type_builder'
2
3
  require 'gir_ffi/builders/with_layout'
3
4
  require 'gir_ffi/builders/property_builder'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  module Builders
3
4
  # Creates property getter and setter code for a given IPropertyInfo.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/builders/base_type_builder'
2
3
  require 'gir_ffi/method_stubber'
3
4
  require 'gir_ffi/builders/function_builder'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'gir_ffi/builders/base_argument_builder'
2
3
  require 'gir_ffi/builders/full_c_to_ruby_convertor'
3
4
  require 'gir_ffi/builders/closure_convertor'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GirFFI
2
3
  module Builders
3
4
  # Builder that generates code to convert values from Ruby to C. Used by