gir_ffi 0.7.8 → 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +16 -0
  3. data/README.md +24 -11
  4. data/TODO.md +10 -2
  5. data/gir_ffi.gemspec +2 -2
  6. data/lib/ffi-glib/array.rb +1 -1
  7. data/lib/ffi-glib/hash_table.rb +0 -4
  8. data/lib/ffi-gobject.rb +10 -6
  9. data/lib/ffi-gobject/object.rb +17 -0
  10. data/lib/ffi-gobject/ruby_closure.rb +1 -1
  11. data/lib/ffi-gobject/value.rb +28 -4
  12. data/lib/ffi-gobject_introspection.rb +4 -0
  13. data/lib/ffi-gobject_introspection/g_error.rb +2 -2
  14. data/lib/ffi-gobject_introspection/i_base_info.rb +1 -3
  15. data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
  16. data/lib/ffi-gobject_introspection/i_registered_type_info.rb +2 -0
  17. data/lib/ffi-gobject_introspection/i_repository.rb +4 -4
  18. data/lib/ffi-gobject_introspection/lib.rb +57 -32
  19. data/lib/gir_ffi.rb +1 -1
  20. data/lib/gir_ffi/boxed_base.rb +40 -0
  21. data/lib/gir_ffi/builders/argument_builder.rb +11 -3
  22. data/lib/gir_ffi/builders/base_argument_builder.rb +4 -0
  23. data/lib/gir_ffi/builders/boxed_builder.rb +29 -0
  24. data/lib/gir_ffi/builders/callback_builder.rb +3 -1
  25. data/lib/gir_ffi/builders/callback_return_value_builder.rb +9 -1
  26. data/lib/gir_ffi/builders/field_builder.rb +68 -18
  27. data/lib/gir_ffi/builders/function_builder.rb +12 -2
  28. data/lib/gir_ffi/builders/mapping_method_builder.rb +7 -5
  29. data/lib/gir_ffi/builders/marshalling_method_builder.rb +1 -1
  30. data/lib/gir_ffi/builders/module_builder.rb +1 -1
  31. data/lib/gir_ffi/builders/registered_type_builder.rb +0 -9
  32. data/lib/gir_ffi/builders/return_value_builder.rb +0 -1
  33. data/lib/gir_ffi/builders/signal_closure_builder.rb +3 -1
  34. data/lib/gir_ffi/builders/struct_builder.rb +4 -16
  35. data/lib/gir_ffi/builders/union_builder.rb +2 -13
  36. data/lib/gir_ffi/builders/user_defined_builder.rb +6 -6
  37. data/lib/gir_ffi/builders/vfunc_argument_builder.rb +44 -0
  38. data/lib/gir_ffi/builders/vfunc_builder.rb +3 -1
  39. data/lib/gir_ffi/callback_base.rb +5 -2
  40. data/lib/gir_ffi/class_base.rb +6 -7
  41. data/lib/gir_ffi/enum_base.rb +5 -0
  42. data/lib/gir_ffi/ffi_ext/pointer.rb +1 -0
  43. data/lib/gir_ffi/field_argument_info.rb +4 -0
  44. data/lib/gir_ffi/in_out_pointer.rb +1 -1
  45. data/lib/gir_ffi/in_pointer.rb +2 -2
  46. data/lib/gir_ffi/info_ext/i_arg_info.rb +12 -2
  47. data/lib/gir_ffi/info_ext/i_callable_info.rb +1 -1
  48. data/lib/gir_ffi/info_ext/i_callback_info.rb +7 -2
  49. data/lib/gir_ffi/info_ext/i_field_info.rb +1 -1
  50. data/lib/gir_ffi/info_ext/i_function_info.rb +1 -1
  51. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +7 -2
  52. data/lib/gir_ffi/info_ext/i_type_info.rb +21 -9
  53. data/lib/gir_ffi/info_ext/i_unresolved_info.rb +5 -0
  54. data/lib/gir_ffi/interface_base.rb +5 -0
  55. data/lib/gir_ffi/object_base.rb +5 -0
  56. data/lib/gir_ffi/receiver_argument_info.rb +5 -0
  57. data/lib/gir_ffi/registered_type_base.rb +5 -0
  58. data/lib/gir_ffi/return_value_info.rb +3 -1
  59. data/lib/gir_ffi/sized_array.rb +1 -1
  60. data/lib/gir_ffi/struct_base.rb +2 -24
  61. data/lib/gir_ffi/type_map.rb +5 -1
  62. data/lib/gir_ffi/union_base.rb +2 -2
  63. data/lib/gir_ffi/version.rb +1 -1
  64. data/lib/gir_ffi/zero_terminated.rb +1 -1
  65. data/test/base_test_helper.rb +6 -6
  66. data/test/ffi-glib/hash_table_test.rb +7 -7
  67. data/test/ffi-glib/iconv_test.rb +2 -3
  68. data/test/ffi-glib/main_loop_test.rb +2 -2
  69. data/test/ffi-gobject/gobject_test.rb +1 -1
  70. data/test/ffi-gobject/object_test.rb +5 -14
  71. data/test/ffi-gobject/value_test.rb +30 -6
  72. data/test/ffi-gobject_introspection/i_base_info_test.rb +6 -6
  73. data/test/ffi-gobject_introspection/i_repository_test.rb +2 -4
  74. data/test/gir_ffi/arg_helper_test.rb +1 -1
  75. data/test/gir_ffi/builder_test.rb +18 -12
  76. data/test/gir_ffi/builders/argument_builder_test.rb +2 -5
  77. data/test/gir_ffi/builders/callback_builder_test.rb +1 -1
  78. data/test/gir_ffi/builders/callback_return_value_builder_test.rb +11 -10
  79. data/test/gir_ffi/builders/field_builder_test.rb +0 -2
  80. data/test/gir_ffi/builders/function_builder_test.rb +156 -147
  81. data/test/gir_ffi/builders/interface_builder_test.rb +1 -1
  82. data/test/gir_ffi/builders/module_builder_test.rb +2 -2
  83. data/test/gir_ffi/builders/object_builder_test.rb +2 -2
  84. data/test/gir_ffi/builders/property_builder_test.rb +5 -5
  85. data/test/gir_ffi/builders/return_value_builder_test.rb +30 -30
  86. data/test/gir_ffi/builders/struct_builder_test.rb +14 -14
  87. data/test/gir_ffi/builders/user_defined_builder_test.rb +21 -22
  88. data/test/gir_ffi/builders/vfunc_builder_test.rb +57 -0
  89. data/test/gir_ffi/class_base_test.rb +8 -8
  90. data/test/gir_ffi/ffi_ext/pointer_test.rb +4 -4
  91. data/test/gir_ffi/g_type_test.rb +1 -1
  92. data/test/gir_ffi/in_pointer_test.rb +2 -2
  93. data/test/gir_ffi/info_ext/i_callable_info_test.rb +3 -3
  94. data/test/gir_ffi/info_ext/i_callback_info_test.rb +2 -2
  95. data/test/gir_ffi/info_ext/i_field_info_test.rb +8 -8
  96. data/test/gir_ffi/info_ext/i_function_info_test.rb +13 -13
  97. data/test/gir_ffi/info_ext/i_type_info_test.rb +131 -132
  98. data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +2 -2
  99. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +2 -2
  100. data/test/gir_ffi/info_ext/safe_function_name_test.rb +2 -2
  101. data/test/gir_ffi/interface_base_test.rb +3 -3
  102. data/test/gir_ffi/object_base_test.rb +3 -3
  103. data/test/gir_ffi/sized_array_test.rb +2 -2
  104. data/test/gir_ffi/type_map_test.rb +3 -3
  105. data/test/gir_ffi/unintrospectable_type_info_test.rb +14 -14
  106. data/test/gir_ffi/user_defined_property_info_test.rb +1 -1
  107. data/test/gir_ffi/user_defined_type_info_test.rb +25 -12
  108. data/test/gir_ffi/zero_terminated_test.rb +0 -1
  109. data/test/gir_ffi_test.rb +3 -3
  110. data/test/gir_ffi_test_helper.rb +4 -0
  111. data/test/integration/generated_gimarshallingtests_test.rb +31 -25
  112. data/test/integration/generated_gio_test.rb +1 -1
  113. data/test/integration/generated_gobject_test.rb +1 -1
  114. data/test/integration/generated_regress_test.rb +18 -22
  115. metadata +11 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58dffbf9a2115d4ddfe8ca620557382d27510bb5
4
- data.tar.gz: 6f0e46d81b16c5d29468acc9fce70e4249b44f37
3
+ metadata.gz: b9da5e936faa40d8974a094267b9da5c302fd08c
4
+ data.tar.gz: 441e768cda62450ab418c941703e9cff26e28c0a
5
5
  SHA512:
6
- metadata.gz: 80c91f162cc4b515d85a77de746ba8305c1a8f241bf28e739bbbb46bd5e34ee4029f553ff57764f7824a33dedcb2486931c979a3d612432601e92aa2867e02d3
7
- data.tar.gz: e5e38438a0b57c2ac477a60d464dbf7e0547f74ae7b8326c54f79a486c6bbc205e7e90f484a95a9c628abd927023b771c94b1c0f1272537ac480dcc85a958cdf
6
+ metadata.gz: 09115a044eee555798d204123d566e10c7fb291f679fb2bfa6d18123716a618de6dcbcd5a23e49fc890b8d2c221046df21f34ac52e92d9939a1cd723fbdac3af
7
+ data.tar.gz: 6cb2722920829fe0e81ca48ee8fd8e19d5fade1f34d461608c6d8cb43b5421917074b8173a0010e0a07e796ea57d0369799c3db39f81b6b8571a8beea5d5a8a4
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.9 / 2015-05-05
4
+
5
+ * Unset GValues in finalizer
6
+ * Dereference GObjects in finalizer
7
+ * Increase refcount for ingoing :object arguments of functions with full
8
+ ownership transfer
9
+ * Increase refcount for receiver arguments with full ownership transfer
10
+ * Increase refcount for ingoing :object arguments of vfuncs with no ownership
11
+ transfer
12
+ * Increase refcount for :object return values of vfuncs with full transfer
13
+ * Increase refcount for outgoing :object arguments of vfuncs with full ownership
14
+ transfer
15
+ * Apply more RuboCop rules
16
+ * Support Ruby 2.2
17
+ * Rename several methods. The old names are deprecated and will be removed in 0.8.0.
18
+
3
19
  ## 0.7.8 / 2014-12-09
4
20
 
5
21
  * Support constants with a falsy value
data/README.md CHANGED
@@ -9,10 +9,10 @@ Ruby bindings for GNOME using the GObject Introspection Repository.
9
9
  ## Status
10
10
 
11
11
  [![Gem Version](https://badge.fury.io/rb/gir_ffi.png)](http://badge.fury.io/rb/gir_ffi)
12
- [![Dependency Status](https://gemnasium.com/mvz/ruby-gir-ffi.png)](https://gemnasium.com/mvz/ruby-gir-ffi)
13
- [![Build Status](https://travis-ci.org/mvz/ruby-gir-ffi.png?branch=master)](https://travis-ci.org/mvz/ruby-gir-ffi)
14
- [![Code Climate](https://codeclimate.com/github/mvz/ruby-gir-ffi.png)](https://codeclimate.com/github/mvz/ruby-gir-ffi)
15
- [![Coverage Status](https://coveralls.io/repos/mvz/ruby-gir-ffi/badge.png)](https://coveralls.io/r/mvz/ruby-gir-ffi)
12
+ [![Dependency Status](https://gemnasium.com/mvz/gir_ffi.png)](https://gemnasium.com/mvz/gir_ffi)
13
+ [![Build Status](https://travis-ci.org/mvz/gir_ffi.png?branch=master)](https://travis-ci.org/mvz/gir_ffi)
14
+ [![Code Climate](https://codeclimate.com/github/mvz/gir_ffi.png)](https://codeclimate.com/github/mvz/gir_ffi)
15
+ [![Coverage Status](https://coveralls.io/repos/mvz/gir_ffi/badge.png)](https://coveralls.io/r/mvz/gir_ffi)
16
16
 
17
17
  ## Features
18
18
 
@@ -45,8 +45,8 @@ Ruby bindings for GNOME using the GObject Introspection Repository.
45
45
 
46
46
  ## Requirements
47
47
 
48
- GirFFI should work on MRI 1.9.3, 2.0, and 2.1, JRuby in 1.9 or 2.0 mode, and on
49
- Rubinius.
48
+ GirFFI should work on CRuby 1.9.3, 2.0, 2.1 and 2.2, JRuby in 1.9 or 2.0 mode,
49
+ and on Rubinius.
50
50
 
51
51
  You will also need gobject-introspection installed with some
52
52
  introspection data.
@@ -73,17 +73,21 @@ overrides can be defined. The following gems with overrides
73
73
  already exist:
74
74
 
75
75
  * `gir_ffi-gtk`: overrides for Gtk+ 2 and 3.
76
+ * `gir_ffi-gnome_keyring`: overrides for GnomeKeyring
76
77
  * `gir_ffi-cairo`: overrides for Cairo
77
78
  * `gir_ffi-pango`: overrides for Pango
78
79
  * `gir_ffi-tracker`: overrides for Tracker
79
80
 
80
81
  ## Hacking and contributing
81
82
 
82
- If you want to help out, have a look at TODO.md, and check the notes
83
- in the code (e.g., using `dnote`). Feel free to file bugs or send pull
84
- requests.
83
+ Please feel free to file bugs or send pull requests!
85
84
 
86
- If you want to send pull requests or patches, please:
85
+ If you just want to help out but don't know where to start, have a look at
86
+ TODO.md, and check the notes in the code (e.g., using `dnote`).
87
+
88
+ If you want to send pull requests or patches, please try to follow these
89
+ instructions. If you get stuck, make a pull request anyway and I'll try to help
90
+ out.
87
91
 
88
92
  * Make sure `rake test` runs without reporting any failures. If your code
89
93
  breaks existing stuff, it won't get merged in.
@@ -94,9 +98,18 @@ If you want to send pull requests or patches, please:
94
98
  * Try not to include changes that are irrelevant to your feature in the
95
99
  same commit.
96
100
 
101
+ ## Contributors
102
+
103
+ The following people have contributed to GirFFI over the years:
104
+
105
+ * John Cupitt
106
+ * Marius Hanne
107
+ * Antonio Terceiro
108
+ * Matijs van Zuijlen
109
+
97
110
  ## License
98
111
 
99
- Copyright © 2009–2014 [Matijs van Zuijlen](http://www.matijs.net)
112
+ Copyright © 2009–2015 [Matijs van Zuijlen](http://www.matijs.net)
100
113
 
101
114
  GirFFI is free software, distributed under the terms of the GNU Lesser
102
115
  General Public License, version 2.1 or later. See the file COPYING.LIB for
data/TODO.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # TODO
2
2
 
3
- MAKE CONSTRUCTOR_WRAP CHECK TYPES?
3
+ ## Miscellaneous
4
+
5
+ * MAKE CONSTRUCTOR_WRAP CHECK TYPES? This would allow GObject::Object.new to
6
+ work and create the correct subtype.
7
+ * Add tests for the other test files in gobject-introspection. Currently, only
8
+ regress.c and gimarshallingtests.c are used, but there are 6 other files
9
+ available.
10
+ * Move GObjectIntrospection to GIRepository, and allow generating its own
11
+ members.
4
12
 
5
13
  ## Memory managment
6
14
 
@@ -8,7 +16,7 @@ GirFFI does not attempt to free any memory at the moment, or lower the
8
16
  reference count of any objects it gets from GObject. This task therefore involves two parts:
9
17
 
10
18
  - Free non-GObject pointers as needed (at garbage-collection time)
11
- - Lower reference count of GObjects (at garbage-collection time)
19
+ - Lower reference count of GObjects (at garbage-collection time) (done!)
12
20
 
13
21
  **Use memory_profiler to check memory use (https://github.com/SamSaffron/memory_profiler)**
14
22
 
@@ -33,8 +33,8 @@ Gem::Specification.new do |s|
33
33
  s.add_runtime_dependency('ffi', ["~> 1.8"])
34
34
  s.add_runtime_dependency('indentation', ["~> 0.1.1"])
35
35
 
36
- s.add_development_dependency('minitest', ["~> 5.2"])
37
- s.add_development_dependency('rr', ["~> 1.1.2"])
36
+ s.add_development_dependency('minitest', ["~> 5.5.1"])
37
+ s.add_development_dependency('minitest-rspec_mocks', ["~> 0.2.0"])
38
38
  s.add_development_dependency('rake', ["~> 10.1"])
39
39
 
40
40
  s.require_paths = ["lib"]
@@ -67,7 +67,7 @@ module GLib
67
67
  private
68
68
 
69
69
  def self.calculated_element_size type
70
- ffi_type = GirFFI::TypeMap.type_specification_to_ffitype(type)
70
+ ffi_type = GirFFI::TypeMap.type_specification_to_ffi_type(type)
71
71
  FFI.type_size(ffi_type)
72
72
  end
73
73
 
@@ -57,8 +57,6 @@ module GLib
57
57
  FFI::Function.new(:uint,
58
58
  [:pointer],
59
59
  find_support_function('g_str_hash'))
60
- else
61
- nil
62
60
  end
63
61
  end
64
62
 
@@ -68,8 +66,6 @@ module GLib
68
66
  FFI::Function.new(:int,
69
67
  [:pointer, :pointer],
70
68
  find_support_function('g_str_equal'))
71
- else
72
- nil
73
69
  end
74
70
  end
75
71
 
@@ -83,7 +83,11 @@ module GObject
83
83
 
84
84
  # NOTE: This Lib module is set up in `gir_ffi-base/gobject/lib.rb`.
85
85
  module Lib
86
- attach_function :g_object_ref_sink, [:pointer], :void
86
+ attach_function :g_object_ref_sink, [:pointer], :pointer
87
+ attach_function :g_object_ref, [:pointer], :pointer
88
+ attach_function :g_object_unref, [:pointer], :pointer
89
+
90
+ attach_function :g_value_unset, [:pointer], :pointer
87
91
 
88
92
  attach_function :g_array_get_type, [], :size_t
89
93
  attach_function :g_byte_array_get_type, [], :size_t
@@ -91,14 +95,14 @@ module GObject
91
95
  attach_function :g_strv_get_type, [], :size_t
92
96
 
93
97
  attach_function :g_signal_connect_data,
94
- [:pointer, :string, Callback, :pointer, ClosureNotify, ConnectFlags],
95
- :ulong
98
+ [:pointer, :string, Callback, :pointer, ClosureNotify, ConnectFlags],
99
+ :ulong
96
100
  attach_function :g_closure_set_marshal,
97
- [:pointer, ClosureMarshal], :void
101
+ [:pointer, ClosureMarshal], :void
98
102
 
99
103
  attach_function :g_param_spec_int,
100
- [:string, :string, :string, :int32, :int32, :int32, ParamFlags],
101
- :pointer
104
+ [:string, :string, :string, :int32, :int32, :int32, ParamFlags],
105
+ :pointer
102
106
  end
103
107
 
104
108
  TYPE_ARRAY = Lib.g_array_get_type
@@ -5,6 +5,23 @@ module GObject
5
5
  class Object
6
6
  setup_method 'new'
7
7
 
8
+ def self.constructor_wrap ptr
9
+ super.tap do |obj|
10
+ ObjectSpace.define_finalizer obj, make_finalizer(ptr, obj.class.name) if obj
11
+ end
12
+ end
13
+
14
+ def self.make_finalizer ptr, name
15
+ proc {
16
+ rc = GObject::Object::Struct.new(ptr)[:ref_count]
17
+ if rc == 0 || rc > 100
18
+ warn "not unreffing #{name}:#{ptr} (#{rc})"
19
+ else
20
+ GObject::Lib.g_object_unref ptr
21
+ end
22
+ }
23
+ end
24
+
8
25
  # TODO: Generate accessor methods from GIR at class definition time
9
26
  def method_missing method, *args
10
27
  getter_name = "get_#{method}"
@@ -10,7 +10,7 @@ module GObject
10
10
  # the object_id of the associated block.
11
11
  class Struct < FFI::Struct
12
12
  layout :parent, Closure::Struct, 0,
13
- :block_id, :int64
13
+ :block_id, :int64
14
14
  end
15
15
 
16
16
  def block
@@ -3,6 +3,23 @@ GObject.load_class :Value
3
3
  module GObject
4
4
  # Overrides for GValue, GObject's generic value container structure.
5
5
  class Value
6
+ setup_instance_method 'init'
7
+
8
+ def init_with_finalizer type
9
+ init_without_finalizer(type).tap do
10
+ ObjectSpace.define_finalizer self, self.class.make_finalizer(to_ptr)
11
+ end
12
+ end
13
+
14
+ alias_method :init_without_finalizer, :init
15
+ alias_method :init, :init_with_finalizer
16
+
17
+ def self.make_finalizer ptr
18
+ proc {
19
+ GObject::Lib.g_value_unset ptr
20
+ }
21
+ end
22
+
6
23
  # TODO: Give more generic name
7
24
  def set_ruby_value val
8
25
  init_for_ruby_value val if current_gtype == 0
@@ -96,17 +113,24 @@ module GObject
96
113
  end
97
114
  end
98
115
 
116
+ # @deprecated Use GObject::Value.for_gtype instead. Will be removed in 0.8.0.
99
117
  def self.for_g_type g_type
100
- return nil if g_type == TYPE_NONE
101
- new.tap { |it| it.init g_type }
118
+ for_gtype g_type
119
+ end
120
+
121
+ def self.for_gtype gtype
122
+ return nil if gtype == TYPE_NONE
123
+ new.tap do |it|
124
+ it.init gtype
125
+ end
102
126
  end
103
127
 
104
128
  # TODO: Combine with wrap_ruby_value
105
129
  def self.wrap_instance instance
106
- new.tap {|it|
130
+ new.tap do |it|
107
131
  it.init GObject.type_from_instance instance
108
132
  it.set_instance instance
109
- }
133
+ end
110
134
  end
111
135
 
112
136
  private
@@ -1 +1,5 @@
1
+ require 'gir_ffi-base'
2
+
3
+ GObject.type_init
4
+
1
5
  require 'ffi-gobject_introspection/i_repository'
@@ -4,8 +4,8 @@ module GObjectIntrospection
4
4
  # GLib's GError struct.
5
5
  class Struct < FFI::Struct
6
6
  layout :domain, :uint32,
7
- :code, :int,
8
- :message, :string
7
+ :code, :int,
8
+ :message, :string
9
9
  end
10
10
 
11
11
  def initialize ptr
@@ -5,9 +5,7 @@ module GObjectIntrospection
5
5
  def initialize ptr, lib = Lib
6
6
  raise ArgumentError, 'ptr must not be null' if ptr.null?
7
7
 
8
- unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
9
- ObjectSpace.define_finalizer self, self.class.make_finalizer(lib, ptr)
10
- end
8
+ ObjectSpace.define_finalizer self, self.class.make_finalizer(lib, ptr)
11
9
 
12
10
  @gobj = ptr
13
11
  @lib = lib
@@ -31,5 +31,13 @@ module GObjectIntrospection
31
31
  def skip_return?
32
32
  Lib.g_callable_info_skip_return @gobj
33
33
  end
34
+
35
+ def instance_ownership_transfer
36
+ if VERSION >= '1.42'
37
+ Lib.g_callable_info_get_instance_ownership_transfer @gobj
38
+ else
39
+ :nothing
40
+ end
41
+ end
34
42
  end
35
43
  end
@@ -13,5 +13,7 @@ module GObjectIntrospection
13
13
  def g_type
14
14
  Lib.g_registered_type_info_get_g_type @gobj
15
15
  end
16
+
17
+ alias_method :gtype, :g_type
16
18
  end
17
19
  end
@@ -1,6 +1,4 @@
1
1
  require 'singleton'
2
- require 'ffi'
3
- require 'gir_ffi-base'
4
2
 
5
3
  require 'ffi-gobject_introspection/lib'
6
4
  require 'ffi-gobject_introspection/g_error'
@@ -23,8 +21,6 @@ require 'ffi-gobject_introspection/i_enum_info'
23
21
  require 'ffi-gobject_introspection/i_flags_info'
24
22
  require 'ffi-gobject_introspection/i_unresolved_info'
25
23
 
26
- GObject.type_init
27
-
28
24
  module GObjectIntrospection
29
25
  # The Gobject Introspection Repository. This class is the point of
30
26
  # access to the introspection typelibs.
@@ -118,6 +114,10 @@ module GObjectIntrospection
118
114
  Lib.g_irepository_get_shared_library @gobj, namespace
119
115
  end
120
116
 
117
+ def version namespace
118
+ Lib.g_irepository_get_version @gobj, namespace
119
+ end
120
+
121
121
  def self.wrap_ibaseinfo_pointer ptr
122
122
  return nil if ptr.null?
123
123
  type = Lib.g_base_info_get_type ptr
@@ -6,25 +6,41 @@ module GObjectIntrospection
6
6
  extend FFI::Library
7
7
  ffi_lib 'girepository-1.0'
8
8
 
9
+ # Helper class to support guessing the gobject-introspection version.
10
+ # Provide several guesses to #provide_guess, and the result in #best_guess
11
+ # will be the best (i.e., lowest) guess.
12
+ class VersionGuesser
13
+ def initialize base
14
+ @guess = base
15
+ end
16
+
17
+ def provide_guess guessed
18
+ @guess = guessed if guessed < @guess
19
+ end
20
+
21
+ def best_guess
22
+ @guess
23
+ end
24
+ end
25
+
26
+ version_guesser = VersionGuesser.new('1.42')
27
+
9
28
  # IRepository
10
29
  enum :IRepositoryLoadFlags, [:LAZY, (1 << 0)]
11
30
 
12
31
  attach_function :g_irepository_get_default, [], :pointer
13
32
  attach_function :g_irepository_prepend_search_path, [:string], :void
14
33
  attach_function :g_irepository_require,
15
- [:pointer, :string, :string, :IRepositoryLoadFlags, :pointer],
16
- :pointer
34
+ [:pointer, :string, :string, :IRepositoryLoadFlags, :pointer],
35
+ :pointer
36
+ attach_function :g_irepository_get_version, [:pointer, :string], :string
37
+
17
38
  attach_function :g_irepository_get_n_infos, [:pointer, :string], :int
18
- attach_function :g_irepository_get_info,
19
- [:pointer, :string, :int], :pointer
20
- attach_function :g_irepository_find_by_name,
21
- [:pointer, :string, :string], :pointer
22
- attach_function :g_irepository_find_by_gtype,
23
- [:pointer, :size_t], :pointer
24
- attach_function :g_irepository_get_dependencies,
25
- [:pointer, :string], :pointer
26
- attach_function :g_irepository_get_shared_library,
27
- [:pointer, :string], :string
39
+ attach_function :g_irepository_get_info, [:pointer, :string, :int], :pointer
40
+ attach_function :g_irepository_find_by_name, [:pointer, :string, :string], :pointer
41
+ attach_function :g_irepository_find_by_gtype, [:pointer, :size_t], :pointer
42
+ attach_function :g_irepository_get_dependencies, [:pointer, :string], :pointer
43
+ attach_function :g_irepository_get_shared_library, [:pointer, :string], :string
28
44
 
29
45
  # IBaseInfo
30
46
  enum :IInfoType, [
@@ -78,6 +94,13 @@ module GObjectIntrospection
78
94
  attach_function :g_callable_info_get_arg, [:pointer, :int], :pointer
79
95
  attach_function :g_callable_info_skip_return, [:pointer], :bool
80
96
 
97
+ begin
98
+ attach_function :g_callable_info_get_instance_ownership_transfer,
99
+ [:pointer], :ITransfer
100
+ rescue FFI::NotFoundError
101
+ version_guesser.provide_guess '1.40'
102
+ end
103
+
81
104
  # IArgInfo
82
105
  enum :IDirection, [
83
106
  :in,
@@ -236,26 +259,26 @@ module GObjectIntrospection
236
259
  signed_size_t = "int#{FFI.type_size(:size_t) * 8}".to_sym
237
260
 
238
261
  layout :v_boolean, :int,
239
- :v_int8, :int8,
240
- :v_uint8, :uint8,
241
- :v_int16, :int16,
242
- :v_uint16, :uint16,
243
- :v_int32, :int32,
244
- :v_uint32, :uint32,
245
- :v_int64, :int64,
246
- :v_uint64, :uint64,
247
- :v_float, :float,
248
- :v_double, :double,
249
- :v_short, :short,
250
- :v_ushort, :ushort,
251
- :v_int, :int,
252
- :v_uint, :uint,
253
- :v_long, :long,
254
- :v_ulong, :ulong,
255
- :v_ssize, signed_size_t,
256
- :v_size, :size_t,
257
- :v_string, :string,
258
- :v_pointer, :pointer
262
+ :v_int8, :int8,
263
+ :v_uint8, :uint8,
264
+ :v_int16, :int16,
265
+ :v_uint16, :uint16,
266
+ :v_int32, :int32,
267
+ :v_uint32, :uint32,
268
+ :v_int64, :int64,
269
+ :v_uint64, :uint64,
270
+ :v_float, :float,
271
+ :v_double, :double,
272
+ :v_short, :short,
273
+ :v_ushort, :ushort,
274
+ :v_int, :int,
275
+ :v_uint, :uint,
276
+ :v_long, :long,
277
+ :v_ulong, :ulong,
278
+ :v_ssize, signed_size_t,
279
+ :v_size, :size_t,
280
+ :v_string, :string,
281
+ :v_pointer, :pointer
259
282
  end
260
283
 
261
284
  # IConstInfo
@@ -266,5 +289,7 @@ module GObjectIntrospection
266
289
  # IPropertyInfo
267
290
  #
268
291
  attach_function :g_property_info_get_type, [:pointer], :pointer
292
+
293
+ ::GObjectIntrospection::VERSION = version_guesser.best_guess
269
294
  end
270
295
  end