gobject-introspection 4.3.9 → 4.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e39e6feae1d2623095aa26ad12481c07726a5f797999e23fdc98b103ce083288
4
- data.tar.gz: c4fea6dd3fd14c5ec51193396e052dacce887bac6c035dc82963c92fe0f6e125
3
+ metadata.gz: a71466d8733cb6b96ea22ef764d7f57fe757c694bc23468f181ec0404527a9d3
4
+ data.tar.gz: 4e3f8b8646372d617e2245cec2b9d24aa15cd35ac7e86186a70880b9b511eb40
5
5
  SHA512:
6
- metadata.gz: ce675d17cb6870a8b8a27ffe5ac5c806bab2d5f3da6b4e04e3ba2774b36e1587167212d622ded13ddfb9fd9d44fe43a4e842bf8ce9c7396d095d1549d2d2448f
7
- data.tar.gz: 2c41300a2740d624ab4c00d7e4bc588cbc22dc10adf629a0996d9da5cab791197167e7a30fdf93df87f1abfa40d08b29918a795f41cc19850bcc54bf3a28f3ce
6
+ metadata.gz: db687934ad2f486086aa3ceb4e9fe3987fcc7a292e3aec7e56f44afb1658a4e5d80eb0b21a8f969b016680148fe749eb59d47ce2e45d19732b04768b4ad01a10
7
+ data.tar.gz: 656e9922a8db31271a112c99879623e84b138606dfe310f6e392b843d343673f6ae2cee4f3e4972444b211c391fc1ac2a3512f14d316b02dfcfccc16d3286d7f
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012-2022 Ruby-GNOME Project Team
3
+ * Copyright (C) 2012-2026 Ruby-GNOME Project Team
4
4
  *
5
5
  * This library is free software; you can redistribute it and/or
6
6
  * modify it under the terms of the GNU Lesser General Public
@@ -828,13 +828,26 @@ rb_gi_arguments_in_init_arg_ruby_array_c(RBGIArguments *args,
828
828
  gchar *raw_array = RSTRING_PTR(rb_arg);
829
829
  gsize length = RSTRING_LEN(rb_arg);
830
830
  if (metadata->transfer != GI_TRANSFER_NOTHING) {
831
- rb_raise(rb_eNotImpError,
832
- "TODO: [%s] %s Ruby -> GIArgument(array/%s)[%s][%s]",
833
- metadata->name,
834
- rb_gi_direction_to_string(metadata->direction),
835
- rb_gi_array_type_to_string(metadata->array_type),
836
- g_type_tag_to_string(metadata->element_type.tag),
837
- rb_gi_transfer_to_string(metadata->transfer));
831
+ if (metadata->direction == GI_DIRECTION_INOUT) {
832
+ rb_raise(rb_eNotImpError,
833
+ "TODO: [%s] %s Ruby -> GIArgument(array/%s)[%s][%s]",
834
+ metadata->name,
835
+ rb_gi_direction_to_string(metadata->direction),
836
+ rb_gi_array_type_to_string(metadata->array_type),
837
+ g_type_tag_to_string(metadata->element_type.tag),
838
+ rb_gi_transfer_to_string(metadata->transfer));
839
+ }
840
+ #if GLIB_CHECK_VERSION(2, 68, 0)
841
+ raw_array = g_memdup2(raw_array, length);
842
+ #else
843
+ if (length > 0) {
844
+ gchar *copied_raw_array = g_malloc(length);
845
+ memcpy(copied_raw_array, raw_array, length);
846
+ raw_array = copied_raw_array;
847
+ } else {
848
+ raw_array = NULL;
849
+ }
850
+ #endif
838
851
  }
839
852
  if (metadata->direction == GI_DIRECTION_INOUT) {
840
853
  metadata->in_arg->v_pointer = ALLOC(gpointer);
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012-2025 Ruby-GNOME Project Team
1
+ # Copyright (C) 2012-2026 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -361,6 +361,18 @@ module GObjectIntrospection
361
361
  klass.class_eval(<<-DEFINE_METHOD, __FILE__, __LINE__ + 1)
362
362
  def initialize(*arguments, &block)
363
363
  invokers = INITIALIZE_INVOKERS
364
+ if invokers.size > 1
365
+ # Prefer the constructor whose signature matches the given
366
+ # arguments without any cast.
367
+ matched_invoker = invokers.values.find do |invoker|
368
+ invoker.match?(self, arguments, block)
369
+ end
370
+ if matched_invoker
371
+ matched_invoker.invoke(self, arguments.dup, block)
372
+ LOADER_CLASS.initialize_instance_post(self)
373
+ return
374
+ end
375
+ end
364
376
  invokers.values.each do |invoker|
365
377
  catch do |tag|
366
378
  invoker.invoke(self, arguments.dup, block, abort_tag: tag)
@@ -729,6 +741,25 @@ module GObjectIntrospection
729
741
  end
730
742
  end
731
743
 
744
+ def match?(receiver, arguments, block)
745
+ ensure_prepared
746
+
747
+ arguments = arguments.dup
748
+ if receiver and @info.class == FunctionInfo
749
+ arguments.unshift(receiver)
750
+ end
751
+
752
+ arguments, _block = build(receiver, arguments, block)
753
+ return false if wrong_number_of_arguments?(arguments)
754
+ arguments.each_with_index.all? do |argument, i|
755
+ if argument.nil?
756
+ @in_arg_nils[i]
757
+ else
758
+ @in_arg_types[i].match?(argument)
759
+ end
760
+ end
761
+ end
762
+
732
763
  def signature
733
764
  ensure_prepared
734
765
  argument_signatures = @in_args.collect(&:signature)
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2019 Ruby-GNOME Project Team
1
+ # Copyright (C) 2019-2026 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -19,16 +19,8 @@ module GObjectIntrospection
19
19
  def try_convert(value)
20
20
  return nil if value.nil?
21
21
 
22
- type = gtype
23
- if type == GLib::Type::NONE
24
- ns = namespace
25
- return value unless Object.const_defined?(ns)
26
- mod = Object.const_get(ns)
27
- return value unless mod.const_defined?(name)
28
- klass = mod.const_get(name)
29
- else
30
- klass = type.to_class
31
- end
22
+ klass = resolve_class
23
+ return value if klass.nil?
32
24
 
33
25
  case value
34
26
  when klass
@@ -42,8 +34,31 @@ module GObjectIntrospection
42
34
  end
43
35
  end
44
36
 
37
+ def match?(value)
38
+ return false if value.nil?
39
+
40
+ klass = resolve_class
41
+ return false if klass.nil?
42
+
43
+ value.is_a?(klass)
44
+ end
45
+
45
46
  def description
46
47
  "#{gtype.to_class}(#{gtype.name})"
47
48
  end
49
+
50
+ private
51
+ def resolve_class
52
+ type = gtype
53
+ if type == GLib::Type::NONE
54
+ ns = namespace
55
+ return nil unless Object.const_defined?(ns)
56
+ mod = Object.const_get(ns)
57
+ return nil unless mod.const_defined?(name)
58
+ mod.const_get(name)
59
+ else
60
+ type.to_class
61
+ end
62
+ end
48
63
  end
49
64
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2019 Ruby-GNOME Project Team
1
+ # Copyright (C) 2019-2026 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -20,6 +20,10 @@ module GObjectIntrospection
20
20
  tag.try_convert(self, value)
21
21
  end
22
22
 
23
+ def match?(value)
24
+ tag.match?(self, value)
25
+ end
26
+
23
27
  def description
24
28
  tag.description(self)
25
29
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2019-2021 Ruby-GNOME Project Team
1
+ # Copyright (C) 2019-2026 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,15 @@ module GObjectIntrospection
25
25
  end
26
26
  end
27
27
 
28
+ def match?(type_info, value)
29
+ method = "match_#{nick}?"
30
+ if respond_to?(method, true)
31
+ __send__(method, type_info, value)
32
+ else
33
+ false
34
+ end
35
+ end
36
+
28
37
  def description(type_info)
29
38
  method = "description_#{nick}"
30
39
  if respond_to?(method, true)
@@ -46,6 +55,10 @@ module GObjectIntrospection
46
55
  end
47
56
  end
48
57
 
58
+ def match_boolean?(type_info, value)
59
+ value == true or value == false
60
+ end
61
+
49
62
  def try_convert_integer(type_info, value)
50
63
  if value.is_a?(Integer)
51
64
  value
@@ -65,6 +78,19 @@ module GObjectIntrospection
65
78
  alias_method :try_convert_int64, :try_convert_integer
66
79
  alias_method :try_convert_uint64, :try_convert_integer
67
80
 
81
+ def match_integer?(type_info, value)
82
+ value.is_a?(Integer)
83
+ end
84
+
85
+ alias_method :match_int8?, :match_integer?
86
+ alias_method :match_uint8?, :match_integer?
87
+ alias_method :match_int16?, :match_integer?
88
+ alias_method :match_uint16?, :match_integer?
89
+ alias_method :match_int32?, :match_integer?
90
+ alias_method :match_uint32?, :match_integer?
91
+ alias_method :match_int64?, :match_integer?
92
+ alias_method :match_uint64?, :match_integer?
93
+
68
94
  def try_convert_float(type_info, value)
69
95
  if value.is_a?(Float)
70
96
  value
@@ -77,10 +103,20 @@ module GObjectIntrospection
77
103
 
78
104
  alias_method :try_convert_double, :try_convert_float
79
105
 
106
+ def match_float?(type_info, value)
107
+ value.is_a?(Float)
108
+ end
109
+
110
+ alias_method :match_double?, :match_float?
111
+
80
112
  def try_convert_gtype(type_info, value)
81
113
  GLib::Type.try_convert(value)
82
114
  end
83
115
 
116
+ def match_gtype?(type_info, value)
117
+ value.is_a?(GLib::Type)
118
+ end
119
+
84
120
  def try_convert_utf8(type_info, value)
85
121
  case value
86
122
  when String
@@ -96,6 +132,10 @@ module GObjectIntrospection
96
132
  end
97
133
  end
98
134
 
135
+ def match_utf8?(type_info, value)
136
+ value.is_a?(String)
137
+ end
138
+
99
139
  def try_convert_filename(type_info, value)
100
140
  case value
101
141
  when String
@@ -111,6 +151,10 @@ module GObjectIntrospection
111
151
  end
112
152
  end
113
153
 
154
+ def match_filename?(type_info, value)
155
+ value.is_a?(String)
156
+ end
157
+
114
158
  def try_convert_array_like(type_info, value)
115
159
  value = Array.try_convert(value)
116
160
  return nil if value.nil?
@@ -124,6 +168,14 @@ module GObjectIntrospection
124
168
  end
125
169
  end
126
170
 
171
+ def match_array_like?(type_info, value)
172
+ return false unless value.is_a?(Array)
173
+ element_type_info = get_element_type_info(type_info)
174
+ value.all? do |v|
175
+ v.nil? or element_type_info.match?(v)
176
+ end
177
+ end
178
+
127
179
  def description_array_like(type_info)
128
180
  element_type_info = type_info.get_param_type(0)
129
181
  "#{nick}(#{element_type_info.description})"
@@ -146,11 +198,21 @@ module GObjectIntrospection
146
198
  try_convert_array_like(type_info, value)
147
199
  end
148
200
 
201
+ def match_array?(type_info, value)
202
+ case get_element_type_info(type_info).tag
203
+ when INT8, UINT8
204
+ return true if value.is_a?(String)
205
+ end
206
+ match_array_like?(type_info, value)
207
+ end
208
+
149
209
  alias_method :description_array, :description_array_like
150
210
 
151
211
  alias_method :try_convert_glist, :try_convert_array_like
212
+ alias_method :match_glist?, :match_array_like?
152
213
  alias_method :description_glist, :description_array_like
153
214
  alias_method :try_convert_gslist, :try_convert_array_like
215
+ alias_method :match_gslist?, :match_array_like?
154
216
  alias_method :description_gslist, :description_array_like
155
217
 
156
218
  def try_convert_ghash(type_info, value)
@@ -162,6 +224,10 @@ module GObjectIntrospection
162
224
  end
163
225
  end
164
226
 
227
+ def match_ghash?(type_info, value)
228
+ value.is_a?(Hash)
229
+ end
230
+
165
231
  def description_ghash(type_info)
166
232
  key_type = type_info.get_param_type(0)
167
233
  value_type = type_info.get_param_type(1)
@@ -172,6 +238,10 @@ module GObjectIntrospection
172
238
  type_info.interface.try_convert(value)
173
239
  end
174
240
 
241
+ def match_interface?(type_info, value)
242
+ type_info.interface.match?(value)
243
+ end
244
+
175
245
  def description_interface(type_info)
176
246
  "#{nick}(#{type_info.interface.description})"
177
247
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2012-2026 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -32,4 +32,28 @@ class TestRegisteredTypeInfo < Test::Unit::TestCase
32
32
  def test_gtype
33
33
  assert_equal(GLib::Type.new("GTypePlugin"), @info.gtype)
34
34
  end
35
+
36
+ def test_match
37
+ @repository.require("GLib")
38
+ info = @repository.find("GLib", "Bytes")
39
+ assert do
40
+ info.match?(GLib::Bytes.new("data"))
41
+ end
42
+ end
43
+
44
+ def test_match_cast
45
+ @repository.require("GLib")
46
+ info = @repository.find("GLib", "Bytes")
47
+ assert do
48
+ not info.match?("data")
49
+ end
50
+ end
51
+
52
+ def test_match_unresolved
53
+ @repository.require("GLib")
54
+ info = @repository.find("GLib", "Cond")
55
+ assert do
56
+ not info.match?(Object.new)
57
+ end
58
+ end
35
59
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2012-2026 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -59,4 +59,50 @@ class TestTypeInfo < Test::Unit::TestCase
59
59
  assert_equal(GObjectIntrospection::ArrayType::C,
60
60
  @info.array_type)
61
61
  end
62
+
63
+ sub_test_case("#match?") do
64
+ def test_uint8_array_string
65
+ info = @repository.find("Gio", "content_type_guess").get_arg(1).type
66
+ assert do
67
+ info.match?("data")
68
+ end
69
+ end
70
+
71
+ def test_uint8_array_bytes
72
+ info = @repository.find("Gio", "content_type_guess").get_arg(1).type
73
+ assert do
74
+ not info.match?(GLib::Bytes.new("data"))
75
+ end
76
+ end
77
+
78
+ def test_utf8_string
79
+ function_info = @repository.find("Gio", "content_type_get_description")
80
+ info = function_info.get_arg(0).type
81
+ assert do
82
+ info.match?("text/plain")
83
+ end
84
+ end
85
+
86
+ def test_utf8_symbol
87
+ function_info = @repository.find("Gio", "content_type_get_description")
88
+ info = function_info.get_arg(0).type
89
+ assert do
90
+ not info.match?(:text)
91
+ end
92
+ end
93
+
94
+ def test_interface_enum
95
+ info = @repository.find("Gio", "bus_get_sync").get_arg(0).type
96
+ assert do
97
+ info.match?(Gio::BusType::SESSION)
98
+ end
99
+ end
100
+
101
+ def test_interface_enum_symbol
102
+ info = @repository.find("Gio", "bus_get_sync").get_arg(0).type
103
+ assert do
104
+ not info.match?(:session)
105
+ end
106
+ end
107
+ end
62
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gobject-introspection
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.9
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Ruby-GNOME Project Team
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 4.3.9
18
+ version: 4.4.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 4.3.9
25
+ version: 4.4.0
26
26
  description: Ruby/GObjectIntrospection provides bindings of GObject Introspection
27
27
  and a loader module that can generate dynamically Ruby bindings of any GObject C
28
28
  libraries
@@ -157,7 +157,7 @@ requirements:
157
157
  - 'system: gobject-introspection-1.0: macports: gobject-introspection'
158
158
  - 'system: gobject-introspection-1.0: msys2: gobject-introspection'
159
159
  - 'system: gobject-introspection-1.0: rhel: pkgconfig(gobject-introspection-1.0)'
160
- rubygems_version: 4.0.16
160
+ rubygems_version: 4.0.20
161
161
  specification_version: 4
162
162
  summary: Ruby/GObjectIntrospection is a Ruby binding of GObject Introspection.
163
163
  test_files: []