gobject-introspection 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -94,6 +94,26 @@ module GObjectIntrospection
94
94
  end
95
95
  end
96
96
 
97
+ def define_singleton_method(klass, name, info)
98
+ unlock_gvl = should_unlock_gvl?(info, klass)
99
+ validate = lambda do |arguments|
100
+ validate_arguments(info, "#{klass}.#{name}", arguments)
101
+ end
102
+ singleton_class = (class << klass; self; end)
103
+ singleton_class.__send__(:define_method, name) do |*arguments, &block|
104
+ validate.call(arguments, &block)
105
+ if block.nil? and info.require_callback?
106
+ Enumerator.new(self, name, *arguments)
107
+ else
108
+ info.invoke({
109
+ :arguments => arguments,
110
+ :unlock_gvl => unlock_gvl,
111
+ },
112
+ &block)
113
+ end
114
+ end
115
+ end
116
+
97
117
  def define_struct(info, options={})
98
118
  if info.gtype == GLib::Type::NONE
99
119
  klass = self.class.define_struct(info.size, info.name, @base_module,
@@ -127,6 +147,32 @@ module GObjectIntrospection
127
147
  enum_module.const_set(value_info.name.upcase, value_info.value)
128
148
  end
129
149
 
150
+ def define_enum(info)
151
+ self.class.define_class(info.gtype,
152
+ enum_class_name(info),
153
+ @base_module)
154
+ end
155
+
156
+ def enum_class_name(info)
157
+ info.name
158
+ end
159
+
160
+ def define_error(info)
161
+ self.class.define_error(info.error_domain,
162
+ error_class_name(info),
163
+ @base_module,
164
+ :parent => error_parent_class(info),
165
+ :gtype => info.gtype)
166
+ end
167
+
168
+ def error_class_name(info)
169
+ info.name
170
+ end
171
+
172
+ def error_parent_class(info)
173
+ nil
174
+ end
175
+
130
176
  def load_enum_info(info)
131
177
  if info.gtype == GLib::Type::NONE
132
178
  enum_module = Module.new
@@ -135,7 +181,11 @@ module GObjectIntrospection
135
181
  end
136
182
  @base_module.const_set(info.name, enum_module)
137
183
  else
138
- self.class.define_class(info.gtype, info.name, @base_module)
184
+ if info.error_domain
185
+ define_error(info)
186
+ else
187
+ define_enum(info)
188
+ end
139
189
  end
140
190
  end
141
191
 
@@ -252,14 +302,27 @@ module GObjectIntrospection
252
302
  def find_suitable_callable_info(infos, arguments)
253
303
  min_n_args = nil
254
304
  max_n_args = nil
305
+ candidate_infos = []
255
306
  infos.each do |info|
256
307
  if arguments.size == info.n_in_args
257
- return info
308
+ candidate_infos << info
258
309
  end
259
310
  n_in_args = info.n_in_args
260
311
  min_n_args = [min_n_args || n_in_args, n_in_args].min
261
312
  max_n_args = [max_n_args || n_in_args, n_in_args].max
262
313
  end
314
+
315
+ if candidate_infos.size == 1
316
+ return candidate_infos.first
317
+ elsif candidate_infos.size > 1
318
+ candidate_info = candidate_infos.find do |info|
319
+ info.in_args.each.with_index.all? do |arg_info, i|
320
+ match_argument?(arg_info, arguments[i])
321
+ end
322
+ end
323
+ return candidate_info || candidate_infos.first
324
+ end
325
+
263
326
  detail = "#{arguments.size} for #{min_n_args}"
264
327
  if min_n_args < max_n_args
265
328
  detail << "..#{max_n_args}"
@@ -267,6 +330,16 @@ module GObjectIntrospection
267
330
  raise ArgumentError, "wrong number of arguments (#{detail})"
268
331
  end
269
332
 
333
+ def match_argument?(arg_info, argument)
334
+ case arg_info.type.tag
335
+ when TypeTag::UTF8
336
+ argument.is_a?(String)
337
+ else
338
+ # TODO
339
+ false
340
+ end
341
+ end
342
+
270
343
  def rubyish_method_name(function_info)
271
344
  name = function_info.name
272
345
  return_type = function_info.return_type
@@ -332,23 +405,7 @@ module GObjectIntrospection
332
405
  name = rubyish_method_name(info)
333
406
  next if name == "new"
334
407
  next if name == "alloc"
335
- unlock_gvl = should_unlock_gvl?(info, klass)
336
- validate = lambda do |arguments|
337
- validate_arguments(info, "#{klass}.#{name}", arguments)
338
- end
339
- singleton_class = (class << klass; self; end)
340
- singleton_class.__send__(:define_method, name) do |*arguments, &block|
341
- validate.call(arguments, &block)
342
- if block.nil? and info.require_callback?
343
- Enumerator.new(self, name, *arguments)
344
- else
345
- info.invoke({
346
- :arguments => arguments,
347
- :unlock_gvl => unlock_gvl,
348
- },
349
- &block)
350
- end
351
- end
408
+ define_singleton_method(klass, name, info)
352
409
  end
353
410
  end
354
411
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2012-2014 Ruby-GNOME2 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
@@ -53,4 +53,9 @@ class TestEnumInfo < Test::Unit::TestCase
53
53
  assert_equal(GObjectIntrospection::TypeTag::UINT32,
54
54
  @info.storage_type)
55
55
  end
56
+
57
+ def test_error_domain
58
+ assert_equal("g-resource-error-quark",
59
+ @info.error_domain)
60
+ end
56
61
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2012-2014 Ruby-GNOME2 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
@@ -67,9 +67,9 @@ class TestInterfaceInfo < Test::Unit::TestCase
67
67
  end
68
68
 
69
69
  def test_get_signal_name
70
- require_version(1, 34, 0)
70
+ require_version(1, 36, 0)
71
71
  info = @repository.find("Gio", "Volume")
72
- assert_kind_of(GObjectIntrospection::FunctionInfo,
72
+ assert_kind_of(GObjectIntrospection::SignalInfo,
73
73
  info.get_signal("changed"))
74
74
  end
75
75
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2012-2014 Ruby-GNOME2 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
@@ -15,6 +15,8 @@
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
  class TestRepository < Test::Unit::TestCase
18
+ include GObjectIntrospectionTestUtils
19
+
18
20
  def setup
19
21
  @repository = GObjectIntrospection::Repository.default
20
22
  @repository.require("GObject")
@@ -31,7 +33,8 @@ class TestRepository < Test::Unit::TestCase
31
33
  end
32
34
 
33
35
  def test_get_dependencies
34
- assert_equal(["GLib-2.0", "GObject-2.0"].sort,
36
+ require_version(1, 36, 0)
37
+ assert_equal(["GObject-2.0"].sort,
35
38
  @repository.get_dependencies("Gio").sort)
36
39
  end
37
40
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2012-2014 Ruby-GNOME2 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
@@ -15,15 +15,18 @@
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
  class TestSignalInfo < Test::Unit::TestCase
18
+ include GObjectIntrospectionTestUtils
19
+
18
20
  def setup
19
21
  @repository = GObjectIntrospection::Repository.default
20
22
  @repository.require("Gio")
21
23
  @object_info = @repository.find("Gio", "Application")
22
- @info = @object_info.get_signal(0)
24
+ @info = @object_info.signals.find {|info| info.name == "startup"}
23
25
  end
24
26
 
25
27
  def test_flags
26
- assert_equal(GLib::SignalFlags::RUN_CLEANUP,
28
+ require_version(1, 39, 0)
29
+ assert_equal(GLib::SignalFlags::RUN_LAST,
27
30
  @info.flags)
28
31
  end
29
32
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2012-2014 Ruby-GNOME2 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
@@ -40,11 +40,11 @@ class TestStructInfo < Test::Unit::TestCase
40
40
  end
41
41
 
42
42
  def test_size
43
- assert_equal(24, @info.size)
43
+ assert_operator(@info.size, :>=, 20)
44
44
  end
45
45
 
46
46
  def test_alignment
47
- assert_equal(8, @info.alignment)
47
+ assert_operator(@info.alignment, :>=, 4)
48
48
  end
49
49
 
50
50
  def test_gtype_struct?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gobject-introspection
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Ruby-GNOME2 Project Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-29 00:00:00.000000000 Z
11
+ date: 2014-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glib2
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.0
19
+ version: 2.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.0
26
+ version: 2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement