gir_ffi 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/History.txt +14 -0
  2. data/TODO.rdoc +23 -5
  3. data/lib/ffi-glib/array.rb +14 -15
  4. data/lib/ffi-glib/container_class_methods.rb +0 -1
  5. data/lib/ffi-glib/hash_table.rb +3 -4
  6. data/lib/ffi-glib/ptr_array.rb +12 -4
  7. data/lib/ffi-glib/sized_array.rb +27 -7
  8. data/lib/ffi-gobject.rb +14 -15
  9. data/lib/ffi-gobject/closure.rb +1 -1
  10. data/lib/ffi-gobject/object.rb +40 -15
  11. data/lib/ffi-gobject/ruby_closure.rb +0 -1
  12. data/lib/ffi-gobject/value.rb +45 -21
  13. data/lib/ffi-gobject_introspection/i_arg_info.rb +4 -0
  14. data/lib/ffi-gobject_introspection/i_base_info.rb +42 -2
  15. data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
  16. data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -4
  17. data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
  18. data/lib/ffi-gobject_introspection/i_object_info.rb +2 -0
  19. data/lib/ffi-gobject_introspection/i_repository.rb +2 -3
  20. data/lib/ffi-gobject_introspection/i_struct_info.rb +3 -8
  21. data/lib/ffi-gobject_introspection/lib.rb +3 -0
  22. data/lib/gir_ffi-base.rb +3 -1
  23. data/lib/gir_ffi-base/gir_ffi/struct.rb +27 -0
  24. data/lib/gir_ffi-base/glib/boolean.rb +13 -1
  25. data/lib/gir_ffi-base/gobject.rb +7 -0
  26. data/lib/gir_ffi-base/gobject/lib.rb +0 -2
  27. data/lib/gir_ffi.rb +1 -3
  28. data/lib/gir_ffi/arg_helper.rb +4 -85
  29. data/lib/gir_ffi/builder.rb +5 -5
  30. data/lib/gir_ffi/builder_helper.rb +7 -0
  31. data/lib/gir_ffi/builders/argument_builder.rb +132 -0
  32. data/lib/gir_ffi/{base_argument_builder.rb → builders/base_argument_builder.rb} +32 -41
  33. data/lib/gir_ffi/builders/base_type_builder.rb +47 -0
  34. data/lib/gir_ffi/builders/callback_builder.rb +38 -0
  35. data/lib/gir_ffi/builders/constant_builder.rb +18 -0
  36. data/lib/gir_ffi/builders/enum_builder.rb +62 -0
  37. data/lib/gir_ffi/builders/error_argument_builder.rb +18 -0
  38. data/lib/gir_ffi/builders/field_builder.rb +94 -0
  39. data/lib/gir_ffi/builders/function_builder.rb +123 -0
  40. data/lib/gir_ffi/builders/interface_builder.rb +29 -0
  41. data/lib/gir_ffi/builders/mapping_method_builder.rb +88 -0
  42. data/lib/gir_ffi/builders/module_builder.rb +124 -0
  43. data/lib/gir_ffi/{null_argument_builder.rb → builders/null_argument_builder.rb} +0 -0
  44. data/lib/gir_ffi/builders/null_builder.rb +11 -0
  45. data/lib/gir_ffi/builders/object_builder.rb +123 -0
  46. data/lib/gir_ffi/{builder/property.rb → builders/property_builder.rb} +0 -0
  47. data/lib/gir_ffi/builders/registered_type_builder.rb +50 -0
  48. data/lib/gir_ffi/builders/return_value_builder.rb +68 -0
  49. data/lib/gir_ffi/builders/signal_builder.rb +91 -0
  50. data/lib/gir_ffi/builders/struct_builder.rb +35 -0
  51. data/lib/gir_ffi/builders/type_builder.rb +40 -0
  52. data/lib/gir_ffi/builders/unintrospectable_builder.rb +35 -0
  53. data/lib/gir_ffi/builders/union_builder.rb +34 -0
  54. data/lib/gir_ffi/builders/user_defined_builder.rb +103 -0
  55. data/lib/gir_ffi/builders/with_layout.rb +55 -0
  56. data/lib/gir_ffi/builders/with_methods.rb +44 -0
  57. data/lib/gir_ffi/callback_base.rb +31 -0
  58. data/lib/gir_ffi/class_base.rb +16 -10
  59. data/lib/gir_ffi/enum_base.rb +8 -4
  60. data/lib/gir_ffi/ffi_ext/pointer.rb +19 -2
  61. data/lib/gir_ffi/in_out_pointer.rb +38 -39
  62. data/lib/gir_ffi/in_pointer.rb +33 -18
  63. data/lib/gir_ffi/info_ext.rb +0 -4
  64. data/lib/gir_ffi/info_ext/i_arg_info.rb +0 -18
  65. data/lib/gir_ffi/info_ext/i_callable_info.rb +2 -1
  66. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +6 -8
  67. data/lib/gir_ffi/info_ext/i_signal_info.rb +6 -21
  68. data/lib/gir_ffi/info_ext/i_type_info.rb +54 -29
  69. data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -1
  70. data/lib/gir_ffi/interface_base.rb +1 -1
  71. data/lib/gir_ffi/module_base.rb +5 -1
  72. data/lib/gir_ffi/object_base.rb +5 -1
  73. data/lib/gir_ffi/setter_argument_info.rb +4 -0
  74. data/lib/gir_ffi/signal_base.rb +21 -0
  75. data/lib/gir_ffi/struct_base.rb +24 -0
  76. data/lib/gir_ffi/type_base.rb +11 -0
  77. data/lib/gir_ffi/type_map.rb +4 -2
  78. data/lib/gir_ffi/union_base.rb +24 -0
  79. data/lib/gir_ffi/version.rb +1 -1
  80. data/tasks/test.rake +73 -7
  81. data/test/base_test_helper.rb +3 -19
  82. data/test/ffi-glib/array_test.rb +6 -0
  83. data/test/ffi-glib/ptr_array_test.rb +13 -0
  84. data/test/ffi-glib/ruby_closure_test.rb +7 -7
  85. data/test/ffi-glib/sized_array_test.rb +2 -2
  86. data/test/ffi-gobject/gobject_test.rb +3 -12
  87. data/test/ffi-gobject/object_test.rb +33 -2
  88. data/test/ffi-gobject/value_test.rb +114 -1
  89. data/test/ffi-gobject_introspection/i_enum_info_test.rb +2 -2
  90. data/test/ffi-gobject_introspection/i_object_info_test.rb +3 -3
  91. data/test/ffi-gobject_introspection/i_repository_test.rb +26 -21
  92. data/test/ffi-gobject_test.rb +14 -14
  93. data/test/gir_ffi-base/glib/boolean_test.rb +6 -0
  94. data/test/gir_ffi/arg_helper_test.rb +2 -122
  95. data/test/gir_ffi/builder_test.rb +67 -204
  96. data/test/gir_ffi/{argument_builder_test.rb → builders/argument_builder_test.rb} +230 -108
  97. data/test/gir_ffi/builders/base_argument_builder_test.rb +5 -0
  98. data/test/gir_ffi/builders/callback_builder_test.rb +50 -0
  99. data/test/gir_ffi/builders/constant_builder_test.rb +4 -0
  100. data/test/gir_ffi/{builder/type/enum_test.rb → builders/enum_builder_test.rb} +2 -3
  101. data/test/gir_ffi/builders/field_builder_test.rb +94 -0
  102. data/test/gir_ffi/{function_builder_test.rb → builders/function_builder_test.rb} +43 -24
  103. data/test/gir_ffi/{builder/type/interface_test.rb → builders/interface_builder_test.rb} +2 -2
  104. data/test/gir_ffi/{builder/module_test.rb → builders/module_builder_test.rb} +12 -13
  105. data/test/gir_ffi/{builder/type/object_test.rb → builders/object_builder_test.rb} +9 -9
  106. data/test/gir_ffi/{return_value_builder_test.rb → builders/return_value_builder_test.rb} +94 -58
  107. data/test/gir_ffi/builders/signal_builder_test.rb +62 -0
  108. data/test/gir_ffi/{builder/type/struct_test.rb → builders/struct_builder_test.rb} +36 -19
  109. data/test/gir_ffi/{builder/type/unintrospectable_test.rb → builders/unintrospectable_builder_test.rb} +3 -3
  110. data/test/gir_ffi/builders/union_builder_test.rb +29 -0
  111. data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb} +2 -2
  112. data/test/gir_ffi/callback_base_test.rb +11 -0
  113. data/test/gir_ffi/class_base_test.rb +22 -22
  114. data/test/gir_ffi/ffi_ext/pointer_test.rb +18 -0
  115. data/test/gir_ffi/in_out_pointer_test.rb +0 -7
  116. data/test/gir_ffi/in_pointer_test.rb +27 -3
  117. data/test/gir_ffi/info_ext/i_signal_info_test.rb +16 -44
  118. data/test/gir_ffi/info_ext/i_type_info_test.rb +315 -74
  119. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +6 -0
  120. data/test/gir_ffi/interface_base_test.rb +3 -5
  121. data/test/gir_ffi/object_base_test.rb +10 -6
  122. data/test/gir_ffi/type_map_test.rb +2 -2
  123. data/test/gir_ffi/unintrospectable_type_info_test.rb +2 -2
  124. data/test/gir_ffi_test_helper.rb +12 -4
  125. data/test/integration/generated_gimarshallingtests_test.rb +436 -76
  126. data/test/integration/generated_gio_test.rb +5 -11
  127. data/test/integration/generated_gobject_test.rb +8 -0
  128. data/test/integration/generated_regress_test.rb +755 -309
  129. data/test/integration/generated_secret_test.rb +2 -1
  130. metadata +73 -72
  131. data/lib/ffi-gobject/ruby_style.rb +0 -23
  132. data/lib/gir_ffi/argument_builder.rb +0 -154
  133. data/lib/gir_ffi/builder/field.rb +0 -60
  134. data/lib/gir_ffi/builder/module.rb +0 -127
  135. data/lib/gir_ffi/builder/type.rb +0 -39
  136. data/lib/gir_ffi/builder/type/base.rb +0 -48
  137. data/lib/gir_ffi/builder/type/callback.rb +0 -30
  138. data/lib/gir_ffi/builder/type/constant.rb +0 -22
  139. data/lib/gir_ffi/builder/type/enum.rb +0 -66
  140. data/lib/gir_ffi/builder/type/interface.rb +0 -33
  141. data/lib/gir_ffi/builder/type/object.rb +0 -134
  142. data/lib/gir_ffi/builder/type/registered_type.rb +0 -62
  143. data/lib/gir_ffi/builder/type/struct.rb +0 -34
  144. data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -39
  145. data/lib/gir_ffi/builder/type/union.rb +0 -34
  146. data/lib/gir_ffi/builder/type/user_defined.rb +0 -107
  147. data/lib/gir_ffi/builder/type/with_layout.rb +0 -62
  148. data/lib/gir_ffi/builder/type/with_methods.rb +0 -64
  149. data/lib/gir_ffi/callback.rb +0 -72
  150. data/lib/gir_ffi/callback_helper.rb +0 -11
  151. data/lib/gir_ffi/error_argument_builder.rb +0 -17
  152. data/lib/gir_ffi/function_builder.rb +0 -112
  153. data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -11
  154. data/lib/gir_ffi/info_ext/i_object_info.rb +0 -11
  155. data/lib/gir_ffi/info_ext/i_struct_info.rb +0 -11
  156. data/lib/gir_ffi/info_ext/i_union_info.rb +0 -12
  157. data/lib/gir_ffi/return_value_builder.rb +0 -81
  158. data/test/ffi-gobject/ruby_style_test.rb +0 -38
  159. data/test/gir_ffi/base_argument_builder_test.rb +0 -13
  160. data/test/gir_ffi/builder/type/callback_test.rb +0 -6
  161. data/test/gir_ffi/builder/type/constant_test.rb +0 -4
  162. data/test/gir_ffi/builder/type/union_test.rb +0 -12
  163. data/test/gir_ffi/callback_helper_test.rb +0 -10
  164. data/test/gir_ffi/callback_test.rb +0 -49
  165. data/test/gir_ffi/info_ext/i_arg_info_test.rb +0 -39
  166. data/test/gir_ffi/info_ext/i_object_info_test.rb +0 -14
data/History.txt CHANGED
@@ -1,3 +1,17 @@
1
+ == 0.6.7 / 2013-09-28
2
+
3
+ * Uniform handling of callback, signal and method arguments
4
+ * Automatically convert array elements to GValue
5
+ * Support inline array fields
6
+ * Support struct fields
7
+ * Improved field setters and getters
8
+ * Support many more types of properties
9
+ * Support skipped arguments and return values
10
+ * Fix refcount for the result of IBaseInfo#container
11
+ * Check bounds in GLib::PtrArray#index and GLib::Array#index
12
+ * Deprecate several methods
13
+ * Lots of refactoring
14
+
1
15
  == 0.6.6 / 2013-08-05
2
16
 
3
17
  * Handle GArrays of booleans and structs
data/TODO.rdoc CHANGED
@@ -8,17 +8,35 @@ reference count of any objects it gets from GObject. This task therefore involve
8
8
  - Free non-GObject pointers as needed (at garbage-collection time)
9
9
  - Lower reference count of GObjects (at garbage-collection time)
10
10
 
11
+ == Refactorings
12
+
13
+ These in the order they occured to me, and may therefore be fixed in any order.
14
+
15
+ - Create Type objects for all FFI types, including the ones currently
16
+ represented by a single symbol, so we can always do stuff like
17
+
18
+ GirFFI::Types::UInt8.get_value_from_pointer(ptr)
19
+
20
+ rather than having awkward dynamic method dispatch inside GirFFI::InOutPointer.
21
+
22
+ - Move code in GirFFI::Struct to StructBase, then somehow unify UnionBase and
23
+ StructBase.
24
+
25
+ - Move to a single Pointer class, rather than InPointer, InOutPointer and
26
+ Pointer monkeypatching.
27
+
28
+ - Move special types like SizedArray to sane namespaces. Types (like
29
+ GLib::List) that have actual GLib implementations go to the GLib namespace.
30
+ Other types go to the GirFFI namespace.
31
+
32
+ - Use argumentbuilders to build signal argument marshalling functions.
33
+
11
34
  == Persistent Ruby GObject identity
12
35
 
13
36
  GirFFI should make sure that if it gets a pointer to a GObject for which a Ruby
14
37
  object already exists, the existing object is returned. This involves the use
15
38
  of WeakRef, no doubt.
16
39
 
17
- == Remove code for passing generic pointers
18
-
19
- Generic pointers have been declared 'not introspectable', so
20
- handling them can be removed.
21
-
22
40
  == Handle fundamental objects that are not GObject.
23
41
 
24
42
  This is a big one. See commit 1e9822c7817062a9b853269b9418fd78782090b5 in
@@ -22,27 +22,21 @@ module GLib
22
22
 
23
23
  def append_vals ary
24
24
  bytes = GirFFI::InPointer.from_array element_type, ary
25
- len = ary.length
26
- Lib.g_array_append_vals(self, bytes, len)
25
+ Lib.g_array_append_vals(self, bytes, ary.length)
27
26
  self
28
27
  end
29
28
 
30
29
  # Re-implementation of the g_array_index macro
31
30
  def index idx
32
- # TODO: Check idx < length
33
- ptr = GirFFI::InOutPointer.new element_type, data + idx * get_element_size
34
- case element_type
35
- when :utf8
36
- GirFFI::ArgHelper.ptr_to_utf8 ptr.to_value
37
- when Symbol
38
- ptr.to_value
39
- else
40
- element_type.wrap ptr.to_value
31
+ if idx >= length or idx < 0
32
+ raise IndexError, "Index #{idx} outside of bounds 0..#{length - 1}"
41
33
  end
34
+ ptr = GirFFI::InOutPointer.new element_type, data_ptr + idx * get_element_size
35
+ ptr.to_ruby_value
42
36
  end
43
37
 
44
38
  def each
45
- length.times.each do |idx|
39
+ length.times do |idx|
46
40
  yield index(idx)
47
41
  end
48
42
  end
@@ -51,10 +45,16 @@ module GLib
51
45
  @struct[:len]
52
46
  end
53
47
 
54
- def data
48
+ def data_ptr
55
49
  @struct[:data]
56
50
  end
57
51
 
52
+ undef :data
53
+
54
+ # @deprecated From 0.7.0, data will return the actual data as a string,
55
+ # as generated by GirFFI.
56
+ alias data data_ptr
57
+
58
58
  def get_element_size
59
59
  Lib.g_array_get_element_size self
60
60
  end
@@ -81,8 +81,7 @@ module GLib
81
81
 
82
82
  def self.calculated_element_size type
83
83
  ffi_type = GirFFI::TypeMap.type_specification_to_ffitype(type)
84
- # FIXME: Smell. Make struct ffi_types into DataConvertor?
85
- FFI.type_size(ffi_type) rescue ffi_type.size
84
+ FFI.type_size(ffi_type)
86
85
  end
87
86
 
88
87
  def calculated_element_size
@@ -13,7 +13,6 @@ module GLib
13
13
  when FFI::Pointer
14
14
  wrap typespec, it
15
15
  when self
16
- # TODO: Reset or check?
17
16
  it.reset_typespec typespec
18
17
  else
19
18
  from_enumerable typespec, it
@@ -8,9 +8,8 @@ module GLib
8
8
  include Enumerable
9
9
  extend ContainerClassMethods
10
10
 
11
- # TODO: Restructure so these can become attr_readers.
12
- attr_accessor :key_type
13
- attr_accessor :value_type
11
+ attr_reader :key_type
12
+ attr_reader :value_type
14
13
 
15
14
  def each
16
15
  prc = Proc.new {|keyptr, valptr, userdata|
@@ -41,7 +40,7 @@ module GLib
41
40
  end
42
41
 
43
42
  def reset_typespec typespec
44
- self.key_type, self.value_type = *typespec
43
+ @key_type, @value_type = *typespec
45
44
  self
46
45
  end
47
46
 
@@ -8,6 +8,8 @@ module GLib
8
8
 
9
9
  attr_accessor :element_type
10
10
 
11
+ POINTER_SIZE = FFI.type_size(:pointer)
12
+
11
13
  class << self
12
14
  remove_method :new
13
15
  # Remove stub generated by builder.
@@ -46,17 +48,23 @@ module GLib
46
48
 
47
49
  # Re-implementation of the g_ptr_array_index macro
48
50
  def index idx
49
- sz = FFI.type_size :pointer
50
- ptr = @struct[:pdata].get_pointer(idx * sz)
51
- GirFFI::ArgHelper.cast_from_pointer(element_type, ptr)
51
+ if idx >= length or idx < 0
52
+ raise IndexError, "Index #{idx} outside of bounds 0..#{length - 1}"
53
+ end
54
+ ptr = GirFFI::InOutPointer.new element_type, @struct[:pdata] + idx * POINTER_SIZE
55
+ ptr.to_ruby_value
52
56
  end
53
57
 
54
58
  def each
55
- @struct[:len].times.each do |idx|
59
+ length.times do |idx|
56
60
  yield index(idx)
57
61
  end
58
62
  end
59
63
 
64
+ def length
65
+ @struct[:len]
66
+ end
67
+
60
68
  def ==(other)
61
69
  self.to_a == other.to_a
62
70
  end
@@ -1,3 +1,4 @@
1
+ # FIXME: SizedArray does not really belong in GLib, does it?
1
2
  module GLib
2
3
  # Class representing an array with a determined size
3
4
  class SizedArray
@@ -14,14 +15,14 @@ module GLib
14
15
  @pointer
15
16
  end
16
17
 
18
+ def index idx
19
+ ptr = GirFFI::InOutPointer.new element_type, @pointer + idx * element_size
20
+ ptr.to_ruby_value
21
+ end
22
+
17
23
  def each &block
18
- # TODO: Move implementation from GirFFI::ArgHelper to here.
19
- # While doing so, the implentation could also become a real iterator
20
- arr = GirFFI::ArgHelper.ptr_to_typed_array(@element_type, @pointer, @size)
21
- if block_given?
22
- arr.each(&block)
23
- else
24
- arr.each
24
+ size.times do |idx|
25
+ yield index(idx)
25
26
  end
26
27
  end
27
28
 
@@ -29,6 +30,25 @@ module GLib
29
30
  self.to_a == other.to_a
30
31
  end
31
32
 
33
+ def size_in_bytes
34
+ size * element_size
35
+ end
36
+
37
+ def self.copy_value_to_pointer value, pointer
38
+ size = value.size_in_bytes
39
+ pointer.put_bytes(0, value.to_ptr.read_bytes(size), 0, size)
40
+ end
41
+
42
+ private
43
+
44
+ def element_ffi_type
45
+ @element_ffi_type ||= GirFFI::TypeMap.type_specification_to_ffitype element_type
46
+ end
47
+
48
+ def element_size
49
+ @element_size ||= FFI.type_size element_ffi_type
50
+ end
51
+
32
52
  def self.wrap element_type, size, pointer
33
53
  new element_type, size, pointer unless pointer.null?
34
54
  end
data/lib/ffi-gobject.rb CHANGED
@@ -10,13 +10,9 @@ require 'ffi-gobject/initially_unowned'
10
10
  require 'ffi-gobject/closure'
11
11
  require 'ffi-gobject/object'
12
12
  require 'ffi-gobject/ruby_closure'
13
- require 'gir_ffi/builder/type/user_defined'
13
+ require 'gir_ffi/builders/user_defined_builder'
14
14
 
15
15
  module GObject
16
- def self.type_init
17
- Lib::g_type_init
18
- end
19
-
20
16
  def self.object_ref obj
21
17
  Lib::g_object_ref obj.to_ptr
22
18
  end
@@ -76,9 +72,9 @@ module GObject
76
72
  signal, _ = detailed_signal.split('::')
77
73
  sig_info = object.class.find_signal signal
78
74
  callback = sig_info.signal_callback(&block)
79
- GirFFI::CallbackHelper.store_callback callback
75
+ GirFFI::CallbackBase.store_callback callback
80
76
 
81
- data_ptr = GirFFI::ArgHelper.object_to_inptr data
77
+ data_ptr = GirFFI::InPointer.from_object data
82
78
 
83
79
  Lib.g_signal_connect_data object, detailed_signal, callback, data_ptr, nil, 0
84
80
  end
@@ -105,12 +101,13 @@ module GObject
105
101
  attach_function :g_object_unref, [:pointer], :void
106
102
  attach_function :g_object_is_floating, [:pointer], :bool
107
103
 
108
- attach_function :g_strv_get_type, [], :size_t
104
+ attach_function :g_array_get_type, [], :size_t
109
105
  attach_function :g_hash_table_get_type, [], :size_t
106
+ attach_function :g_strv_get_type, [], :size_t
110
107
 
111
108
  attach_function :g_signal_connect_data,
112
109
  [:pointer, :string, Callback, :pointer, ClosureNotify, ConnectFlags],
113
- :ulong
110
+ :ulong
114
111
  attach_function :g_closure_set_marshal,
115
112
  [:pointer, ClosureMarshal], :void
116
113
 
@@ -119,17 +116,19 @@ module GObject
119
116
  :pointer
120
117
  end
121
118
 
122
- TYPE_STRV = Lib.g_strv_get_type
119
+ TYPE_ARRAY = Lib.g_array_get_type
123
120
  TYPE_HASH_TABLE = Lib.g_hash_table_get_type
121
+ TYPE_STRV = Lib.g_strv_get_type
124
122
 
125
123
  TYPE_TAG_TO_GTYPE = {
126
- :void => TYPE_NONE,
124
+ :array => TYPE_ARRAY,
127
125
  :gboolean => TYPE_BOOLEAN,
128
- :gint32 => TYPE_INT,
129
- :gfloat => TYPE_FLOAT,
130
126
  :gdouble => TYPE_DOUBLE,
131
- :utf8 => TYPE_STRING,
127
+ :gfloat => TYPE_FLOAT,
132
128
  :ghash => TYPE_HASH_TABLE,
133
- :glist => TYPE_POINTER
129
+ :gint32 => TYPE_INT,
130
+ :glist => TYPE_POINTER,
131
+ :utf8 => TYPE_STRING,
132
+ :void => TYPE_NONE
134
133
  }
135
134
  end
@@ -4,7 +4,7 @@ module GObject
4
4
  # Overrides for GClosure, GObject's base class for closure objects.
5
5
  class Closure
6
6
  def set_marshal marshal
7
- callback = GirFFI::Callback.from("GObject", "ClosureMarshal", marshal)
7
+ callback = GObject::ClosureMarshal.from marshal
8
8
  Lib.g_closure_set_marshal self, callback
9
9
  end
10
10
  end
@@ -1,35 +1,57 @@
1
- require 'ffi-gobject/ruby_style'
2
-
3
1
  module GObject
4
2
  load_class :Object
5
3
 
6
4
  # Overrides for GObject, GObject's generic base class.
7
5
  class Object
8
6
 
9
- include RubyStyle
10
-
11
7
  setup_method "new"
8
+
9
+ # TODO: Generate accessor methods from GIR at class definition time
10
+ def method_missing(method, *args)
11
+ if respond_to?("get_#{method}")
12
+ return send("get_#{method}", *args)
13
+ end
14
+ if method.to_s =~ /(.*)=$/ && respond_to?("set_#{$1}")
15
+ return send("set_#{$1}", *args)
16
+ end
17
+ super
18
+ end
19
+
20
+ def signal_connect(event, &block)
21
+ GObject.signal_connect(self, event, &block)
22
+ end
23
+
12
24
  setup_instance_method "get_property"
13
25
  setup_instance_method "set_property"
14
26
 
15
27
  def get_property_with_override property_name
16
- type = get_property_type property_name
17
- gvalue = type.make_g_value
28
+ type_info = get_property_type property_name
29
+ pspec = type_class.find_property property_name
18
30
 
31
+ gvalue = GObject::Value.for_g_type pspec.value_type
19
32
  get_property_without_override property_name, gvalue
20
33
 
21
- adjust_value_to_type gvalue.get_value, type
34
+ case type_info.tag
35
+ when :ghash, :glist
36
+ adjust_value_to_type gvalue.get_value_plain, type_info
37
+ else
38
+ gvalue.get_value
39
+ end
22
40
  end
23
41
 
24
42
  def set_property_with_override property_name, value
25
- type = get_property_type property_name
26
- gvalue = type.make_g_value
27
-
28
- gvalue.set_value adjust_value_to_type(value, type)
43
+ type_info = get_property_type property_name
44
+ pspec = type_class.find_property property_name
29
45
 
46
+ gvalue = GObject::Value.for_g_type pspec.value_type
47
+ gvalue.set_value adjust_value_to_type(value, type_info)
30
48
  set_property_without_override property_name, gvalue
31
49
  end
32
50
 
51
+ def type_class
52
+ GObject::ObjectClass.wrap(self.to_ptr.get_pointer 0)
53
+ end
54
+
33
55
  alias get_property_without_override get_property
34
56
  alias get_property get_property_with_override
35
57
 
@@ -43,12 +65,15 @@ module GObject
43
65
  prop.property_type
44
66
  end
45
67
 
46
- def adjust_value_to_type val, type
47
- case type.tag
68
+ # TODO: Move to ITypeInfo
69
+ def adjust_value_to_type val, type_info
70
+ case type_info.flattened_tag
48
71
  when :ghash
49
- GLib::HashTable.from type.element_type, val
72
+ GLib::HashTable.from type_info.element_type, val
50
73
  when :glist
51
- GLib::List.from type.element_type, val
74
+ GLib::List.from type_info.element_type, val
75
+ when :strv
76
+ GLib::Strv.from val
52
77
  else
53
78
  val
54
79
  end
@@ -37,7 +37,6 @@ module GObject
37
37
  return closure
38
38
  end
39
39
 
40
- # TODO: Use invocation_hint and marshal_data
41
40
  def self.marshaller(closure, return_value, n_param_values,
42
41
  param_values, _invocation_hint, _marshal_data)
43
42
  rclosure = wrap(closure.to_ptr)
@@ -14,16 +14,24 @@ module GObject
14
14
 
15
15
  TYPE_TO_SET_METHOD_MAP = {
16
16
  TYPE_BOOLEAN => :set_boolean,
17
- TYPE_INT => :set_int,
18
- TYPE_INT64 => :set_int64,
19
- TYPE_STRING => :set_string,
20
- TYPE_FLOAT => :set_float,
17
+ TYPE_BOXED => :set_boxed,
18
+ TYPE_CHAR => :set_char,
21
19
  TYPE_DOUBLE => :set_double,
22
- TYPE_PARAM => :set_param,
20
+ TYPE_ENUM => :set_enum,
21
+ TYPE_FLOAT => :set_float,
22
+ TYPE_GTYPE => :set_gtype,
23
+ TYPE_INT64 => :set_int64,
24
+ TYPE_INT => :set_int,
25
+ TYPE_LONG => :set_long,
23
26
  TYPE_OBJECT => :set_instance_enhanced,
24
- TYPE_BOXED => :set_boxed,
27
+ TYPE_PARAM => :set_param,
25
28
  TYPE_POINTER => :set_pointer,
26
- TYPE_ENUM => :set_enum
29
+ TYPE_STRING => :set_string,
30
+ TYPE_UCHAR => :set_uchar,
31
+ TYPE_UINT => :set_uint,
32
+ TYPE_UINT64 => :set_uint64,
33
+ TYPE_ULONG => :set_ulong,
34
+ TYPE_VARIANT => :set_variant,
27
35
  }
28
36
 
29
37
  def value= val
@@ -66,17 +74,34 @@ module GObject
66
74
 
67
75
  TYPE_TO_GET_METHOD_MAP = {
68
76
  TYPE_BOOLEAN => :get_boolean,
69
- TYPE_INT => :get_int,
70
- TYPE_INT64 => :get_int64,
71
- TYPE_STRING => :get_string,
72
- TYPE_FLOAT => :get_float,
77
+ TYPE_BOXED => :get_boxed,
78
+ TYPE_CHAR => :get_char,
73
79
  TYPE_DOUBLE => :get_double,
80
+ TYPE_FLOAT => :get_float,
81
+ TYPE_GTYPE => :get_gtype,
82
+ TYPE_INT64 => :get_int64,
83
+ TYPE_INT => :get_int,
84
+ TYPE_LONG => :get_long,
74
85
  TYPE_OBJECT => :get_object,
75
- TYPE_BOXED => :get_boxed_enhanced,
76
- TYPE_POINTER => :get_pointer
86
+ TYPE_POINTER => :get_pointer,
87
+ TYPE_STRING => :get_string,
88
+ TYPE_UCHAR => :get_uchar,
89
+ TYPE_UINT => :get_uint,
90
+ TYPE_UINT64 => :get_uint64,
91
+ TYPE_ULONG => :get_ulong,
92
+ TYPE_VARIANT => :get_variant,
77
93
  }
78
94
 
79
95
  def get_value
96
+ value = get_value_plain
97
+ if current_fundamental_type == TYPE_BOXED
98
+ wrap_boxed value
99
+ else
100
+ value
101
+ end
102
+ end
103
+
104
+ def get_value_plain
80
105
  send get_method
81
106
  end
82
107
 
@@ -129,27 +154,26 @@ module GObject
129
154
  end
130
155
  end
131
156
 
132
- def get_boxed_enhanced
133
- boxed = get_boxed
134
- gtype = current_gtype
135
-
136
- case gtype
157
+ def wrap_boxed boxed
158
+ case current_gtype
137
159
  when TYPE_STRV
138
160
  GLib::Strv.wrap boxed
139
161
  when TYPE_HASH_TABLE
140
162
  GLib::HashTable.wrap [:gpointer, :gpointer], boxed
141
163
  else
142
- GirFFI::ArgHelper.wrap_object_pointer_by_gtype boxed, gtype
164
+ boxed.wrap_by_gtype current_gtype
143
165
  end
144
166
  end
145
167
 
146
168
  def get_method
147
- TYPE_TO_GET_METHOD_MAP[current_fundamental_type] or
169
+ TYPE_TO_GET_METHOD_MAP[current_gtype] or
170
+ TYPE_TO_GET_METHOD_MAP[current_fundamental_type] or
148
171
  raise "Can't find method to get #{current_gtype_name}"
149
172
  end
150
173
 
151
174
  def set_method
152
- TYPE_TO_SET_METHOD_MAP[current_fundamental_type] or
175
+ TYPE_TO_SET_METHOD_MAP[current_gtype] or
176
+ TYPE_TO_SET_METHOD_MAP[current_fundamental_type] or
153
177
  raise "Can't find method to set #{current_gtype_name}"
154
178
  end
155
179
  end