gir_ffi 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +17 -1
  3. data/README.md +1 -1
  4. data/Rakefile +0 -7
  5. data/examples/main_loop.rb +12 -0
  6. data/lib/ffi-glib/array.rb +18 -5
  7. data/lib/ffi-glib/array_methods.rb +1 -1
  8. data/lib/ffi-glib/list.rb +1 -1
  9. data/lib/ffi-glib/list_methods.rb +1 -1
  10. data/lib/ffi-glib/main_loop.rb +51 -0
  11. data/lib/ffi-glib/ptr_array.rb +2 -2
  12. data/lib/ffi-glib/s_list.rb +1 -1
  13. data/lib/ffi-glib/variant.rb +3 -3
  14. data/lib/ffi-glib.rb +1 -0
  15. data/lib/ffi-gobject/initially_unowned.rb +1 -1
  16. data/lib/ffi-gobject/object.rb +14 -12
  17. data/lib/ffi-gobject/ruby_closure.rb +3 -2
  18. data/lib/ffi-gobject/value.rb +12 -16
  19. data/lib/ffi-gobject.rb +4 -21
  20. data/lib/ffi-gobject_introspection/i_base_info.rb +3 -3
  21. data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -1
  22. data/lib/ffi-gobject_introspection/i_repository.rb +1 -1
  23. data/lib/ffi-gobject_introspection/lib.rb +1 -1
  24. data/lib/gir_ffi/arg_helper.rb +2 -2
  25. data/lib/gir_ffi/builder.rb +1 -1
  26. data/lib/gir_ffi/builders/argument_builder.rb +19 -17
  27. data/lib/gir_ffi/builders/argument_builder_collection.rb +51 -16
  28. data/lib/gir_ffi/builders/base_argument_builder.rb +20 -10
  29. data/lib/gir_ffi/builders/base_type_builder.rb +6 -5
  30. data/lib/gir_ffi/builders/callback_argument_builder.rb +5 -5
  31. data/lib/gir_ffi/builders/callback_builder.rb +0 -4
  32. data/lib/gir_ffi/builders/callback_return_value_builder.rb +11 -11
  33. data/lib/gir_ffi/builders/constant_builder.rb +2 -4
  34. data/lib/gir_ffi/builders/enum_builder.rb +7 -7
  35. data/lib/gir_ffi/builders/error_argument_builder.rb +16 -4
  36. data/lib/gir_ffi/builders/field_builder.rb +5 -17
  37. data/lib/gir_ffi/builders/function_builder.rb +36 -86
  38. data/lib/gir_ffi/builders/interface_builder.rb +2 -7
  39. data/lib/gir_ffi/builders/mapping_method_builder.rb +42 -33
  40. data/lib/gir_ffi/builders/marshalling_method_builder.rb +44 -33
  41. data/lib/gir_ffi/builders/method_template.rb +81 -0
  42. data/lib/gir_ffi/builders/module_builder.rb +5 -5
  43. data/lib/gir_ffi/builders/object_builder.rb +44 -25
  44. data/lib/gir_ffi/builders/property_builder.rb +6 -2
  45. data/lib/gir_ffi/builders/registered_type_builder.rb +1 -5
  46. data/lib/gir_ffi/builders/return_value_builder.rb +20 -15
  47. data/lib/gir_ffi/builders/signal_closure_builder.rb +3 -6
  48. data/lib/gir_ffi/builders/type_builder.rb +1 -1
  49. data/lib/gir_ffi/builders/unintrospectable_builder.rb +1 -5
  50. data/lib/gir_ffi/builders/user_defined_builder.rb +17 -21
  51. data/lib/gir_ffi/builders/vfunc_builder.rb +3 -6
  52. data/lib/gir_ffi/builders/with_layout.rb +2 -6
  53. data/lib/gir_ffi/callback_base.rb +10 -5
  54. data/lib/gir_ffi/class_base.rb +4 -7
  55. data/lib/gir_ffi/enum_base.rb +1 -1
  56. data/lib/gir_ffi/g_type.rb +21 -19
  57. data/lib/gir_ffi/in_out_pointer.rb +2 -4
  58. data/lib/gir_ffi/in_pointer.rb +9 -8
  59. data/lib/gir_ffi/info_ext/i_field_info.rb +1 -3
  60. data/lib/gir_ffi/info_ext/i_signal_info.rb +4 -4
  61. data/lib/gir_ffi/info_ext/i_type_info.rb +6 -6
  62. data/lib/gir_ffi/module_base.rb +3 -2
  63. data/lib/gir_ffi/object_base.rb +1 -1
  64. data/lib/gir_ffi/struct_base.rb +1 -1
  65. data/lib/gir_ffi/type_base.rb +2 -2
  66. data/lib/gir_ffi/unintrospectable_type_info.rb +2 -0
  67. data/lib/gir_ffi/version.rb +1 -1
  68. data/lib/gir_ffi/zero_terminated.rb +1 -1
  69. data/lib/gir_ffi-base/glib/strv.rb +2 -2
  70. data/lib/gir_ffi.rb +1 -1
  71. data/test/ffi-glib/array_test.rb +28 -0
  72. data/test/ffi-glib/byte_array_test.rb +1 -1
  73. data/test/ffi-glib/bytes_test.rb +1 -1
  74. data/test/ffi-gobject/object_test.rb +11 -1
  75. data/test/ffi-gobject/value_test.rb +12 -1
  76. data/test/ffi-gobject_introspection/i_base_info_test.rb +14 -0
  77. data/test/ffi-gobject_introspection/i_object_info_test.rb +8 -6
  78. data/test/ffi-gobject_introspection/i_registered_type_info_test.rb +24 -0
  79. data/test/ffi-gobject_introspection/i_type_info_test.rb +17 -0
  80. data/test/gir_ffi/builder_test.rb +3 -2
  81. data/test/gir_ffi/builders/argument_builder_test.rb +2 -2
  82. data/test/gir_ffi/builders/function_builder_test.rb +27 -27
  83. data/test/gir_ffi/builders/object_builder_test.rb +10 -0
  84. data/test/gir_ffi/builders/return_value_builder_test.rb +3 -3
  85. data/test/gir_ffi/builders/signal_closure_builder_test.rb +6 -6
  86. data/test/gir_ffi/in_out_pointer_test.rb +0 -2
  87. data/test/gir_ffi/info_ext/i_type_info_test.rb +1 -1
  88. data/test/gir_ffi_test_helper.rb +0 -4
  89. data/test/integration/generated_gimarshallingtests_test.rb +1 -1
  90. data/test/integration/generated_regress_test.rb +2 -2
  91. data/test/integration/idle_loop_test.rb +25 -0
  92. data/test/minitest/stats_plugin.rb +26 -0
  93. metadata +13 -62
  94. data/lib/gir_ffi/builders/null_argument_builder.rb +0 -12
  95. data/lib/gir_ffi/builders/null_builder.rb +0 -12
  96. data/tasks/yard.rake +0 -6
@@ -61,17 +61,13 @@ module GirFFI
61
61
  }
62
62
  end
63
63
 
64
- def parent
64
+ def parent_info
65
65
  nil
66
66
  end
67
67
 
68
68
  def fields
69
69
  info.fields
70
70
  end
71
-
72
- def superclass
73
- ClassBase
74
- end
75
71
  end
76
72
  end
77
73
  end
@@ -7,17 +7,17 @@ module GirFFI
7
7
  module Builders
8
8
  # Implements building post-processing statements for return values.
9
9
  class ReturnValueBuilder < BaseArgumentBuilder
10
- def initialize var_gen, arginfo, is_constructor = false
10
+ def initialize var_gen, arginfo, constructor_result = false
11
11
  super var_gen, arginfo
12
- @is_constructor = is_constructor
12
+ @constructor_result = constructor_result
13
13
  end
14
14
 
15
- def is_relevant?
16
- !is_void_return_value? && !arginfo.skip?
15
+ def relevant?
16
+ !void_return_value? && !arginfo.skip?
17
17
  end
18
18
 
19
19
  def capture_variable_name
20
- @capture_variable_name ||= new_variable
20
+ @capture_variable_name ||= new_variable if relevant?
21
21
  end
22
22
 
23
23
  def post_converted_name
@@ -29,32 +29,33 @@ module GirFFI
29
29
  end
30
30
 
31
31
  def return_value_name
32
- if is_relevant?
33
- post_converted_name unless array_arg
34
- end
32
+ post_converted_name if has_return_value_name?
35
33
  end
36
34
 
37
35
  def post_conversion
36
+ # TODO: Avoid conditional by using NullConvertor
38
37
  if has_post_conversion?
39
- [ "#{post_converted_name} = #{post_convertor.conversion}" ]
38
+ ["#{post_converted_name} = #{post_convertor.conversion}"]
40
39
  else
41
40
  []
42
41
  end
43
42
  end
44
43
 
45
- attr_reader :is_constructor
46
-
47
44
  private
48
45
 
46
+ def constructor_result?
47
+ @constructor_result
48
+ end
49
+
49
50
  def has_post_conversion?
50
- is_closure || is_constructor ||
51
+ closure? || constructor_result? ||
51
52
  type_info.needs_c_to_ruby_conversion_for_functions?
52
53
  end
53
54
 
54
55
  def post_convertor
55
- @post_convertor ||= if is_closure
56
+ @post_convertor ||= if closure?
56
57
  ClosureConvertor.new(capture_variable_name)
57
- elsif is_constructor
58
+ elsif constructor_result?
58
59
  ConstructorResultConvertor.new(capture_variable_name)
59
60
  else
60
61
  CToRubyConvertor.new(type_info,
@@ -67,9 +68,13 @@ module GirFFI
67
68
  length_arg && length_arg.post_converted_name
68
69
  end
69
70
 
70
- def is_void_return_value?
71
+ def void_return_value?
71
72
  specialized_type_tag == :void && !type_info.pointer?
72
73
  end
74
+
75
+ def has_return_value_name?
76
+ relevant? && !array_arg
77
+ end
73
78
  end
74
79
  end
75
80
  end
@@ -6,12 +6,9 @@ module GirFFI
6
6
  # Implements the creation of a closure class for handling a particular
7
7
  # signal. The type will be attached to the appropriate class.
8
8
  class SignalClosureBuilder < BaseTypeBuilder
9
- def instantiate_class
10
- unless already_set_up
11
- setup_constants
12
- klass.class_eval marshaller_definition
13
- end
14
- klass
9
+ def setup_class
10
+ setup_constants
11
+ klass.class_eval marshaller_definition
15
12
  end
16
13
 
17
14
  def setup_method _method
@@ -29,7 +29,7 @@ module GirFFI
29
29
  }
30
30
 
31
31
  def self.build info
32
- TYPE_MAP[info.info_type].new(info).build_class
32
+ builder_for(info).build_class
33
33
  end
34
34
 
35
35
  # TODO: Pull up to include :function and :module
@@ -6,10 +6,6 @@ module GirFFI
6
6
  # which no data is found in the GIR. Typically, these are created to
7
7
  # cast objects returned by a function that returns an interface.
8
8
  class UnintrospectableBuilder < ObjectBuilder
9
- def instantiate_class
10
- setup_class unless already_set_up
11
- end
12
-
13
9
  def klass
14
10
  @klass ||= TypeBuilder::CACHE[target_gtype] ||= Class.new(superclass)
15
11
  end
@@ -26,7 +22,7 @@ module GirFFI
26
22
 
27
23
  private
28
24
 
29
- def signal_definers
25
+ def ancestor_infos
30
26
  info.interfaces
31
27
  end
32
28
  end
@@ -9,37 +9,33 @@ module GirFFI
9
9
  @info = info
10
10
  end
11
11
 
12
- def instantiate_class
13
- if already_set_up
14
- @gtype = klass.get_gtype
15
- else
16
- @gtype = GObject.type_register_static(parent_gtype.to_i,
17
- info.g_name,
18
- gobject_type_info, 0)
19
- included_interfaces.each do |interface|
20
- ifinfo = gobject_interface_info interface
21
- GObject.type_add_interface_static @gtype, interface.get_gtype, ifinfo
22
- end
23
- setup_class
24
- TypeBuilder::CACHE[@gtype] = klass
25
- end
26
- end
27
-
28
12
  def setup_class
13
+ register_type
29
14
  setup_layout
30
15
  setup_constants
31
16
  setup_property_accessors
32
17
  setup_constructor
18
+ TypeBuilder::CACHE[@gtype] = klass
33
19
  end
34
20
 
35
21
  def target_gtype
36
- @gtype
22
+ @gtype ||= klass.get_gtype
37
23
  end
38
24
 
39
25
  private
40
26
 
41
- def parent
42
- @parent ||= gir.find_by_gtype(parent_gtype.to_i)
27
+ def register_type
28
+ @gtype = GObject.type_register_static(parent_gtype.to_i,
29
+ info.g_name,
30
+ gobject_type_info, 0)
31
+ included_interfaces.each do |interface|
32
+ ifinfo = gobject_interface_info interface
33
+ GObject.type_add_interface_static @gtype, interface.get_gtype, ifinfo
34
+ end
35
+ end
36
+
37
+ def parent_info
38
+ @parent_info ||= gir.find_by_gtype(parent_gtype.to_i)
43
39
  end
44
40
 
45
41
  def parent_gtype
@@ -47,7 +43,7 @@ module GirFFI
47
43
  end
48
44
 
49
45
  def interface_gtypes
50
- included_interfaces.map {|interface| GType.new(interface.get_gtype) }
46
+ included_interfaces.map { |interface| GType.new(interface.get_gtype) }
51
47
  end
52
48
 
53
49
  def included_interfaces
@@ -141,7 +137,7 @@ module GirFFI
141
137
 
142
138
  def setup_vfunc super_class_struct, impl
143
139
  vfunc_name = impl.name
144
- vfunc_info = parent.find_vfunc vfunc_name.to_s
140
+ vfunc_info = parent_info.find_vfunc vfunc_name.to_s
145
141
 
146
142
  if vfunc_info
147
143
  install_vfunc super_class_struct, vfunc_name, vfunc_info, impl.implementation
@@ -12,12 +12,9 @@ module GirFFI
12
12
  # can serve as such an implementation in C. The class will be namespaced
13
13
  # inside class defining the vfunc.
14
14
  class VFuncBuilder < BaseTypeBuilder
15
- def instantiate_class
16
- unless already_set_up
17
- setup_constants
18
- klass.class_eval mapping_method_definition
19
- end
20
- klass
15
+ def setup_class
16
+ setup_constants
17
+ klass.class_eval mapping_method_definition
21
18
  end
22
19
 
23
20
  def klass
@@ -23,8 +23,8 @@ module GirFFI
23
23
  end
24
24
 
25
25
  def dummy_layout_specification
26
- if parent
27
- [:parent, superclass.const_get(:Struct), 0]
26
+ if parent_info
27
+ [:parent, superclass::Struct, 0]
28
28
  else
29
29
  [:dummy, :char, 0]
30
30
  end
@@ -40,10 +40,6 @@ module GirFFI
40
40
  end
41
41
  end
42
42
 
43
- def instantiate_class
44
- setup_class unless already_set_up
45
- end
46
-
47
43
  def klass
48
44
  @klass ||= get_or_define_class namespace_module, @classname, superclass
49
45
  end
@@ -19,9 +19,14 @@ module GirFFI
19
19
  end
20
20
 
21
21
  def self.to_native value, _context
22
- return nil unless value
23
- return value if FFI::Function === value
24
- value.to_native
22
+ case value
23
+ when CallbackBase
24
+ value.to_native
25
+ when FFI::Function
26
+ value
27
+ else
28
+ nil
29
+ end
25
30
  end
26
31
 
27
32
  def self.wrap ptr
@@ -43,8 +48,8 @@ module GirFFI
43
48
  end
44
49
 
45
50
  def self.wrap_in_callback_args_mapper prc
46
- return nil unless prc
47
- return prc if FFI::Function === prc
51
+ return unless prc
52
+
48
53
  new do |*args|
49
54
  call_with_argument_mapping(prc, *args)
50
55
  end
@@ -1,5 +1,4 @@
1
1
  require 'forwardable'
2
- require 'gir_ffi/builders/null_builder'
3
2
  require 'gir_ffi/registered_type_base'
4
3
 
5
4
  module GirFFI
@@ -12,13 +11,11 @@ module GirFFI
12
11
  attr_reader :struct
13
12
  def_delegators :@struct, :to_ptr
14
13
 
15
- GIR_FFI_BUILDER = NullBuilder.new
16
-
17
14
  def setup_and_call method, *arguments, &block
18
15
  method_name = self.class.try_in_ancestors(:setup_instance_method, method.to_s)
19
16
 
20
17
  unless method_name
21
- raise RuntimeError, "Unable to set up instance method '#{method}' in #{self}"
18
+ raise "Unable to set up instance method '#{method}' in #{self}"
22
19
  end
23
20
 
24
21
  send method_name, *arguments, &block
@@ -34,7 +31,7 @@ module GirFFI
34
31
  method_name = try_in_ancestors(:setup_method, method.to_s)
35
32
 
36
33
  unless method_name
37
- raise RuntimeError, "Unable to set up method '#{method}' in #{self}"
34
+ raise "Unable to set up method '#{method}' in #{self}"
38
35
  end
39
36
 
40
37
  send method_name, *arguments, &block
@@ -74,9 +71,9 @@ module GirFFI
74
71
  # Wrap the passed pointer in an instance of the current class. Will not
75
72
  # do any casting to subtypes.
76
73
  def direct_wrap ptr
77
- return nil if !ptr or ptr.null?
74
+ return nil if !ptr || ptr.null?
78
75
  obj = _real_new
79
- obj.instance_variable_set :@struct, self::Struct.new(ptr.to_ptr)
76
+ obj.instance_variable_set :@struct, self::Struct.new(ptr)
80
77
  obj
81
78
  end
82
79
 
@@ -42,7 +42,7 @@ module GirFFI
42
42
  result = setup_method method.to_s
43
43
 
44
44
  unless result
45
- raise RuntimeError, "Unable to set up method #{method} in #{self}"
45
+ raise "Unable to set up method #{method} in #{self}"
46
46
  end
47
47
 
48
48
  send method, *arguments, &block
@@ -1,25 +1,27 @@
1
- # Wrapper class providing extended functionality for a GType, which is normally
2
- # just a kind of integer
3
- class GirFFI::GType
4
- def initialize gtype
5
- @gtype = gtype
6
- end
1
+ module GirFFI
2
+ # Wrapper class providing extended functionality for a GType, which is
3
+ # normally just a kind of integer
4
+ class GType
5
+ def initialize gtype
6
+ @gtype = gtype
7
+ end
7
8
 
8
- def to_i
9
- @gtype
10
- end
11
-
12
- def class_size
13
- type_query.class_size
14
- end
9
+ def to_i
10
+ @gtype
11
+ end
15
12
 
16
- def instance_size
17
- type_query.instance_size
18
- end
13
+ def class_size
14
+ type_query.class_size
15
+ end
16
+
17
+ def instance_size
18
+ type_query.instance_size
19
+ end
19
20
 
20
- private
21
+ private
21
22
 
22
- def type_query
23
- @type_query ||= GObject.type_query @gtype
23
+ def type_query
24
+ @type_query ||= GObject.type_query @gtype
25
+ end
24
26
  end
25
27
  end
@@ -13,8 +13,6 @@ module GirFFI
13
13
  super ptr
14
14
  end
15
15
 
16
- private :initialize
17
-
18
16
  # TODO: Create type classes that extract values from pointers.
19
17
  def to_value
20
18
  case value_ffi_type
@@ -58,11 +56,11 @@ module GirFFI
58
56
  end
59
57
 
60
58
  def self.for type
61
- new(type).tap {|ptr| ptr.clear}
59
+ new(type).tap { |ptr| ptr.clear }
62
60
  end
63
61
 
64
62
  def self.from type, value
65
- new(type).tap {|ptr| ptr.set_value value}
63
+ new(type).tap { |ptr| ptr.set_value value }
66
64
  end
67
65
 
68
66
  private
@@ -4,7 +4,7 @@ module GirFFI
4
4
  # arrays, strings, or interfaces.
5
5
  class InPointer < FFI::Pointer
6
6
  def self.from_array type, ary
7
- return if !ary
7
+ return unless ary
8
8
  case type
9
9
  when :utf8, :filename
10
10
  from_utf8_array ary
@@ -30,7 +30,7 @@ module GirFFI
30
30
  end
31
31
 
32
32
  def self.from type, val
33
- return if !val
33
+ return unless val
34
34
  case type
35
35
  when :utf8, :filename
36
36
  from_utf8 val
@@ -47,22 +47,23 @@ module GirFFI
47
47
 
48
48
  class << self
49
49
  def from_closure_data obj
50
- FFI::Pointer.new(obj.object_id).tap {|ptr|
51
- ArgHelper::OBJECT_STORE.store(ptr, obj) }
50
+ FFI::Pointer.new(obj.object_id).tap do |ptr|
51
+ ArgHelper::OBJECT_STORE.store(ptr, obj)
52
+ end
52
53
  end
53
54
 
54
55
  private
55
56
 
56
57
  def from_utf8_array ary
57
- from_basic_type_array :pointer, ary.map {|str| from_utf8 str}
58
+ from_basic_type_array :pointer, ary.map { |str| from_utf8 str }
58
59
  end
59
60
 
60
61
  def from_boolean_array ary
61
- from_basic_type_array :int, ary.map {|val| val ? 1 : 0}
62
+ from_basic_type_array :int, ary.map { |val| val ? 1 : 0 }
62
63
  end
63
64
 
64
65
  def from_pointer_array type, ary
65
- from_basic_type_array :pointer, ary.map {|elem| from type, elem }
66
+ from_basic_type_array :pointer, ary.map { |elem| from type, elem }
66
67
  end
67
68
 
68
69
  def from_gvalue_array type, ary
@@ -90,7 +91,7 @@ module GirFFI
90
91
  end
91
92
 
92
93
  def from_enum_array type, ary
93
- from_basic_type_array :int32, ary.map {|sym| type.to_native sym, nil }
94
+ from_basic_type_array :int32, ary.map { |sym| type.to_native sym, nil }
94
95
  end
95
96
 
96
97
  def from_utf8 str
@@ -3,9 +3,7 @@ module GirFFI
3
3
  # Extensions for GObjectIntrospection::IFieldInfo needed by GirFFI
4
4
  module IFieldInfo
5
5
  def layout_specification
6
- [ name.to_sym,
7
- field_type.to_ffitype,
8
- offset ]
6
+ [name.to_sym, field_type.to_ffitype, offset]
9
7
  end
10
8
  end
11
9
  end
@@ -14,13 +14,13 @@ module GirFFI
14
14
  bldr.build_class.new(&block)
15
15
  end
16
16
 
17
- # TODO: Use argument info to convert out arguments and array lengths.
18
17
  def arguments_to_gvalues instance, arguments
19
- arg_values = args.zip(arguments).map do |info, arg|
20
- info.argument_type.make_g_value.set_value(arg)
18
+ arg_g_values = args.map { |info| info.argument_type.make_g_value }
19
+ arg_g_values.zip(arguments).each do |g_value, arg|
20
+ g_value.set_value arg
21
21
  end
22
22
 
23
- arg_values.unshift GObject::Value.wrap_instance(instance)
23
+ arg_g_values.unshift GObject::Value.wrap_instance(instance)
24
24
  end
25
25
 
26
26
  def gvalue_for_return_value
@@ -4,7 +4,6 @@ module GirFFI
4
4
  module InfoExt
5
5
  # Extensions for GObjectIntrospection::ITypeInfo needed by GirFFI
6
6
  module ITypeInfo
7
-
8
7
  def self.flattened_tag_to_gtype_map
9
8
  @flattened_tag_to_gtype_map ||= {
10
9
  array: GObject::TYPE_ARRAY,
@@ -22,10 +21,11 @@ module GirFFI
22
21
 
23
22
  def g_type
24
23
  if tag == :interface
25
- interface.g_type
24
+ return interface.g_type
25
+ elsif (type = ITypeInfo.flattened_tag_to_gtype_map[flattened_tag])
26
+ return type
26
27
  else
27
- ITypeInfo.flattened_tag_to_gtype_map[flattened_tag] or
28
- raise "Can't find type for #{flattened_tag} pointer? = #{pointer?}"
28
+ raise "Can't find GType for #{flattened_tag} pointer? = #{pointer?}"
29
29
  end
30
30
  end
31
31
 
@@ -36,7 +36,7 @@ module GirFFI
36
36
  def element_type
37
37
  case tag
38
38
  when :glist, :gslist, :array, :c
39
- enumerable_element_type
39
+ enumerable_element_type
40
40
  when :ghash
41
41
  dictionary_element_type
42
42
  else
@@ -197,7 +197,7 @@ module GirFFI
197
197
  subtype = param_type(index).to_ffitype
198
198
  if subtype == :pointer
199
199
  # NOTE: Don't use pointer directly to appease JRuby.
200
- :"uint#{FFI.type_size(:pointer)*8}"
200
+ :"uint#{FFI.type_size(:pointer) * 8}"
201
201
  else
202
202
  subtype
203
203
  end
@@ -11,14 +11,15 @@ module GirFFI
11
11
  load_class(classname) || super
12
12
  end
13
13
 
14
+ # @deprecated The load_class method should always be used. Remove in 0.8.0
14
15
  def setup_class classname
15
16
  gir_ffi_builder.build_namespaced_class classname.to_s
16
17
  end
17
18
 
18
- alias load_class setup_class
19
+ alias_method :load_class, :setup_class
19
20
 
20
21
  def gir_ffi_builder
21
- const_get :GIR_FFI_BUILDER
22
+ self::GIR_FFI_BUILDER
22
23
  end
23
24
 
24
25
  def setup_method name
@@ -33,7 +33,7 @@ module GirFFI
33
33
  :pointer
34
34
  end
35
35
 
36
- def self.copy_value_to_pointer value, pointer, offset=0
36
+ def self.copy_value_to_pointer value, pointer, offset = 0
37
37
  pointer.put_pointer offset, value.to_ptr
38
38
  end
39
39
 
@@ -21,7 +21,7 @@ module GirFFI
21
21
  pointer.to_ptr
22
22
  end
23
23
 
24
- def self.copy_value_to_pointer value, pointer, offset=0
24
+ def self.copy_value_to_pointer value, pointer, offset = 0
25
25
  size = self::Struct.size
26
26
  pointer.put_bytes offset, value.to_ptr.read_bytes(size), 0, size
27
27
  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
- const_get :GIR_FFI_BUILDER
5
+ self::GIR_FFI_BUILDER
6
6
  end
7
7
 
8
8
  def gir_info
9
- const_get :GIR_INFO
9
+ self::GIR_INFO
10
10
  end
11
11
  end
12
12
  end
@@ -1,3 +1,5 @@
1
+ require 'gir_ffi/info_ext/full_type_name'
2
+
1
3
  module GirFFI
2
4
  # Represents a type not found in the GIR, conforming, as needed, to the
3
5
  # interface of GObjectIntrospection::IObjectInfo.
@@ -1,4 +1,4 @@
1
1
  # Current GirFFI version
2
2
  module GirFFI
3
- VERSION = "0.7.5"
3
+ VERSION = "0.7.6"
4
4
  end
@@ -25,7 +25,7 @@ module GirFFI
25
25
  def each
26
26
  return if @ptr.null?
27
27
  offset = 0
28
- while val = read_value(offset)
28
+ while (val = read_value(offset))
29
29
  offset += ffi_type_size
30
30
  yield wrap_value(val)
31
31
  end
@@ -17,7 +17,8 @@ module GLib
17
17
  end
18
18
 
19
19
  def each
20
- reset_iterator or return
20
+ return if @ptr.null?
21
+ reset_iterator
21
22
  while (ptr = next_ptr)
22
23
  yield ptr.read_string
23
24
  end
@@ -30,7 +31,6 @@ module GLib
30
31
  private
31
32
 
32
33
  def reset_iterator
33
- return if @ptr.null?
34
34
  @offset = 0
35
35
  end
36
36
 
data/lib/gir_ffi.rb CHANGED
@@ -20,7 +20,7 @@ require 'gir_ffi/version'
20
20
  # Main module containing classes and modules needed for generating GLib and
21
21
  # GObject bindings.
22
22
  module GirFFI
23
- def self.setup module_name, version=nil
23
+ def self.setup module_name, version = nil
24
24
  module_name = module_name.to_s
25
25
  GirFFI::Builder.build_module module_name, version
26
26
  end
@@ -153,4 +153,32 @@ describe GLib::Array do
153
153
  proc { arr.index(-1) }.must_raise IndexError
154
154
  end
155
155
  end
156
+
157
+ describe "#reset_typespec" do
158
+ describe "when it needs to guess the type" do
159
+ it "guesses :uint8 for size 1" do
160
+ arr = GLib::Array.from :int8, [1, 2, 3]
161
+ arr.reset_typespec
162
+ arr.element_type.must_equal :uint8
163
+ end
164
+
165
+ it "guesses :uint16 for size 2" do
166
+ arr = GLib::Array.from :int16, [1, 2, 3]
167
+ arr.reset_typespec
168
+ arr.element_type.must_equal :uint16
169
+ end
170
+
171
+ it "guesses :uint32 for size 4" do
172
+ arr = GLib::Array.from :int32, [1, 2, 3]
173
+ arr.reset_typespec
174
+ arr.element_type.must_equal :uint32
175
+ end
176
+
177
+ it "guesses :uint64 for size 8" do
178
+ arr = GLib::Array.from :int64, [1, 2, 3]
179
+ arr.reset_typespec
180
+ arr.element_type.must_equal :uint64
181
+ end
182
+ end
183
+ end
156
184
  end