gir_ffi 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +7 -0
  3. data/TODO.md +8 -0
  4. data/lib/ffi-glib/array.rb +7 -7
  5. data/lib/ffi-glib/byte_array.rb +3 -4
  6. data/lib/ffi-glib/bytes.rb +3 -3
  7. data/lib/ffi-glib/error.rb +2 -2
  8. data/lib/ffi-glib/hash_table.rb +7 -7
  9. data/lib/ffi-glib/iconv.rb +3 -4
  10. data/lib/ffi-glib/list.rb +3 -3
  11. data/lib/ffi-glib/list_methods.rb +3 -3
  12. data/lib/ffi-glib/ptr_array.rb +6 -6
  13. data/lib/ffi-glib/s_list.rb +3 -3
  14. data/lib/ffi-glib/strv.rb +3 -3
  15. data/lib/ffi-glib/variant.rb +6 -2
  16. data/lib/ffi-glib.rb +3 -0
  17. data/lib/ffi-gobject/base.rb +1 -0
  18. data/lib/ffi-gobject/closure.rb +2 -2
  19. data/lib/ffi-gobject/initially_unowned.rb +4 -3
  20. data/lib/ffi-gobject/object.rb +5 -5
  21. data/lib/ffi-gobject/object_class.rb +2 -2
  22. data/lib/ffi-gobject/ruby_closure.rb +2 -3
  23. data/lib/ffi-gobject/value.rb +5 -5
  24. data/lib/ffi-gobject.rb +17 -22
  25. data/lib/ffi-gobject_introspection/i_arg_info.rb +0 -1
  26. data/lib/ffi-gobject_introspection/i_base_info.rb +3 -4
  27. data/lib/ffi-gobject_introspection/i_callable_info.rb +1 -2
  28. data/lib/ffi-gobject_introspection/i_constant_info.rb +19 -11
  29. data/lib/ffi-gobject_introspection/i_enum_info.rb +4 -3
  30. data/lib/ffi-gobject_introspection/i_function_info.rb +7 -1
  31. data/lib/ffi-gobject_introspection/i_interface_info.rb +12 -0
  32. data/lib/ffi-gobject_introspection/i_object_info.rb +19 -8
  33. data/lib/ffi-gobject_introspection/i_registered_type_info.rb +0 -1
  34. data/lib/ffi-gobject_introspection/i_repository.rb +10 -15
  35. data/lib/ffi-gobject_introspection/i_struct_info.rb +4 -2
  36. data/lib/ffi-gobject_introspection/i_type_info.rb +4 -2
  37. data/lib/ffi-gobject_introspection/i_union_info.rb +7 -3
  38. data/lib/ffi-gobject_introspection/i_value_info.rb +0 -1
  39. data/lib/ffi-gobject_introspection/lib.rb +1 -2
  40. data/lib/ffi-gobject_introspection.rb +0 -1
  41. data/lib/gir_ffi/allocation_helper.rb +2 -1
  42. data/lib/gir_ffi/arg_helper.rb +6 -2
  43. data/lib/gir_ffi/builder_helper.rb +1 -0
  44. data/lib/gir_ffi/builders/argument_builder_collection.rb +67 -0
  45. data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +2 -0
  46. data/lib/gir_ffi/builders/callback_argument_builder.rb +7 -5
  47. data/lib/gir_ffi/builders/callback_builder.rb +3 -1
  48. data/lib/gir_ffi/builders/callback_return_value_builder.rb +2 -0
  49. data/lib/gir_ffi/builders/closure_argument_builder.rb +13 -0
  50. data/lib/gir_ffi/builders/closure_convertor.rb +2 -0
  51. data/lib/gir_ffi/builders/closure_to_pointer_convertor.rb +2 -0
  52. data/lib/gir_ffi/builders/constructor_result_convertor.rb +1 -0
  53. data/lib/gir_ffi/builders/enum_builder.rb +1 -4
  54. data/lib/gir_ffi/builders/field_builder.rb +2 -2
  55. data/lib/gir_ffi/builders/function_builder.rb +2 -1
  56. data/lib/gir_ffi/builders/interface_builder.rb +0 -3
  57. data/lib/gir_ffi/builders/mapping_method_builder.rb +24 -92
  58. data/lib/gir_ffi/builders/marshalling_method_builder.rb +73 -0
  59. data/lib/gir_ffi/builders/null_argument_builder.rb +3 -0
  60. data/lib/gir_ffi/builders/null_builder.rb +1 -0
  61. data/lib/gir_ffi/builders/object_builder.rb +0 -2
  62. data/lib/gir_ffi/builders/property_builder.rb +4 -4
  63. data/lib/gir_ffi/builders/registered_type_builder.rb +35 -1
  64. data/lib/gir_ffi/builders/return_value_builder.rb +4 -6
  65. data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +2 -0
  66. data/lib/gir_ffi/builders/signal_closure_builder.rb +46 -0
  67. data/lib/gir_ffi/builders/struct_builder.rb +0 -2
  68. data/lib/gir_ffi/builders/type_builder.rb +1 -1
  69. data/lib/gir_ffi/builders/unintrospectable_builder.rb +1 -1
  70. data/lib/gir_ffi/builders/union_builder.rb +0 -2
  71. data/lib/gir_ffi/builders/user_defined_builder.rb +6 -18
  72. data/lib/gir_ffi/builders/vfunc_builder.rb +6 -4
  73. data/lib/gir_ffi/builders/with_layout.rb +1 -2
  74. data/lib/gir_ffi/callback_base.rb +4 -4
  75. data/lib/gir_ffi/class_base.rb +28 -18
  76. data/lib/gir_ffi/enum_base.rb +2 -2
  77. data/lib/gir_ffi/ffi_ext/pointer.rb +1 -0
  78. data/lib/gir_ffi/in_out_pointer.rb +4 -4
  79. data/lib/gir_ffi/in_pointer.rb +2 -2
  80. data/lib/gir_ffi/info_ext/full_type_name.rb +16 -0
  81. data/lib/gir_ffi/info_ext/i_arg_info.rb +2 -3
  82. data/lib/gir_ffi/info_ext/i_callback_info.rb +1 -8
  83. data/lib/gir_ffi/info_ext/i_property_info.rb +0 -1
  84. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +0 -1
  85. data/lib/gir_ffi/info_ext/i_signal_info.rb +8 -40
  86. data/lib/gir_ffi/info_ext/i_type_info.rb +12 -2
  87. data/lib/gir_ffi/info_ext/i_vfunc_info.rb +1 -6
  88. data/lib/gir_ffi/info_ext/safe_constant_name.rb +0 -5
  89. data/lib/gir_ffi/info_ext.rb +1 -0
  90. data/lib/gir_ffi/lib_c.rb +1 -0
  91. data/lib/gir_ffi/module_base.rb +2 -2
  92. data/lib/gir_ffi/object_base.rb +0 -16
  93. data/lib/gir_ffi/receiver_argument_info.rb +0 -4
  94. data/lib/gir_ffi/registered_type_base.rb +0 -1
  95. data/lib/gir_ffi/sized_array.rb +5 -5
  96. data/lib/gir_ffi/struct_base.rb +4 -0
  97. data/lib/gir_ffi/type_base.rb +2 -2
  98. data/lib/gir_ffi/type_map.rb +1 -0
  99. data/lib/gir_ffi/unintrospectable_type_info.rb +1 -3
  100. data/lib/gir_ffi/user_data_type_info.rb +2 -0
  101. data/lib/gir_ffi/version.rb +2 -1
  102. data/lib/gir_ffi/zero_terminated.rb +6 -6
  103. data/lib/gir_ffi-base/glib/boolean.rb +2 -2
  104. data/lib/gir_ffi-base/glib/strv.rb +1 -1
  105. data/lib/gir_ffi-base/gobject/lib.rb +1 -0
  106. data/lib/gir_ffi-base/gobject.rb +1 -1
  107. data/lib/gir_ffi.rb +2 -0
  108. data/test/ffi-glib/hash_table_test.rb +1 -1
  109. data/test/ffi-glib/strv_test.rb +27 -0
  110. data/test/ffi-gobject_introspection/i_constant_info_test.rb +1 -5
  111. data/test/ffi-gobject_test.rb +3 -3
  112. data/test/gir_ffi/builders/{with_methods_test.rb → registered_type_builder_test.rb} +1 -1
  113. data/test/gir_ffi/builders/signal_closure_builder_test.rb +136 -0
  114. data/test/gir_ffi/builders/user_defined_builder_test.rb +2 -1
  115. data/test/gir_ffi/info_ext/i_signal_info_test.rb +0 -11
  116. data/test/integration/generated_gimarshallingtests_test.rb +47 -2
  117. data/test/integration/generated_regress_test.rb +19 -11
  118. metadata +82 -25
  119. data/lib/gir_ffi/builders/signal_builder.rb +0 -51
  120. data/lib/gir_ffi/builders/with_methods.rb +0 -45
  121. data/lib/gir_ffi/signal_base.rb +0 -21
  122. data/lib/gir_ffi/vfunc_base.rb +0 -9
  123. data/test/gir_ffi/builders/signal_builder_test.rb +0 -106
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1adc3c9b00a49fef5e4ae2dc6674c79c62dc56b6
4
- data.tar.gz: 47303f482166c93c612ed7debdf2d2ed95aad752
3
+ metadata.gz: 18cf75d3dd4a310371647db4f56ab2bdcf516245
4
+ data.tar.gz: d3a5fe4123bdc4ae02e7eae61364e87fa7f01cca
5
5
  SHA512:
6
- metadata.gz: d6983eb6497add24e59e8d8041b815fccd9615e8e9d42895a8e1afbacb44c180a9e6bf63a9a719c6c5bca0552c9fb426391aefe5f668ba44669a3e425554fc2f
7
- data.tar.gz: b904270d51f8905733777fb1ad5e9f6c8da61dd44153c078c472befcd0eee83988ebc08d95d9bb0dc3f57866cd4b4638e45046239fac63a0aa5ddc7e23ba6f49
6
+ metadata.gz: 5280cf6c320d6c50cf10bf320c8738ed5c14ae22867ceb8c8de74a31d6a1a6c5990cb572d26772574bac971296547ca333fcd91e051d3e8aaae2165851a2ac0d
7
+ data.tar.gz: 4f2d7eb7bb6161c3436388ce09b3948e7e04f428053055eedf4386f264dd7faac6c91d6b198abf52b471319b3a0cd6be6e905a68ee3076a21ac03a99731ea0db
data/Changelog.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.5 / 2014-06-22
4
+
5
+ * Use closures as signal handlers, rather than callbacks
6
+ * Obtain reference to GVariant on creation
7
+ * Make struct arguments work in JRuby
8
+ * Various refactoring & code cleanup
9
+
3
10
  ## 0.7.4 / 2014-05-03
4
11
 
5
12
  * Correctly handle closure data arguments originating from C
data/TODO.md CHANGED
@@ -89,6 +89,14 @@ to be put in place for that.
89
89
 
90
90
  For how to handle objects, see https://bugzilla.gnome.org/show_bug.cgi?id=657202#c1
91
91
 
92
+ ## External dependencies
93
+
94
+ Things that I think GirFFI cannot fix:
95
+
96
+ * gobject-introspection should correctly mark private fields as not readable.
97
+ * gobject-introspection should ignore functions that are only defined but not
98
+ implemented, or implement those cases in GIMarshallingTests.
99
+
92
100
  ## See Also
93
101
 
94
102
  dnote
@@ -1,9 +1,9 @@
1
1
  require 'ffi-glib/container_class_methods'
2
2
  require 'ffi-glib/array_methods'
3
3
 
4
- module GLib
5
- load_class :Array
4
+ GLib.load_class :Array
6
5
 
6
+ module GLib
7
7
  # Overrides for GArray, GLib's automatically growing array. It should not
8
8
  # be necessary to create objects of this class from Ruby directly.
9
9
  class Array
@@ -46,8 +46,8 @@ module GLib
46
46
 
47
47
  alias element_size get_element_size
48
48
 
49
- def ==(other)
50
- self.to_a == other.to_a
49
+ def == other
50
+ to_a == other.to_a
51
51
  end
52
52
 
53
53
  def reset_typespec typespec
@@ -57,7 +57,7 @@ module GLib
57
57
  end
58
58
 
59
59
  def self.from_enumerable elmtype, it
60
- self.new(elmtype).tap {|arr| arr.append_vals it }
60
+ new(elmtype).tap {|arr| arr.append_vals it }
61
61
  end
62
62
 
63
63
  private
@@ -68,11 +68,11 @@ module GLib
68
68
  end
69
69
 
70
70
  def calculated_element_size
71
- self.class.calculated_element_size self.element_type
71
+ self.class.calculated_element_size element_type
72
72
  end
73
73
 
74
74
  def check_element_size_match
75
- unless calculated_element_size == self.get_element_size
75
+ unless calculated_element_size == get_element_size
76
76
  warn "WARNING: Element sizes do not match"
77
77
  end
78
78
  end
@@ -1,6 +1,6 @@
1
- module GLib
2
- load_class :ByteArray
1
+ GLib.load_class :ByteArray
3
2
 
3
+ module GLib
4
4
  # Overrides for GByteArray, GLib's automatically growing array of bytes.
5
5
  class ByteArray
6
6
  def to_string
@@ -10,7 +10,7 @@ module GLib
10
10
  def append data
11
11
  bytes = GirFFI::InPointer.from :utf8, data
12
12
  len = data.bytesize
13
- self.class.wrap(Lib.g_byte_array_append self.to_ptr, bytes, len)
13
+ self.class.wrap(Lib.g_byte_array_append to_ptr, bytes, len)
14
14
  end
15
15
 
16
16
  class << self; undef :new; end
@@ -20,4 +20,3 @@ module GLib
20
20
  end
21
21
  end
22
22
  end
23
-
@@ -1,6 +1,6 @@
1
- module GLib
2
- load_class :Bytes
1
+ GLib.load_class :Bytes
3
2
 
3
+ module GLib
4
4
  # Overrides for GBytes, GLib's immutable array of bytes.
5
5
  class Bytes
6
6
  include Enumerable
@@ -37,7 +37,7 @@ module GLib
37
37
 
38
38
  def self.new arr
39
39
  data = GirFFI::SizedArray.from :guint8, arr.size, arr
40
- self.wrap Lib.g_bytes_new data.to_ptr, data.size
40
+ wrap Lib.g_bytes_new data.to_ptr, data.size
41
41
  end
42
42
 
43
43
  private
@@ -1,6 +1,6 @@
1
- module GLib
2
- load_class :Error
1
+ GLib.load_class :Error
3
2
 
3
+ module GLib
4
4
  # Overrides for GError, used by GLib for handling non-fatal errors.
5
5
  class Error
6
6
  # TODO: Auto-convert strings and symbols to quarks
@@ -1,8 +1,8 @@
1
1
  require 'ffi-glib/container_class_methods'
2
2
 
3
- module GLib
4
- load_class :HashTable
3
+ GLib.load_class :HashTable
5
4
 
5
+ module GLib
6
6
  # Overrides for GHashTable, GLib's hash table implementation.
7
7
  class HashTable
8
8
  include Enumerable
@@ -12,23 +12,23 @@ module GLib
12
12
  attr_reader :value_type
13
13
 
14
14
  def each
15
- prc = proc {|keyptr, valptr, userdata|
15
+ prc = proc {|keyptr, valptr, _userdata|
16
16
  key = GirFFI::ArgHelper.cast_from_pointer key_type, keyptr
17
17
  val = GirFFI::ArgHelper.cast_from_pointer value_type, valptr
18
18
  yield key, val
19
19
  }
20
20
  callback = GLib::HFunc.from prc
21
- ::GLib::Lib.g_hash_table_foreach self.to_ptr, callback, nil
21
+ ::GLib::Lib.g_hash_table_foreach to_ptr, callback, nil
22
22
  end
23
23
 
24
24
  def to_hash
25
- Hash[self.to_a]
25
+ Hash[to_a]
26
26
  end
27
27
 
28
28
  def insert key, value
29
29
  keyptr = GirFFI::InPointer.from key_type, key
30
30
  valptr = GirFFI::InPointer.from value_type, value
31
- ::GLib::Lib.g_hash_table_insert self.to_ptr, keyptr, valptr
31
+ ::GLib::Lib.g_hash_table_insert to_ptr, keyptr, valptr
32
32
  end
33
33
 
34
34
  class << self; remove_method :new; end
@@ -44,7 +44,7 @@ module GLib
44
44
  end
45
45
 
46
46
  def self.from_enumerable typespec, hash
47
- ghash = self.new(*typespec)
47
+ ghash = new(*typespec)
48
48
  hash.each do |key, val|
49
49
  ghash.insert key, val
50
50
  end
@@ -1,9 +1,9 @@
1
- module GLib
2
- load_class :IConv
1
+ GLib.load_class :IConv
3
2
 
3
+ module GLib
4
4
  # Overrides for IConv
5
5
  class IConv
6
- def self.open(to_codeset, from_codeset)
6
+ def self.open to_codeset, from_codeset
7
7
  to_ptr = GirFFI::InPointer.from(:utf8, to_codeset)
8
8
  from_ptr = GirFFI::InPointer.from(:utf8, from_codeset)
9
9
  result_ptr = Lib.g_iconv_open(to_ptr, from_ptr)
@@ -11,4 +11,3 @@ module GLib
11
11
  end
12
12
  end
13
13
  end
14
-
data/lib/ffi-glib/list.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  require 'ffi-glib/list_methods'
2
2
 
3
- module GLib
4
- load_class :List
3
+ GLib.load_class :List
5
4
 
5
+ module GLib
6
6
  # Overrides for GList, GLib's doubly linked list implementation.
7
7
  class List
8
8
  include ListMethods
9
9
 
10
10
  def self.from_enumerable type, arr
11
- arr.inject(self.new type) { |lst, val| lst.append val }
11
+ arr.inject(new type) { |lst, val| lst.append val }
12
12
  end
13
13
 
14
14
  def append data
@@ -44,8 +44,8 @@ module GLib
44
44
  self
45
45
  end
46
46
 
47
- def ==(other)
48
- self.to_a == other.to_a
47
+ def == other
48
+ to_a == other.to_a
49
49
  end
50
50
 
51
51
  private
@@ -65,6 +65,7 @@ module GLib
65
65
  GirFFI::InPointer.from(element_type, data)
66
66
  end
67
67
 
68
+ # Common class methods for List and SList
68
69
  module ListClassMethods
69
70
  def new type
70
71
  _real_new.tap do |it|
@@ -76,4 +77,3 @@ module GLib
76
77
  end
77
78
  end
78
79
  end
79
-
@@ -1,9 +1,9 @@
1
1
  require 'ffi-glib/container_class_methods'
2
2
  require 'ffi-glib/array_methods'
3
3
 
4
- module GLib
5
- load_class :PtrArray
4
+ GLib.load_class :PtrArray
6
5
 
6
+ module GLib
7
7
  # Overrides for GPtrArray, GLib's automatically growing array of
8
8
  # pointers.
9
9
  class PtrArray
@@ -25,8 +25,8 @@ module GLib
25
25
  wrap(type, Lib.g_ptr_array_new)
26
26
  end
27
27
 
28
- def self.from_enumerable(type, it)
29
- self.new(type).tap {|arr| arr.add_array it}
28
+ def self.from_enumerable type, it
29
+ new(type).tap {|arr| arr.add_array it}
30
30
  end
31
31
 
32
32
  def self.add array, data
@@ -65,8 +65,8 @@ module GLib
65
65
  @struct[:len]
66
66
  end
67
67
 
68
- def ==(other)
69
- self.to_a == other.to_a
68
+ def == other
69
+ to_a == other.to_a
70
70
  end
71
71
  end
72
72
  end
@@ -1,14 +1,14 @@
1
1
  require 'ffi-glib/list_methods'
2
2
 
3
- module GLib
4
- load_class :SList
3
+ GLib.load_class :SList
5
4
 
5
+ module GLib
6
6
  # Overrides for GSList, GLib's singly-linked list implementation.
7
7
  class SList
8
8
  include ListMethods
9
9
 
10
10
  def self.from_enumerable type, arr
11
- arr.reverse.inject(self.new type) { |lst, val| lst.prepend val }
11
+ arr.reverse.inject(new type) { |lst, val| lst.prepend val }
12
12
  end
13
13
 
14
14
  def prepend data
data/lib/ffi-glib/strv.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module GLib
2
2
  # Extra methods for GLib::Strv. The bulk is defined in `gir_ffi-base/glib/strv.rb`
3
3
  class Strv
4
- def ==(other)
5
- self.to_a == other.to_a
4
+ def == other
5
+ to_a == other.to_a
6
6
  end
7
7
 
8
8
  def self.from it
@@ -19,7 +19,7 @@ module GLib
19
19
  end
20
20
 
21
21
  def self.from_enumerable enum
22
- self.wrap GirFFI::InPointer.from_array :utf8, enum
22
+ wrap GirFFI::InPointer.from_array :utf8, enum
23
23
  end
24
24
  end
25
25
  end
@@ -1,6 +1,6 @@
1
- module GLib
2
- load_class :Variant
1
+ GLib.load_class :Variant
3
2
 
3
+ module GLib
4
4
  # Overrides for GVariant, GLib's variant data type.
5
5
  class Variant
6
6
  setup_instance_method "get_string"
@@ -9,6 +9,10 @@ module GLib
9
9
  get_string_without_override.first
10
10
  end
11
11
 
12
+ def self.constructor_wrap ptr
13
+ super.tap {|variant| variant.ref }
14
+ end
15
+
12
16
  alias get_string_without_override get_string
13
17
  alias get_string get_string_with_override
14
18
  end
data/lib/ffi-glib.rb CHANGED
@@ -15,12 +15,15 @@ require 'ffi-glib/s_list'
15
15
  require 'ffi-glib/strv'
16
16
  require 'ffi-glib/variant'
17
17
 
18
+ # Module representing GLib's GLib namespace.
18
19
  module GLib
19
20
  load_class :HFunc
20
21
  load_class :HashFunc
21
22
  load_class :EqualFunc
22
23
  load_class :Func
23
24
 
25
+ # Module for attaching functions from the glib library.
26
+ # NOTE: This module is defined by the call to GirFFI.setup above.
24
27
  module Lib
25
28
  attach_function :g_slist_prepend, [:pointer, :pointer], :pointer
26
29
 
@@ -1,3 +1,4 @@
1
+ # Preload type contants
1
2
  module GObject
2
3
  TYPE_INVALID = type_from_name("invalid")
3
4
  TYPE_NONE = type_from_name("void")
@@ -1,6 +1,6 @@
1
- module GObject
2
- load_class :Closure
1
+ GObject.load_class :Closure
3
2
 
3
+ module GObject
4
4
  # Overrides for GClosure, GObject's base class for closure objects.
5
5
  class Closure
6
6
  def set_marshal marshal
@@ -1,12 +1,13 @@
1
- module GObject
2
- load_class :InitiallyUnowned
1
+ GObject.load_class :InitiallyUnowned
3
2
 
3
+ module GObject
4
4
  # Overrides for GInitiallyUnowned, GObject's base class for objects that
5
5
  # start with a floating reference.
6
6
  class InitiallyUnowned
7
+ # Wrapping method used in constructors. For InitiallyUnowned and
8
+ # descendants, this needs to sink the object's floating reference.
7
9
  def self.constructor_wrap ptr
8
10
  super.tap {|obj| ::GObject.object_ref_sink obj}
9
11
  end
10
12
  end
11
13
  end
12
-
@@ -1,13 +1,13 @@
1
- module GObject
2
- load_class :Object
1
+ GObject.load_class :Object
3
2
 
3
+ module GObject
4
4
  # Overrides for GObject, GObject's generic base class.
5
5
  class Object
6
6
 
7
7
  setup_method "new"
8
8
 
9
9
  # TODO: Generate accessor methods from GIR at class definition time
10
- def method_missing(method, *args)
10
+ def method_missing method, *args
11
11
  if respond_to?("get_#{method}")
12
12
  return send("get_#{method}", *args)
13
13
  end
@@ -17,7 +17,7 @@ module GObject
17
17
  super
18
18
  end
19
19
 
20
- def signal_connect(event, &block)
20
+ def signal_connect event, &block
21
21
  GObject.signal_connect(self, event, &block)
22
22
  end
23
23
 
@@ -59,7 +59,7 @@ module GObject
59
59
  end
60
60
 
61
61
  def type_class
62
- GObject::ObjectClass.wrap(self.to_ptr.get_pointer 0)
62
+ GObject::ObjectClass.wrap(to_ptr.get_pointer 0)
63
63
  end
64
64
 
65
65
  alias get_property_without_override get_property
@@ -1,6 +1,6 @@
1
- module GObject
2
- load_class :ObjectClass
1
+ GObject.load_class :ObjectClass
3
2
 
3
+ module GObject
4
4
  # Overrides for GObjectClass, a struct containing GObject's class data
5
5
  class ObjectClass
6
6
  def set_property= callback
@@ -34,11 +34,10 @@ module GObject
34
34
  closure.block = block
35
35
  closure.set_marshal Proc.new {|*args| marshaller(*args)}
36
36
 
37
- return closure
37
+ closure
38
38
  end
39
39
 
40
- def self.marshaller(closure, return_value, param_values,
41
- _invocation_hint, _marshal_data)
40
+ def self.marshaller closure, return_value, param_values, _invocation_hint, _marshal_data
42
41
  rclosure = wrap(closure.to_ptr)
43
42
  param_values ||= []
44
43
 
@@ -1,6 +1,6 @@
1
- module GObject
2
- load_class :Value
1
+ GObject.load_class :Value
3
2
 
3
+ module GObject
4
4
  # Overrides for GValue, GObject's generic value container structure.
5
5
  class Value
6
6
  # TODO: Give more generic name
@@ -88,7 +88,7 @@ module GObject
88
88
 
89
89
  # TODO: Give more generic name
90
90
  def self.wrap_ruby_value val
91
- self.new.set_ruby_value val
91
+ new.set_ruby_value val
92
92
  end
93
93
 
94
94
  def self.from val
@@ -104,12 +104,12 @@ module GObject
104
104
 
105
105
  def self.for_g_type g_type
106
106
  return nil if g_type == TYPE_NONE
107
- self.new.tap {|it| it.init g_type }
107
+ new.tap {|it| it.init g_type }
108
108
  end
109
109
 
110
110
  # TODO: Combine with wrap_ruby_value
111
111
  def self.wrap_instance instance
112
- self.new.tap {|it|
112
+ new.tap {|it|
113
113
  it.init GObject.type_from_instance instance
114
114
  it.set_instance instance
115
115
  }
data/lib/ffi-gobject.rb CHANGED
@@ -16,19 +16,19 @@ require 'gir_ffi/builders/user_defined_builder'
16
16
  # Module representing GLib's GObject namespace.
17
17
  module GObject
18
18
  def self.object_ref obj
19
- Lib::g_object_ref obj.to_ptr
19
+ Lib.g_object_ref obj.to_ptr
20
20
  end
21
21
 
22
22
  def self.object_ref_sink obj
23
- Lib::g_object_ref_sink obj.to_ptr
23
+ Lib.g_object_ref_sink obj.to_ptr
24
24
  end
25
25
 
26
26
  def self.object_unref obj
27
- Lib::g_object_unref obj.to_ptr
27
+ Lib.g_object_unref obj.to_ptr
28
28
  end
29
29
 
30
30
  def self.object_is_floating obj
31
- Lib::g_object_is_floating obj.to_ptr
31
+ Lib.g_object_is_floating obj.to_ptr
32
32
  end
33
33
 
34
34
  def self.type_from_instance_pointer inst_ptr
@@ -52,8 +52,6 @@ module GObject
52
52
  ObjectClass.wrap klsptr
53
53
  end
54
54
 
55
- setup_method :signal_emitv
56
-
57
55
  def self.signal_lookup_from_instance signal, object
58
56
  signal_lookup signal, type_from_instance(object)
59
57
  end
@@ -62,31 +60,29 @@ module GObject
62
60
  signal, detail = detailed_signal.split('::')
63
61
  signal_id = signal_lookup_from_instance signal, object
64
62
  detail_quark = GLib.quark_from_string(detail)
65
- sig_info = object.class.find_signal signal
66
-
67
- arr_ptr = sig_info.arguments_to_gvalue_array_pointer object, args
68
63
 
69
- rval = sig_info.gvalue_for_return_value
64
+ sig_info = object.class.find_signal signal
65
+ argument_gvalues = sig_info.arguments_to_gvalues object, args
66
+ return_gvalue = sig_info.gvalue_for_return_value
70
67
 
71
- Lib.g_signal_emitv arr_ptr, signal_id, detail_quark, rval
68
+ signal_emitv argument_gvalues, signal_id, detail_quark, return_gvalue
72
69
 
73
- return rval
70
+ return_gvalue
74
71
  end
75
72
 
76
73
  def self.signal_connect object, detailed_signal, data=nil, &block
77
- signal, _ = detailed_signal.split('::')
78
- sig_info = object.class.find_signal signal
79
- callback = sig_info.create_callback(&block)
80
- GirFFI::CallbackBase.store_callback callback
74
+ raise ArgumentError, "Block needed" unless block_given?
75
+ signal_name, _ = detailed_signal.split('::')
76
+ sig_info = object.class.find_signal signal_name
81
77
 
82
- data_ptr = GirFFI::InPointer.from_closure_data data
78
+ closure = sig_info.wrap_in_closure {|*args| block.call(*args << data) }
83
79
 
84
- Lib.g_signal_connect_data object, detailed_signal, callback, data_ptr, nil, 0
80
+ # TODO: Provide _after variant
81
+ signal_connect_closure object, detailed_signal, closure, false
85
82
  end
86
83
 
87
84
  # Smells of :reek:LongParameterList: due to the C interface.
88
- def self.param_spec_int(name, nick, blurb, minimum, maximum,
89
- default_value, flags)
85
+ def self.param_spec_int name, nick, blurb, minimum, maximum, default_value, flags
90
86
  ptr = Lib.g_param_spec_int(name, nick, blurb, minimum, maximum,
91
87
  default_value, flags)
92
88
  ParamSpecInt.wrap(ptr)
@@ -98,9 +94,8 @@ module GObject
98
94
  load_class :ClosureMarshal
99
95
  load_class :ParamFlags
100
96
 
97
+ # NOTE: This Lib module is set up in `gir_ffi-base/gobject/lib.rb`.
101
98
  module Lib
102
- # NOTE: This Lib module is set up in `gir_ffi-base/gobject/lib.rb`.
103
-
104
99
  attach_function :g_object_ref, [:pointer], :void
105
100
  attach_function :g_object_ref_sink, [:pointer], :void
106
101
  attach_function :g_object_unref, [:pointer], :void
@@ -48,4 +48,3 @@ module GObjectIntrospection
48
48
  end
49
49
  end
50
50
  end
51
-
@@ -40,7 +40,7 @@ module GObjectIntrospection
40
40
  method = method.to_s
41
41
  single ||= method.to_s[0..-2]
42
42
  count = method.sub(/^(get_)?/, "\\1n_")
43
- self.class_eval <<-CODE
43
+ class_eval <<-CODE
44
44
  def #{method}
45
45
  (0..(#{count} - 1)).map do |i|
46
46
  #{single} i
@@ -70,7 +70,7 @@ module GObjectIntrospection
70
70
  single = method.sub(/^find_/, "")
71
71
  counter ||= "n_#{single}s"
72
72
  fetcher ||= "#{single}"
73
- self.class_eval <<-CODE
73
+ class_eval <<-CODE
74
74
  def #{method}(name)
75
75
  (0..(#{counter} - 1)).each do |i|
76
76
  it = #{fetcher}(i)
@@ -108,8 +108,7 @@ module GObjectIntrospection
108
108
  end
109
109
 
110
110
  def self.wrap ptr
111
- return nil if ptr.null?
112
- return new ptr
111
+ new ptr unless ptr.null?
113
112
  end
114
113
 
115
114
  def == other
@@ -22,7 +22,7 @@ module GObjectIntrospection
22
22
  Lib.g_callable_info_get_n_args @gobj
23
23
  end
24
24
 
25
- def arg(index)
25
+ def arg index
26
26
  IArgInfo.wrap(Lib.g_callable_info_get_arg @gobj, index)
27
27
  end
28
28
  ##
@@ -33,4 +33,3 @@ module GObjectIntrospection
33
33
  end
34
34
  end
35
35
  end
36
-
@@ -14,24 +14,32 @@ module GObjectIntrospection
14
14
  utf8: :v_string
15
15
  }
16
16
 
17
- def value_union
18
- val = Lib::GIArgument.new
19
- Lib.g_constant_info_get_value @gobj, val
20
- return val
21
- end
22
-
23
17
  def value
24
- tag = constant_type.tag
25
- val = value_union[TYPE_TAG_TO_UNION_MEMBER[tag]]
26
- if tag == :utf8
27
- val.force_encoding("utf-8")
18
+ if type_tag == :utf8
19
+ raw_value.force_encoding("utf-8")
28
20
  else
29
- val
21
+ raw_value
30
22
  end
31
23
  end
32
24
 
33
25
  def constant_type
34
26
  ITypeInfo.wrap(Lib.g_constant_info_get_type @gobj)
35
27
  end
28
+
29
+ private
30
+
31
+ def type_tag
32
+ @type_tag ||= constant_type.tag
33
+ end
34
+
35
+ def raw_value
36
+ value_union = Lib::GIArgument.new
37
+ Lib.g_constant_info_get_value @gobj, value_union
38
+ value_union[union_member_key]
39
+ end
40
+
41
+ def union_member_key
42
+ TYPE_TAG_TO_UNION_MEMBER[type_tag]
43
+ end
36
44
  end
37
45
  end