gir_ffi 0.7.4 → 0.7.5

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.
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
@@ -3,12 +3,13 @@ require 'gir_ffi/builders/null_builder'
3
3
  require 'gir_ffi/registered_type_base'
4
4
 
5
5
  module GirFFI
6
- # Base class for all generated classes. Contains code for dealing with
7
- # the generated Struct classes.
6
+ # Base class for all generated classes and structs. Contains code for dealing
7
+ # with the generated nested Struct classes.
8
8
  class ClassBase
9
9
  extend RegisteredTypeBase
10
10
  extend Forwardable
11
11
 
12
+ attr_reader :struct
12
13
  def_delegators :@struct, :to_ptr
13
14
 
14
15
  GIR_FFI_BUILDER = NullBuilder.new
@@ -20,39 +21,32 @@ module GirFFI
20
21
  raise RuntimeError, "Unable to set up instance method '#{method}' in #{self}"
21
22
  end
22
23
 
23
- self.send method_name, *arguments, &block
24
+ send method_name, *arguments, &block
24
25
  end
25
26
 
26
- if RUBY_PLATFORM == 'java'
27
- # FIXME: JRuby should fix FFI::MemoryPointer#== to return true for
28
- # equivalent FFI::Pointer.
29
- def ==(other)
30
- other.class == self.class && self.to_ptr.address == other.to_ptr.address
31
- end
32
- else
33
- def ==(other)
34
- other.class == self.class && self.to_ptr == other.to_ptr
35
- end
27
+ # NOTE: JRuby should fix FFI::MemoryPointer#== to return true for
28
+ # equivalent FFI::Pointer. For now, user to_ptr.address
29
+ def == other
30
+ other.class == self.class && to_ptr.address == other.to_ptr.address
36
31
  end
37
32
 
38
33
  def self.setup_and_call method, *arguments, &block
39
- method_name = self.try_in_ancestors(:setup_method, method.to_s)
34
+ method_name = try_in_ancestors(:setup_method, method.to_s)
40
35
 
41
36
  unless method_name
42
37
  raise RuntimeError, "Unable to set up method '#{method}' in #{self}"
43
38
  end
44
39
 
45
- self.send method_name, *arguments, &block
40
+ send method_name, *arguments, &block
46
41
  end
47
42
 
48
- def self.try_in_ancestors(method, *arguments)
49
- self.ancestors.each do |klass|
43
+ def self.try_in_ancestors method, *arguments
44
+ ancestors.each do |klass|
50
45
  if klass.respond_to?(method)
51
46
  result = klass.send(method, *arguments)
52
47
  return result if result
53
48
  end
54
49
  end
55
- return
56
50
  end
57
51
 
58
52
  class << self
@@ -99,5 +93,21 @@ module GirFFI
99
93
  val
100
94
  end
101
95
  end
96
+
97
+ #
98
+ # Wraps a pointer retrieved from a constructor method. Here, it is simply
99
+ # defined as a wrapper around direct_wrap, but, e.g., InitiallyUnowned
100
+ # overrides it to sink the floating object.
101
+ #
102
+ # This method assumes the pointer will always be of the type corresponding
103
+ # to the current class, and never of a subtype.
104
+ #
105
+ # @param ptr Pointer to the object's C structure
106
+ #
107
+ # @return An object of the current class wrapping the pointer
108
+ #
109
+ def self.constructor_wrap ptr
110
+ direct_wrap ptr
111
+ end
102
112
  end
103
113
  end
@@ -18,7 +18,7 @@ module GirFFI
18
18
  self::Enum.from_native(*args)
19
19
  end
20
20
 
21
- def [](arg)
21
+ def [] arg
22
22
  self::Enum[arg]
23
23
  end
24
24
 
@@ -45,7 +45,7 @@ module GirFFI
45
45
  raise RuntimeError, "Unable to set up method #{method} in #{self}"
46
46
  end
47
47
 
48
- self.send method, *arguments, &block
48
+ send method, *arguments, &block
49
49
  end
50
50
 
51
51
  def to_ffitype
@@ -1,5 +1,6 @@
1
1
  module GirFFI
2
2
  module FFIExt
3
+ # Extensions to FFI::Pointer
3
4
  module Pointer
4
5
  def to_ptr
5
6
  self
@@ -21,7 +21,7 @@ module GirFFI
21
21
  when Module
22
22
  value_ffi_type.get_value_from_pointer(self)
23
23
  when Symbol
24
- self.send("get_#{value_ffi_type}", 0)
24
+ send("get_#{value_ffi_type}", 0)
25
25
  else
26
26
  raise NotImplementedError
27
27
  end
@@ -47,7 +47,7 @@ module GirFFI
47
47
  when Module
48
48
  value_ffi_type.copy_value_to_pointer(value, self)
49
49
  when Symbol
50
- self.send "put_#{value_ffi_type}", 0, value
50
+ send "put_#{value_ffi_type}", 0, value
51
51
  else
52
52
  raise NotImplementedError, value_ffi_type
53
53
  end
@@ -58,11 +58,11 @@ module GirFFI
58
58
  end
59
59
 
60
60
  def self.for type
61
- self.new(type).tap {|ptr| ptr.clear}
61
+ new(type).tap {|ptr| ptr.clear}
62
62
  end
63
63
 
64
64
  def self.from type, value
65
- self.new(type).tap {|ptr| ptr.set_value value}
65
+ new(type).tap {|ptr| ptr.set_value value}
66
66
  end
67
67
 
68
68
  private
@@ -35,11 +35,11 @@ module GirFFI
35
35
  when :utf8, :filename
36
36
  from_utf8 val
37
37
  when :gint32, :guint32, :gint8
38
- self.new val
38
+ new val
39
39
  when Class, :void
40
40
  val.to_ptr
41
41
  when Module
42
- self.new type[val]
42
+ new type[val]
43
43
  else
44
44
  raise NotImplementedError, type
45
45
  end
@@ -0,0 +1,16 @@
1
+ module GirFFI
2
+ module InfoExt
3
+ # Extension module provinding a #full_type_name method suitable for
4
+ # callbacks, constants and registered types. Signals and vfuncs need a
5
+ # different implementation.
6
+ module FullTypeName
7
+ def full_type_name
8
+ "#{safe_namespace}::#{safe_name}"
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ GObjectIntrospection::ICallbackInfo.send :include, GirFFI::InfoExt::FullTypeName
15
+ GObjectIntrospection::IConstantInfo.send :include, GirFFI::InfoExt::FullTypeName
16
+ GObjectIntrospection::IRegisteredTypeInfo.send :include, GirFFI::InfoExt::FullTypeName
@@ -4,16 +4,15 @@ module GirFFI
4
4
  module IArgInfo
5
5
  def to_ffitype
6
6
  return :pointer if direction != :in
7
- return argument_type.to_ffitype
7
+ argument_type.to_ffitype
8
8
  end
9
9
 
10
10
  def to_callback_ffitype
11
11
  return :pointer if direction != :in
12
- return argument_type.to_callback_ffitype
12
+ argument_type.to_callback_ffitype
13
13
  end
14
14
  end
15
15
  end
16
16
  end
17
17
 
18
18
  GObjectIntrospection::IArgInfo.send :include, GirFFI::InfoExt::IArgInfo
19
-
@@ -11,17 +11,10 @@ module GirFFI
11
11
  end
12
12
 
13
13
  def return_ffi_type
14
- result = return_type.to_callback_ffitype
15
- # FIXME: Should this be in ITypeInfo#to_callback_ffitype?
16
- if result == GLib::Boolean
17
- :bool
18
- else
19
- result
20
- end
14
+ return_type.to_callback_ffitype
21
15
  end
22
16
  end
23
17
  end
24
18
  end
25
19
 
26
20
  GObjectIntrospection::ICallbackInfo.send :include, GirFFI::InfoExt::ICallbackInfo
27
-
@@ -14,4 +14,3 @@ module GirFFI
14
14
  end
15
15
 
16
16
  GObjectIntrospection::IPropertyInfo.send :include, GirFFI::InfoExt::IPropertyInfo
17
-
@@ -21,4 +21,3 @@ module GirFFI
21
21
  end
22
22
 
23
23
  GObjectIntrospection::IRegisteredTypeInfo.send :include, GirFFI::InfoExt::IRegisteredTypeInfo
24
-
@@ -2,32 +2,21 @@ module GirFFI
2
2
  module InfoExt
3
3
  # Extensions for GObjectIntrospection::ISignalInfo needed by GirFFI
4
4
  module ISignalInfo
5
- # Create a signal hander callback. Wraps the given block in such a way that
6
- # arguments and return value are cast correctly to the ruby world and back.
5
+ # Create a signal hander closure. Wraps the given block in a custom
6
+ # descendent of RubyClosure with a marshaller tailored for this signal.
7
7
  #
8
8
  # @param block The body of the signal handler
9
9
  #
10
- # @return [FFI::Function] The signal handler, ready to be passed as a
11
- # callback to C.
12
- def create_callback &block
13
- raise ArgumentError, "Block needed" unless block
14
-
15
- # TODO: Find the signal module directly, then retrieve the info
16
- # from that, instead of vice versa.
17
- bldr = Builders::SignalBuilder.new(self)
18
- wrapped = bldr.build_class.from(block)
19
- # FIXME: Logically, this should use CallbackBase#to_native
20
- FFI::Function.new return_ffi_type, ffi_callback_argument_types, &wrapped
10
+ # @return [GObject::RubyClosure] The signal handler closure, ready to be
11
+ # passed as a GClosure to C.
12
+ def wrap_in_closure &block
13
+ bldr = Builders::SignalClosureBuilder.new(self)
14
+ bldr.build_class.new(&block)
21
15
  end
22
16
 
23
17
  # TODO: Use argument info to convert out arguments and array lengths.
24
- def arguments_to_gvalue_array_pointer object, args
25
- arr = arguments_to_gvalues object, args
26
- GirFFI::InPointer.from_array GObject::Value, arr
27
- end
28
-
29
18
  def arguments_to_gvalues instance, arguments
30
- arg_values = self.args.zip(arguments).map do |info, arg|
19
+ arg_values = args.zip(arguments).map do |info, arg|
31
20
  info.argument_type.make_g_value.set_value(arg)
32
21
  end
33
22
 
@@ -37,27 +26,6 @@ module GirFFI
37
26
  def gvalue_for_return_value
38
27
  return_type.make_g_value
39
28
  end
40
-
41
- # TODO: Rename and clarify relation to argument_ffi_types:
42
- # The types returned by ffi_callback_argument_types are more basic than
43
- # those returned by argument_ffi_types. Is there a way to make these
44
- # methods more related? Perhaps argument_ffi_types can return more basic
45
- # types as well?
46
- def ffi_callback_argument_types
47
- types = args.map do |arg|
48
- arg.to_callback_ffitype
49
- end
50
- types.unshift(:pointer).push(:pointer)
51
- end
52
-
53
- def return_ffi_type
54
- result = return_type.to_ffitype
55
- if result == GLib::Boolean
56
- :bool
57
- else
58
- result
59
- end
60
- end
61
29
  end
62
30
  end
63
31
  end
@@ -112,16 +112,22 @@ module GirFFI
112
112
  end
113
113
  end
114
114
 
115
+ # TODO: Use either ffitype or ffi_type everywhere
115
116
  def to_callback_ffitype
116
117
  return :pointer if pointer?
117
118
 
118
- if tag == :interface
119
+ case tag
120
+ when :interface
121
+ # TODO: Move this logic into interface
119
122
  case interface.info_type
120
123
  when :enum, :flags
121
124
  :int32
122
125
  else
123
126
  :pointer
124
127
  end
128
+ when :gboolean
129
+ # TODO: Move this logic into TypeMap
130
+ :bool
125
131
  else
126
132
  TypeMap.map_basic_type tag
127
133
  end
@@ -156,6 +162,10 @@ module GirFFI
156
162
  needs_c_to_ruby_conversion_for_functions?
157
163
  end
158
164
 
165
+ def needs_c_to_ruby_conversion_for_closures?
166
+ [:array, :c, :ghash, :struct, :strv].include?(flattened_tag)
167
+ end
168
+
159
169
  def extra_conversion_arguments
160
170
  case flattened_tag
161
171
  when :utf8, :void
@@ -183,7 +193,7 @@ module GirFFI
183
193
  subtype_tag_or_class 0
184
194
  end
185
195
 
186
- def subtype_ffitype(index)
196
+ def subtype_ffitype index
187
197
  subtype = param_type(index).to_ffitype
188
198
  if subtype == :pointer
189
199
  # NOTE: Don't use pointer directly to appease JRuby.
@@ -10,12 +10,7 @@ module GirFFI
10
10
  end
11
11
 
12
12
  def return_ffi_type
13
- result = return_type.to_callback_ffitype
14
- if result == GLib::Boolean
15
- :bool
16
- else
17
- result
18
- end
13
+ return_type.to_callback_ffitype
19
14
  end
20
15
  end
21
16
  end
@@ -12,11 +12,6 @@ module GirFFI
12
12
  end
13
13
  end
14
14
  end
15
-
16
- # FIXME: This is invalid for ISignalInfo and IVFuncInfo
17
- def full_type_name
18
- "#{safe_namespace}::#{safe_name}"
19
- end
20
15
  end
21
16
  end
22
17
  end
@@ -1,3 +1,4 @@
1
+ require 'gir_ffi/info_ext/full_type_name'
1
2
  require 'gir_ffi/info_ext/i_arg_info'
2
3
  require 'gir_ffi/info_ext/i_callable_info'
3
4
  require 'gir_ffi/info_ext/i_callback_info'
data/lib/gir_ffi/lib_c.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'ffi'
2
2
 
3
3
  module GirFFI
4
+ # Library of libc functions.
4
5
  module LibC
5
6
  extend FFI::Library
6
7
  ffi_lib FFI::Library::LIBC
@@ -4,7 +4,7 @@ module GirFFI
4
4
  def method_missing method, *arguments, &block
5
5
  result = setup_method method.to_s
6
6
  return super unless result
7
- self.send method, *arguments, &block
7
+ send method, *arguments, &block
8
8
  end
9
9
 
10
10
  def const_missing classname
@@ -18,7 +18,7 @@ module GirFFI
18
18
  alias load_class setup_class
19
19
 
20
20
  def gir_ffi_builder
21
- self.const_get :GIR_FFI_BUILDER
21
+ const_get :GIR_FFI_BUILDER
22
22
  end
23
23
 
24
24
  def setup_method name
@@ -1,22 +1,6 @@
1
1
  module GirFFI
2
2
  # Base class for all generated classes of type :object.
3
3
  class ObjectBase < ClassBase
4
- #
5
- # Wraps a pointer retrieved from a constructor method. Here, it is simply
6
- # defined as a wrapper around direct_wrap, but, e.g., InitiallyUnowned
7
- # overrides it to sink the floating object.
8
- #
9
- # Unlike wrap, this method assumes the pointer will always be of the type
10
- # corresponding to the current class, and never of a subtype.
11
- #
12
- # @param ptr Pointer to the object's C structure
13
- #
14
- # @return An object of the current class wrapping the pointer
15
- #
16
- def self.constructor_wrap ptr
17
- direct_wrap ptr
18
- end
19
-
20
4
  # Wrap the passed pointer in an instance of its type's corresponding class,
21
5
  # generally assumed to be a descendant of the current type.
22
6
  def self.wrap ptr
@@ -11,10 +11,6 @@ class GirFFI::ReceiverArgumentInfo
11
11
  :in
12
12
  end
13
13
 
14
- def skip?
15
- false
16
- end
17
-
18
14
  def name
19
15
  "_instance"
20
16
  end
@@ -11,4 +11,3 @@ module GirFFI
11
11
  end
12
12
  end
13
13
  end
14
-
@@ -19,14 +19,14 @@ module GirFFI
19
19
  ptr.to_ruby_value
20
20
  end
21
21
 
22
- def each &block
22
+ def each
23
23
  size.times do |idx|
24
24
  yield index(idx)
25
25
  end
26
26
  end
27
27
 
28
- def ==(other)
29
- self.to_a == other.to_a
28
+ def == other
29
+ to_a == other.to_a
30
30
  end
31
31
 
32
32
  def size_in_bytes
@@ -81,10 +81,10 @@ module GirFFI
81
81
  size = arr.size
82
82
  check_size expected_size, size
83
83
  ptr = GirFFI::InPointer.from_array element_type, arr
84
- self.wrap element_type, size, ptr
84
+ wrap element_type, size, ptr
85
85
  end
86
86
 
87
- def check_size(expected_size, size)
87
+ def check_size expected_size, size
88
88
  if expected_size > 0 && size != expected_size
89
89
  raise ArgumentError, "Expected size #{expected_size}, got #{size}"
90
90
  end
@@ -13,6 +13,10 @@ module GirFFI
13
13
  self
14
14
  end
15
15
 
16
+ def self.to_native value, _context
17
+ value.struct
18
+ end
19
+
16
20
  def self.get_value_from_pointer pointer
17
21
  pointer.to_ptr
18
22
  end
@@ -2,11 +2,11 @@ module GirFFI
2
2
  # Base module for all generated GLib types.
3
3
  module TypeBase
4
4
  def gir_ffi_builder
5
- self.const_get :GIR_FFI_BUILDER
5
+ const_get :GIR_FFI_BUILDER
6
6
  end
7
7
 
8
8
  def gir_info
9
- self.const_get :GIR_INFO
9
+ const_get :GIR_INFO
10
10
  end
11
11
  end
12
12
  end
@@ -1,6 +1,7 @@
1
1
  require 'gir_ffi/sized_array'
2
2
 
3
3
  module GirFFI
4
+ # Maps GObject type tags and type specification to types FFI can handle.
4
5
  module TypeMap
5
6
  sz = FFI.type_size(:size_t) * 8
6
7
  gsize_type = "uint#{sz}".to_sym
@@ -4,9 +4,7 @@ module GirFFI
4
4
  class UnintrospectableTypeInfo
5
5
  attr_reader :g_type
6
6
 
7
- def initialize(gtype,
8
- gir = GObjectIntrospection::IRepository.default,
9
- gobject = ::GObject)
7
+ def initialize gtype, gir = GObjectIntrospection::IRepository.default, gobject = GObject
10
8
  @g_type = gtype
11
9
  @gir = gir
12
10
  @gobject = gobject
@@ -1,5 +1,7 @@
1
1
  require 'gir_ffi/info_ext/i_type_info'
2
2
 
3
+ # Represents the type of the user data (closure argument) of a signal or vfunc,
4
+ # conforming, as needed, to the interface of GObjectIntrospection::ITypeInfo.
3
5
  class GirFFI::UserDataTypeInfo
4
6
  include GirFFI::InfoExt::ITypeInfo
5
7
 
@@ -1,3 +1,4 @@
1
+ # Current GirFFI version
1
2
  module GirFFI
2
- VERSION = "0.7.4"
3
+ VERSION = "0.7.5"
3
4
  end
@@ -15,24 +15,24 @@ module GirFFI
15
15
  end
16
16
 
17
17
  def self.from type, arg
18
- self.new type, InPointer.from_array(type, arg)
18
+ new type, InPointer.from_array(type, arg)
19
19
  end
20
20
 
21
21
  def self.wrap type, arg
22
- self.new type, arg
22
+ new type, arg
23
23
  end
24
24
 
25
25
  def each
26
26
  return if @ptr.null?
27
27
  offset = 0
28
28
  while val = read_value(offset)
29
- offset += FFI.type_size(ffi_type)
29
+ offset += ffi_type_size
30
30
  yield wrap_value(val)
31
31
  end
32
32
  end
33
33
 
34
- def ==(other)
35
- self.to_a == other.to_a
34
+ def == other
35
+ to_a == other.to_a
36
36
  end
37
37
 
38
38
  private
@@ -46,7 +46,7 @@ module GirFFI
46
46
  @getter_method ||= "get_#{ffi_type}"
47
47
  end
48
48
 
49
- def wrap_value(val)
49
+ def wrap_value val
50
50
  case element_type
51
51
  when Array
52
52
  element_type.last.wrap val
@@ -6,11 +6,11 @@ module GLib
6
6
  extend FFI::DataConverter
7
7
  native_type FFI::Type::INT
8
8
 
9
- def self.from_native value, context
9
+ def self.from_native value, _context
10
10
  value != 0 ? true : false
11
11
  end
12
12
 
13
- def self.to_native value, context
13
+ def self.to_native value, _context
14
14
  value ? 1 : 0
15
15
  end
16
16
 
@@ -24,7 +24,7 @@ module GLib
24
24
  end
25
25
 
26
26
  def self.wrap ptr
27
- self.new ptr
27
+ new ptr
28
28
  end
29
29
 
30
30
  private
@@ -1,4 +1,5 @@
1
1
  module GObject
2
+ # Module for attaching functions from the gobject library
2
3
  module Lib
3
4
  extend FFI::Library
4
5
  ffi_lib "gobject-2.0"
@@ -3,6 +3,6 @@ require 'gir_ffi-base/gobject/lib'
3
3
  # The part of the GObject namespace that is needed by GObjectIntrospection.
4
4
  module GObject
5
5
  def self.type_init
6
- Lib::g_type_init
6
+ Lib.g_type_init
7
7
  end
8
8
  end
data/lib/gir_ffi.rb CHANGED
@@ -17,6 +17,8 @@ require 'gir_ffi/user_defined_type_info'
17
17
  require 'gir_ffi/builder'
18
18
  require 'gir_ffi/version'
19
19
 
20
+ # Main module containing classes and modules needed for generating GLib and
21
+ # GObject bindings.
20
22
  module GirFFI
21
23
  def self.setup module_name, version=nil
22
24
  module_name = module_name.to_s
@@ -8,7 +8,7 @@ describe GLib::HashTable do
8
8
  end
9
9
 
10
10
  describe "::from" do
11
- it "creates a GHashTable from a Ruby array" do
11
+ it "creates a GHashTable from a Ruby hash" do
12
12
  hsh = GLib::HashTable.from [:utf8, :gint32],
13
13
  {"foo" => 23, "bar" => 32}
14
14
  assert_equal({"foo" => 23, "bar" => 32}, hsh.to_hash)