gir_ffi 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +80 -73
  3. data/Gemfile +2 -0
  4. data/README.md +2 -2
  5. data/lib/ffi-glib/array.rb +6 -6
  6. data/lib/ffi-glib/bytes.rb +5 -5
  7. data/lib/ffi-glib/container_class_methods.rb +6 -6
  8. data/lib/ffi-glib/error.rb +4 -4
  9. data/lib/ffi-glib/main_loop.rb +8 -8
  10. data/lib/ffi-glib/ptr_array.rb +2 -2
  11. data/lib/ffi-glib/strv.rb +5 -5
  12. data/lib/ffi-glib/variant.rb +3 -3
  13. data/lib/ffi-gobject.rb +1 -0
  14. data/lib/ffi-gobject/closure.rb +2 -2
  15. data/lib/ffi-gobject/object.rb +37 -15
  16. data/lib/ffi-gobject/value.rb +5 -5
  17. data/lib/ffi-gobject_introspection/i_registered_type_info.rb +1 -1
  18. data/lib/gir_ffi/builders/argument_builder.rb +1 -3
  19. data/lib/gir_ffi/builders/argument_builder_collection.rb +6 -6
  20. data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +1 -5
  21. data/lib/gir_ffi/builders/callback_argument_builder.rb +2 -6
  22. data/lib/gir_ffi/builders/module_builder.rb +1 -3
  23. data/lib/gir_ffi/builders/null_class_builder.rb +2 -2
  24. data/lib/gir_ffi/builders/user_defined_builder.rb +7 -17
  25. data/lib/gir_ffi/builders/with_layout.rb +1 -1
  26. data/lib/gir_ffi/class_base.rb +4 -8
  27. data/lib/gir_ffi/enum_like_base.rb +2 -4
  28. data/lib/gir_ffi/instance_method_setup.rb +14 -0
  29. data/lib/gir_ffi/interface_base.rb +4 -8
  30. data/lib/gir_ffi/method_setup.rb +14 -0
  31. data/lib/gir_ffi/module_base.rb +4 -4
  32. data/lib/gir_ffi/object_base.rb +2 -2
  33. data/lib/gir_ffi/sized_array.rb +4 -3
  34. data/lib/gir_ffi/version.rb +1 -1
  35. data/tasks/test.rake +60 -60
  36. data/test/gir_ffi/builder_test.rb +1 -1
  37. data/test/integration/generated_regress_test.rb +1 -1
  38. metadata +5 -3
@@ -23,14 +23,14 @@ module GLib
23
23
  data.each(&block)
24
24
  end
25
25
 
26
- def self.from(it)
27
- case it
26
+ def self.from(obj)
27
+ case obj
28
28
  when self
29
- it
29
+ obj
30
30
  when FFI::Pointer
31
- wrap it
31
+ wrap obj
32
32
  else
33
- new it
33
+ new obj
34
34
  end
35
35
  end
36
36
 
@@ -22,18 +22,18 @@ module GLib
22
22
  end
23
23
  end
24
24
 
25
- def from(typespec = :void, it)
26
- case it
25
+ def from(typespec = :void, obj)
26
+ case obj
27
27
  when nil
28
28
  nil
29
29
  when FFI::Pointer
30
- wrap typespec, it
30
+ wrap typespec, obj
31
31
  when self
32
- it.reset_typespec typespec
32
+ obj.reset_typespec typespec
33
33
  when GirFFI::BoxedBase
34
- wrap typespec, it.to_ptr
34
+ wrap typespec, obj.to_ptr
35
35
  else
36
- from_enumerable typespec, it
36
+ from_enumerable typespec, obj
37
37
  end
38
38
  end
39
39
  end
@@ -7,12 +7,12 @@ module GLib
7
7
  class Error
8
8
  GIR_FFI_DOMAIN = GLib.quark_from_string('gir_ffi')
9
9
 
10
- def self.from_exception(ex)
11
- new_literal GIR_FFI_DOMAIN, 0, ex.message
10
+ def self.from_exception(exception)
11
+ new_literal GIR_FFI_DOMAIN, 0, exception.message
12
12
  end
13
13
 
14
- def self.from(it)
15
- from_exception it
14
+ def self.from(obj)
15
+ from_exception obj
16
16
  end
17
17
  end
18
18
  end
@@ -37,27 +37,27 @@ module GLib
37
37
  EXCEPTIONS = []
38
38
  RUNNING_LOOPS = []
39
39
 
40
- setup_instance_method :run
40
+ setup_instance_method! :run
41
41
 
42
42
  def run_with_thread_enabler
43
43
  ThreadEnabler.instance.setup_idle_handler if RUBY_ENGINE == 'ruby'
44
44
  RUNNING_LOOPS << self
45
45
  result = run_without_thread_enabler
46
- ex = EXCEPTIONS.shift
46
+ exception = EXCEPTIONS.shift
47
47
  RUNNING_LOOPS.pop
48
- raise ex if ex
48
+ raise exception if exception
49
49
  result
50
50
  end
51
51
 
52
- def self.handle_exception(ex)
52
+ def self.handle_exception(exception)
53
53
  current_loop = RUNNING_LOOPS.last
54
- raise ex unless current_loop
55
- EXCEPTIONS << ex
54
+ raise exception unless current_loop
55
+ EXCEPTIONS << exception
56
56
  current_loop.quit
57
57
  end
58
58
 
59
- alias_method :run_without_thread_enabler, :run
60
- alias_method :run, :run_with_thread_enabler
59
+ alias run_without_thread_enabler run
60
+ alias run run_with_thread_enabler
61
61
  end
62
62
  end
63
63
 
@@ -27,8 +27,8 @@ module GLib
27
27
  store_pointer Lib.g_ptr_array_new
28
28
  end
29
29
 
30
- def self.from_enumerable(type, it)
31
- new(type).tap { |arr| arr.add_array it }
30
+ def self.from_enumerable(type, arr)
31
+ new(type).tap { |it| it.add_array arr }
32
32
  end
33
33
 
34
34
  def self.add(array, data)
data/lib/ffi-glib/strv.rb CHANGED
@@ -10,16 +10,16 @@ module GLib
10
10
  to_a == other.to_a
11
11
  end
12
12
 
13
- def self.from(it)
14
- case it
13
+ def self.from(obj)
14
+ case obj
15
15
  when nil
16
16
  nil
17
17
  when FFI::Pointer
18
- wrap it
18
+ wrap obj
19
19
  when self
20
- it
20
+ obj
21
21
  else
22
- from_enumerable it
22
+ from_enumerable obj
23
23
  end
24
24
  end
25
25
 
@@ -5,14 +5,14 @@ GLib.load_class :Variant
5
5
  module GLib
6
6
  # Overrides for GVariant, GLib's variant data type.
7
7
  class Variant
8
- setup_instance_method 'get_string'
8
+ setup_instance_method! 'get_string'
9
9
 
10
10
  def get_string_with_override
11
11
  get_string_without_override.first
12
12
  end
13
13
 
14
- alias_method :get_string_without_override, :get_string
15
- alias_method :get_string, :get_string_with_override
14
+ alias get_string_without_override get_string
15
+ alias get_string get_string_with_override
16
16
 
17
17
  # Initializing method used in constructors. For Variant, this needs to sink
18
18
  # the variant's floating reference.
data/lib/ffi-gobject.rb CHANGED
@@ -87,6 +87,7 @@ module GObject
87
87
  attach_function :g_object_ref_sink, [:pointer], :pointer
88
88
  attach_function :g_object_ref, [:pointer], :pointer
89
89
  attach_function :g_object_unref, [:pointer], :pointer
90
+ attach_function :g_object_new, [:size_t, :pointer], :pointer
90
91
 
91
92
  attach_function :g_value_copy, [:pointer, :pointer], :void
92
93
  attach_function :g_value_init, [:pointer, :size_t], :pointer
@@ -7,8 +7,8 @@ module GObject
7
7
  #
8
8
  # To create Closure objects wrapping Ruby code, use {RubyClosure}.
9
9
  class Closure
10
- setup_method :new_simple
11
- setup_instance_method :invoke
10
+ setup_method! :new_simple
11
+ setup_instance_method! :invoke
12
12
 
13
13
  # @override
14
14
  #
@@ -7,11 +7,20 @@ GObject.load_class :Object
7
7
  module GObject
8
8
  # Overrides for GObject, GObject's generic base class.
9
9
  class Object
10
- setup_method 'new'
11
10
  if !GLib.check_version(2, 54, 0)
12
- setup_method 'newv'
11
+ GObject::Lib.attach_function(:g_object_new_with_properties,
12
+ [:size_t, :uint32, :pointer, :pointer],
13
+ :pointer)
14
+
15
+ def self.new(*args, &block)
16
+ obj = allocate
17
+ obj.__send__ :initialize, *args, &block
18
+ obj
19
+ end
13
20
 
14
- def initialize_with_automatic_gtype(properties = {})
21
+ # Starting with GLib 2.54.0, use g_object_new_with_properties, which
22
+ # takes an array of names and an array of values.
23
+ def initialize(properties = {})
15
24
  names = []
16
25
  values = []
17
26
  properties.each do |name, value|
@@ -22,9 +31,21 @@ module GObject
22
31
  names << name
23
32
  values << gvalue
24
33
  end
25
- initialize_without_automatic_gtype(self.class.gtype, names, values)
34
+
35
+ n_properties = names.length
36
+ names_arr = GirFFI::SizedArray.from(:utf8, -1, names)
37
+ values_arr = GirFFI::SizedArray.from(GObject::Value, -1, values)
38
+
39
+ ptr = GObject::Lib.g_object_new_with_properties(self.class.gtype,
40
+ n_properties,
41
+ names_arr,
42
+ values_arr)
43
+ store_pointer ptr
26
44
  end
27
45
  else
46
+ setup_method! 'new'
47
+
48
+ # Before GLib 2.54.0, use g_object_newv, which takes an array of GParameter.
28
49
  def initialize_with_automatic_gtype(properties = {})
29
50
  gparameters = properties.map do |name, value|
30
51
  name = name.to_s
@@ -36,11 +57,12 @@ module GObject
36
57
  end
37
58
  initialize_without_automatic_gtype(self.class.gtype, gparameters)
38
59
  end
60
+
61
+ alias initialize_without_automatic_gtype initialize
62
+ alias initialize initialize_with_automatic_gtype
39
63
  end
40
64
 
41
- alias_method :initialize_without_automatic_gtype, :initialize
42
- alias_method :initialize, :initialize_with_automatic_gtype
43
- alias_method :base_initialize, :initialize
65
+ alias base_initialize initialize
44
66
 
45
67
  private :base_initialize
46
68
 
@@ -90,8 +112,8 @@ module GObject
90
112
  GObject.signal_connect_after(self, event, data, &block)
91
113
  end
92
114
 
93
- setup_instance_method 'get_property'
94
- setup_instance_method 'set_property'
115
+ setup_instance_method! 'get_property'
116
+ setup_instance_method! 'set_property'
95
117
 
96
118
  def get_property_extended(property_name)
97
119
  value = get_property(property_name)
@@ -117,14 +139,14 @@ module GObject
117
139
  set_property_without_override property_name, gvalue
118
140
  end
119
141
 
120
- alias_method :get_property_without_override, :get_property
121
- alias_method :get_property, :get_property_with_override
142
+ alias get_property_without_override get_property
143
+ alias get_property get_property_with_override
122
144
 
123
- alias_method :set_property_without_override, :set_property
124
- alias_method :set_property, :set_property_with_override
145
+ alias set_property_without_override set_property
146
+ alias set_property set_property_with_override
125
147
 
126
- setup_instance_method 'is_floating'
127
- alias_method :floating?, :is_floating
148
+ setup_instance_method! 'is_floating'
149
+ alias floating? is_floating
128
150
 
129
151
  private
130
152
 
@@ -58,7 +58,7 @@ module GObject
58
58
  send set_method, val
59
59
  end
60
60
 
61
- alias_method :value=, :set_value
61
+ alias value= set_value
62
62
 
63
63
  def current_gtype
64
64
  @struct[:g_type]
@@ -146,7 +146,7 @@ module GObject
146
146
  raise "Can't handle #{val.class}"
147
147
  end
148
148
 
149
- def set_none(_); end
149
+ def set_none(_val); end
150
150
 
151
151
  def get_none; end
152
152
 
@@ -169,9 +169,9 @@ module GObject
169
169
  end
170
170
 
171
171
  def check_type_compatibility(val)
172
- unless GObject::Value.type_compatible(GObject.type_from_instance(val), current_gtype)
173
- raise ArgumentError, "#{val.class} is incompatible with #{current_gtype_name}"
174
- end
172
+ return if GObject::Value.type_compatible(GObject.type_from_instance(val), current_gtype)
173
+
174
+ raise ArgumentError, "#{val.class} is incompatible with #{current_gtype_name}"
175
175
  end
176
176
 
177
177
  def wrap_boxed(boxed)
@@ -16,6 +16,6 @@ module GObjectIntrospection
16
16
  Lib.g_registered_type_info_get_g_type @gobj
17
17
  end
18
18
 
19
- alias_method :gtype, :g_type
19
+ alias gtype g_type
20
20
  end
21
21
  end
@@ -32,9 +32,7 @@ module GirFFI
32
32
  end
33
33
 
34
34
  def return_value_name
35
- if has_output_value?
36
- post_converted_name unless array_length_parameter?
37
- end
35
+ post_converted_name if has_output_value? && !array_length_parameter?
38
36
  end
39
37
 
40
38
  def capture_variable_name
@@ -76,13 +76,13 @@ module GirFFI
76
76
  end
77
77
  end
78
78
  all_builders.each do |bldr|
79
- if (idx = bldr.array_length_idx) >= 0
80
- other = @base_argument_builders[idx]
81
- next unless other
79
+ idx = bldr.array_length_idx
80
+ next unless idx >= 0
81
+ other = @base_argument_builders[idx]
82
+ next unless other
82
83
 
83
- bldr.length_arg = other
84
- other.array_arg = bldr
85
- end
84
+ bldr.length_arg = other
85
+ other.array_arg = bldr
86
86
  end
87
87
  end
88
88
 
@@ -60,11 +60,7 @@ module GirFFI
60
60
  end
61
61
 
62
62
  def array_size
63
- if @length_arg
64
- @length_arg
65
- else
66
- @type_info.array_fixed_size
67
- end
63
+ @length_arg || @type_info.array_fixed_size
68
64
  end
69
65
 
70
66
  def argument_class
@@ -37,15 +37,11 @@ module GirFFI
37
37
  end
38
38
 
39
39
  def call_argument_name
40
- if [:in, :inout].include? direction
41
- pre_converted_name unless array_arg
42
- end
40
+ pre_converted_name if [:in, :inout].include?(direction) && !array_arg
43
41
  end
44
42
 
45
43
  def capture_variable_name
46
- unless array_arg
47
- result_name if [:out, :inout].include? direction
48
- end
44
+ result_name if [:out, :inout].include?(direction) && !array_arg
49
45
  end
50
46
 
51
47
  def pre_conversion
@@ -90,9 +90,7 @@ module GirFFI
90
90
  lib.extend FFI::Library
91
91
  lib.extend FFI::BitMasks
92
92
  lib.ffi_lib_flags :global, :lazy
93
- if shared_library_specification
94
- lib.ffi_lib(*shared_library_specification.split(/,/))
95
- end
93
+ lib.ffi_lib(*shared_library_specification.split(/,/)) if shared_library_specification
96
94
  end
97
95
 
98
96
  def shared_library_specification
@@ -4,11 +4,11 @@ module GirFFI
4
4
  module Builders
5
5
  # Class builder that does nothing
6
6
  class NullClassBuilder
7
- def setup_method(_)
7
+ def setup_method(_method)
8
8
  nil
9
9
  end
10
10
 
11
- def setup_instance_method(_)
11
+ def setup_instance_method(_method)
12
12
  nil
13
13
  end
14
14
  end
@@ -127,7 +127,7 @@ module GirFFI
127
127
  superclass.gir_ffi_builder.object_class_struct::Struct.new(object_class_ptr)
128
128
 
129
129
  info.vfunc_implementations.each do |impl|
130
- setup_vfunc super_class_struct, impl
130
+ setup_vfunc parent_info, super_class_struct, impl
131
131
  end
132
132
  end
133
133
 
@@ -138,26 +138,16 @@ module GirFFI
138
138
  interface_info = interface_builder.info
139
139
 
140
140
  info.vfunc_implementations.each do |impl|
141
- setup_interface_vfunc interface_info, interface_struct, impl
141
+ setup_vfunc interface_info, interface_struct, impl
142
142
  end
143
143
  end
144
144
 
145
- def setup_vfunc(super_class_struct, impl)
145
+ def setup_vfunc(ancestor_info, ancestor_struct, impl)
146
146
  vfunc_name = impl.name
147
- vfunc_info = parent_info.find_vfunc vfunc_name.to_s
147
+ vfunc_info = ancestor_info.find_vfunc vfunc_name.to_s
148
+ return unless vfunc_info
148
149
 
149
- if vfunc_info
150
- install_vfunc super_class_struct, vfunc_name, vfunc_info, impl.implementation
151
- end
152
- end
153
-
154
- def setup_interface_vfunc(interface_info, interface_struct, impl)
155
- vfunc_name = impl.name
156
- vfunc_info = interface_info.find_vfunc vfunc_name.to_s
157
-
158
- if vfunc_info
159
- install_vfunc interface_struct, vfunc_name, vfunc_info, impl.implementation
160
- end
150
+ install_vfunc ancestor_struct, vfunc_name, vfunc_info, impl.implementation
161
151
  end
162
152
 
163
153
  def install_vfunc(container_struct, vfunc_name, vfunc_info, implementation)
@@ -265,7 +255,7 @@ module GirFFI
265
255
  def setup_constructor
266
256
  code = <<-CODE
267
257
  def initialize
268
- ptr = GObject::Lib.g_object_newv #{@gtype}, 0, nil
258
+ ptr = GObject::Lib.g_object_new #{@gtype}, nil
269
259
  store_pointer(ptr)
270
260
  end
271
261
  CODE